6
A
回答
6
Mage.exe是一個清單生成和編輯命令行工具.NET Framework應用程序。還有一個UI版本MageUI.exe
一個典型的用途是手動創建您的ClickOnce deployment manifests。
0
它用於簽名的ClickOnce應用程序
9
米奇小麥給了一個偉大的答案,如果你剛開始接觸法師,讀的最後一環,他給了!
我想分享一些真正的代碼,爲其他ClickOnce項目提供幫助。我發現使用MSBUILD from the command-line to "create" the deployment非常適合自動構建過程。 I 從不從Visual Studio執行發佈嚮導。雖然,我確實在VS中指定了發佈選項卡上的所有信息,所以我不必從命令行執行它。例如,「應用程序文件」是我不知道如何在命令行上執行的操作。
之後再將應用程序成功地部署到服務器...我使用「法師」爲我的ClickOnce部署的遷移過程中,從一臺服務器到另一個(例如測試 - > Staging->生產)
例如(一個PowerShell腳本,構建您的解決方案從CruiseControl的工作運行):
&"$Env:windir\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe" "C:\Projects\MyCoolApp.sln" /t:clean /t:publish /p:Configuration=Release /p:ApplicationRevision=$Env:CCNETLABEL /p:PublishDir="\\TestServer\MyCoolAppFolder/" /p:PublishUrl="\\TestServer\MyCoolAppFolder/"
後來的後來,當你想從「TESTSERVER」到「QAServer」或「轉移」或「生產遷移ClickOnce應用程序「......你需要寫一個複雜的腳本才能做到這一點。下面是我想到的:
#########################################################################################
# PowerShell Script to Migrate a ClickOnce Deployment from one server to another.
# This is my first attempt at PowerShell... pardon the bad or incorrect code. :-)
# To run a PowerShell script from CruiseControl.Net:
# http://www.cruisecontrolnet.org/projects/ccnet/wiki/PowerShell_Task
# NOTE: When doing the initial build, ensure that the ProviderURL and ProviderDir are set.
#########################################################################################
$SourceDir = "\\TestServer\MyCoolAppFolder"
$DestDir = "\\StagingServer\MyCoolAppFolder"
$DeploymentManifestName = "MyCoolApp.application"
$DeploymentDestUrl = "file://StagingServer/MyCoolAppFolder"
# If your application is one that connects to a database, then likely you want it to point
# to a different database depending what environment it's been deployed to.
# I use a SQL Server connection for this example.
$ConnStringName = "MyCoolAppConnectionString"
$ConnStringValue = "data source=StagingServerInstance;Initial Catalog=MyCoolAppDB;persist security info=True;user id=Gregg;password=Gregg"
# Unfortunately, you *must* specify the publisher when doing Mage, even though you specified it
# when you did the original publish, otherwise Mage will change the Publisher value to the
# name of your Application. A bug in Mage I suspect.
$Publisher = "Gregg Cleland"
# Risk: This next line assumes that the pfx certificate file is readily available.
# Just be certain it's the same key you used when you published originally.
$AuthenticationKeyPath = "C:\Projects\MyCoolApp\MyCoolApp_TemporaryKey.pfx"
# Note: This references the .NET 3.5 version of mage... the .NET 4.0 version of mage.exe can be found at:
# C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\mage.exe
$MAGE = "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\mage.exe"
#########################################################################################
# Start off at the source location.
Set-Location $SourceDir
#########################################################################################
# Get the application manifest directory name and application manifest file name.
[xml]$doc = Get-Content $DeploymentManifestName
$ns = New-Object Xml.XmlNamespaceManager $doc.NameTable
$ns.AddNamespace("asmv1", "urn:schemas-microsoft-com:asm.v1")
$ns.AddNamespace("asmv2", "urn:schemas-microsoft-com:asm.v2")
$xpath = "/asmv1:assembly/asmv2:dependency/asmv2:dependentAssembly"
$appManifestPath = $doc.SelectSingleNode($xpath, $ns).codebase # Example: = "Application Files\MyCoolApp_1_0_0_5\MyApp.exe.manifest"
$position = $appManifestPath.LastIndexOf('\');
$appManifestDir = $appManifestPath.SubString(0, $position); # Example: "Application Files\MyCoolApp_1_0_0_5"
$appManifestFile = $appManifestPath.SubString($position + 1); # Example: "MyCoolApp.exe.manifest"
#########################################################################################
# Copy the deployment files and the latest application files to destination.
# Note: Do not forget to ensure the CruiseControl Service Logon has permissions to write to destination!
# Todo: If robocopy fails, throw "robocopy failed!" Most likely it is an Error 5, Access Denied
# b/c the CruiseControl Service logon account doesn't have permission to copy to create/write to destination.
$CurrentDir = "$DestDir\$appManifestDir"
robocopy "$SourceDir" "$DestDir" /XO
robocopy "$SourceDir\$appManifestDir" $CurrentDir /MIR /XO
#########################################################################################
# Now that we have copied the latest build, let us navigate down into the destination's
# application manifest directory and do some work.
Set-Location $CurrentDir
#########################################################################################
# Remove the .deploy extension from all files. (Mage will throw an exception if you don't do this)
Get-ChildItem -Include *.deploy -Recurse | Rename-Item -NewName { [System.IO.Path]::ChangeExtension($_.Name, "") }
#########################################################################################
# Modify the XML in the app.config file per your needs (e.g. change the connectionStrings)
[xml]$doc = Get-Content $AppConfigFileName
$node = $doc.SelectSingleNode("configuration/connectionStrings/add[@name='$ConnStringName']")
$node.connectionString = $ConnStringValue
$xmldocPath = $PWD.ProviderPath # hack to avoid getting the silly namespace prefixed to the path for UNC paths
$doc.Save("$xmldocPath\$AppConfigFileName") # For some reason, seems to require the fully qualified path
#########################################################################################
# Finally... We get to the part where we use MAGE!
# Use MAGE to update the application manifest hash and sign it.
&"$MAGE" -Update $appManifestFile -FromDirectory "$CurrentDir" -CertFile $AuthenticationKeyPath
#########################################################################################
# Re-Add the ".deploy" extension to all files EXCEPT those that end in "application" or
# "manifest". Do this AFTER signing.
Get-ChildItem -Recurse | Where-Object { !$_.PSIsContainer -and !$_.Name.EndsWith(".application") -and !$_.Name.EndsWith(".manifest") } | Rename-Item -NewName { $_.Name + ".deploy" }
#########################################################################################
# Finally, go back up to the Deployment folder and update the deployment manifest
Set-Location "..\..\"
&"$MAGE" -Update $DeploymentManifestName -ProviderUrl "$DeploymentDestUrl/$DeploymentManifestName" -AppManifest "$appManifestPath" -Publisher $Publisher -CertFile $AuthenticationKeyPath
相關問題
- 1. 什麼是Thread.CurrentPrincipal,它有什麼作用?
- 2. 什麼是newproxy,它有什麼用處?
- 3. 有什麼方法可以確定它是否是測試(.NET)?
- 4. 什麼是MD5CryptoServiceProvider,它可以做什麼?
- 5. Excel公式基於它是什麼日期以及它具有什麼屬性
- 6. 什麼是Ext.Component.initialConfig,它做了什麼,以及在什麼情況下使用它?
- 7. 廚師從用戶獲取UID的最佳方式是什麼?
- 8. 廚師LWRP的屬性方法是什麼?我可以通過哪些方法?
- 9. STDERR?它是什麼?它有什麼共同用途?
- 10. 廚師如果使用陳述,正確的方法是什麼?
- 11. SQL,Postgres OID,它們是什麼以及它們爲什麼有用?
- 12. enCapsa - 它是什麼和用於什麼?
- 13. 什麼是applescript,它用於什麼?
- 14. 這是什麼LINQ的方法語法,它是一個連接,如果不是,那麼它是什麼?
- 15. 什麼是BlockingCollection.TakeFromAny方法有用的
- 16. 什麼是隱式方法調用和顯式方法調用?
- 17. 究竟是什麼ObjectFactory是什麼,它用於什麼?
- 18. 什麼是原子變量,它的用法是什麼?
- 19. 什麼是fasttext(AI),它的用法是什麼?
- 20. winio64.dll中有什麼方法以及如何使用它們
- 21. 什麼是MIME?它到底是什麼?
- 22. JavaVM.framework。它是什麼?我怎麼用它?
- 23. 什麼是反射,它可以在c#中使用什麼?
- 24. 什麼是.inc以及爲什麼要使用它?
- 25. 什麼是BigInteger,我們什麼時候可以使用它?
- 26. 什麼是web.xml文件,我可以用它做什麼?
- 27. 什麼是使用廚師資源
- 28. 什麼是分佈式鎖,爲什麼使用它?
- 29. addEvents的要點/效用是什麼?它什麼時候有用?
- 30. 什麼是PS3 Root密鑰/它有什麼作用/它是如何使用的?
PowerShell腳本很棒!對此感激不盡。 – 2017-03-14 04:16:37