How to update WPF browser application manifest and xbap file with ‘mage.exe’

老外参考文章1

老外参考文章2

I created a WPF browser application MyApp then published it by ClickOnce in VS2008.

Published folder like this:

PublishedFolder\MyApp.xbap

PublishedFolder\setup.exe

PublishedFolder\Application Files\MyApp_0_0_0_1\ MyApp.xbap

PublishedFolder\Application Files\MyApp_0_0_0_1\ MyApp.exe.manifest

PublishedFolder\Application Files\MyApp_0_0_0_1\ MyApp.exe.deploy

PublishedFolder\Application Files\MyApp_0_0_0_1\otherDependedLib.dll.deploy

Now, I usually need to modify app.config because I need modify DB connection string and services addresses etc. But after published to application server, I don’t want to republish the version with VS2008. So I find mage.exe tool.

I put mage.exe and MyApp.pfx in “PublishedFolder\”

Then I do like so:

mage -Update "Application Files\MyApp_0_0_0_1\ MyApp.exe.manifest"

mage -Sign    "Application Files\MyApp_0_0_0_1\ MyApp.exe.manifest" -CertFile MyApp.pfx -Password "test"

mage -Update MyApp.xbap -appm "Application Files\MyApp_0_0_0_1\ MyApp.exe.manifest"

mage -Sign     MyApp.xbap -CertFile MyApp.pfx -Password "test"

When I run update manifest command, I got "Error MSB3113: Could not find file "otherDependedLib.dll"... ".

My dependent dlls all added ".deploy" for client download.

But update success and I found hash value and sign name value had been changed in MyApp.exe.manifest and MyApp.xbap.

Then I browser the application in IE after cleaned buffer with “mage -cc”.

But I get next error:

ERROR SUMMARY

Below is a summary of the errors, details of these errors are listed later in the log.

* An exception occurred while downloading the manifest. Following failure messages were detected:

                + Downloading http://localhost/MyApp.exe.manifest did not succeed.

                + The remote server returned an error: (404) Not Found.

 

Maybe I did some wrong options in mage step, who can tell me the correct method. Thank you!

use a script to remove .deploy first then sign the add it back before signing the xbap

rename *.deploy *.

以上是一个老外在利用脚本发布XBAP中重签名的方法,结合红字部分可以解决问题,经过多方搜索和分析及试验,以下脚本可以完成自动发布并在线安装成功:

 

@echo 编译XBAP相关

@echo 清理APP缓存
"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\mage.exe" -cc 

@echo 编译XBAP项目
@cd App\BrowserOfHmi
RMDIR /s /q "bin\Debug"
%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe BrowserOfHmi.csproj /target:publish /t:Build /property:Configuration=Debug /l:FileLogger,Microsoft.Build.Engine;logfile=BrowserOfHmi.log
@echo Close notepad to continue...
@if errorlevel 1 @notepad  BrowserOfHmi.log

cd..
cd..

@echo 清理旧发布文件
RMDIR /s /q "..\Build\Install\Packages\Browser\Xbap\Application Files\BrowserOfHmi_1_0_0_0\"
md "..\Build\Install\Packages\Browser\Xbap\Application Files\BrowserOfHmi_1_0_0_0\"

@echo 拷贝新发布文件
xcopy "App\BrowserOfHmi\bin\debug\app.publish\*.*" "..\Build\Install\Packages\Browser\Xbap\" /s /h /y /d:1-1-1999

@echo 去掉.deploy
rename "..\Build\Install\Packages\Browser\Xbap\Application Files\BrowserOfHmi_1_0_0_0\*.deploy" "*."
rename "..\Build\Install\Packages\Browser\Xbap\Application Files\BrowserOfHmi_1_0_0_0\Icon\*.deploy" "*."
rename "..\Build\Install\Packages\Browser\Xbap\Application Files\BrowserOfHmi_1_0_0_0\zh-Hans\*.deploy" "*."

@echo 重新签名
"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\mage.exe" -Update "..\Build\Install\Packages\Browser\Xbap\Application Files\BrowserOfHmi_1_0_0_0\BrowserOfHmi.exe.manifest"
"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\mage.exe" -Sign    "..\Build\Install\Packages\Browser\Xbap\Application Files\BrowserOfHmi_1_0_0_0\BrowserOfHmi.exe.manifest" -CertFile "App\BrowserOfHmi\BrowserOfHmi.pfx" -Password "action98"
"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\mage.exe" -Update "..\Build\Install\Packages\Browser\Xbap\BrowserOfHmi.xbap" -appc "Application Files\BrowserOfHmi_1_0_0_0\BrowserOfHmi.exe.manifest" -appm "..\Build\Install\Packages\Browser\Xbap\Application Files\BrowserOfHmi_1_0_0_0\BrowserOfHmi.exe.manifest"
"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\mage.exe" -Sign     "..\Build\Install\Packages\Browser\Xbap\BrowserOfHmi.xbap" -CertFile "App\BrowserOfHmi\BrowserOfHmi.pfx" -Password "action98"

@echo 增加.deploy
ren "..\Build\Install\Packages\Browser\Xbap\Application Files\BrowserOfHmi_1_0_0_0\*.dll" "*.dll.deploy"
ren "..\Build\Install\Packages\Browser\Xbap\Application Files\BrowserOfHmi_1_0_0_0\zh-Hans\*.dll" "*.dll.deploy"
ren "..\Build\Install\Packages\Browser\Xbap\Application Files\BrowserOfHmi_1_0_0_0\*.exe" "*.exe.deploy"
ren "..\Build\Install\Packages\Browser\Xbap\Application Files\BrowserOfHmi_1_0_0_0\icon\*.ico" "*.ico.deploy"

pause

 

posted @ 2015-12-30 15:15  遥望星空  阅读(770)  评论(0编辑  收藏  举报