使用mage.exe在Octopus部署中单击一次应用程序,更改发布网址和app.config

时间:2016-12-14 11:58:36

标签: powershell clickonce octopus-deploy mage

我尝试使用以下过程发布一次点击:

  • Github commit
  • Teamcity构建并创建基本(无符号工件)
  • 推送到Octopus Deploy
  • 八达通更改发布网址和应用设置
  • 八达通使用法师更改上述内容,重新创建应用程序文件并显示和辞职
  • Octopus将文件推送到部署站点

我需要更改应用程序设置才能完成上述操作,并注意以下几点:

  • 仅发布了网址
  • 使用mage重新签名文件,但没有重新生成任何文件。

它现在将发布文件并获取下载并尝试运行/安装应用程序并提供以下错误:

 Activation of http://myapp-setuptool-dev.mysite.co.uk/myappSetupTool.application resulted in exception. Following failure messages were detected:
        + Downloading http://myapp-setuptool-dev.mysite.co.uk/Application Files/myappSetupTool_0_1_1_110/myappSetupTool.exe.config did not succeed.
        + The remote server returned an error: (404) Not Found.

要让Octopus部署为我执行配置转换,我必须在部署期间向OD添加脚本。在预部署部分,它会复制" myappSetupTool.exe.config.deploy"文件并删除" .deploy"扩展,以便OD将其视为配置并自动替换appsetting。

在部署后部分,我将文件复制回来以获得" .deploy"延期。

我发布这会改变文件哈希,这就是为什么它不起作用,所以我认为我必须重新生成.application和.manifest文件来补偿。

问题1:

我是否需要重新生成这些文件,而文件具有.deploy扩展名或没有它们?

问题2:

如果我需要删除" .deploy"扩展我需要把文件放回原来的样子吗?即将它们重命名为" * .deploying"?

问题3:

实现这一目标的步骤是什么?我把我的powershell脚本放在下面。

$mage = "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\mage.exe"
$path = $OctopusParameters["Octopus.Action[deploy click once app].Output.deploymentPath"]

Set-Location -Path $path 

write-host "mage: " $mage

$appNameShort = "myappSetupTool"
$appName = "$appNameShort.application"

$folderName = $OctopusParameters["Octopus.Action[setup version number].Output.clickOnceVersion"]
$version = $folderName.Replace("_", ".")
$folderSegment = "Application Files\$appNameShort" + "_$folderName"

$deploymentApplicaitonPath = "$path\$folderSegment\$appNameShort.application"
$deploymentManifestRelativePath = "$folderSegment\$appNameShort.exe.manifest"
$deploymentManifestPath = "$path\$deploymentManifestRelativePath"

$appApplicationPath = "$path\$appName"
$certFilePath = "$path\$certFileName"

$setupPath = "$path\setup.exe"

$url  = "$publishUrl/$appName"

write-host "deployment application path: " $deploymentApplicaitonPath
write-host "deployment manifest path: " $deploymentManifestPath

write-host "application file path: " $appApplicationPath
write-host "cert file path: " $certFilePath
write-host "setup.exe path: " $setupPath

write-host "publish url: " $url

write-host "renaming all .deploy files to remove deploy extension"
#Need to resign the application manifest, but before we do we need to rename all the files back to their original names (remove .deploy)
Get-ChildItem "$path\$folderSegment\*.deploy" -Recurse | Rename-Item -NewName { $_.Name -replace '\.deploy','' }

write-host "deleting old app files manifest file to be regenerated"
Remove-Item $deploymentManifestRelativePath 

Write-Host "Creating application manifest at "$deploymentManifestRelativePath
write-host "running: $mage -New Application -t $deploymentManifestPath -n $appName -v $version -p msil -fd $path\$folderSegment -tr FullTrust -a sha256RSA"
& "$mage" -New Application -t "$deploymentManifestPath" -n "$appName" -v $version -p msil -fd "$path\$folderSegment" -tr FullTrust -a sha256RSA

write-host "Running: $mage -Sign $deploymentManifestPath -CertFile $certFilePath -Password $certPassword"
& "$mage" -Sign "$deploymentManifestPath" -CertFile "$certFilePath" -Password $certPassword


Write-Host "Creating application: $mage -New Deployment -t $appApplicationPath -n $appName -v $version -p msil -appm $deploymentManifestRelativePath -ip true -i true -um true  -pu $appApplicationPath -appc $deploymentManifestRelativePath -a sha256RSA " 
& "$mage" -New Deployment -t "$appApplicationPath" -n "$appName" -v $version -p msil -appm "$deploymentManifestPath" -ip true -i true -um true  -pu "$appApplicationPath" -appc "$deploymentManifestRelativePath" -a sha256RSA 


write-host "Running: $mage -Update $deploymentApplicaitonPath -ProviderUrl $url"
& "$mage" -Update "$deploymentApplicaitonPath" -ProviderUrl $url



write-host "Running: $mage -Update $appApplicationPath -ProviderUrl $url"
& "$mage" -Update "$appApplicationPath" -ProviderUrl $url

write-host "Running: $mage -Update $appApplicationPath -AppManifest $deploymentManifestRelativePath"
& "$mage" -Update "$appApplicationPath" -AppManifest "$deploymentManifestRelativePath"

write-host "Running: $mage -Sign $appApplicationPath -CertFile $certFilePath  -Password $certPassword"
& "$mage" -Sign "$appApplicationPath" -CertFile "$certFilePath" -Password $certPassword

write-host "Running: $setupPath -url=$publishUrl/"
& "$setupPath" "-url=$publishUrl/"

write-host "update files to have deploy extension again"
#Rename files back to the .deploy extension, skipping the files that shouldn't be renamed
Get-ChildItem -Path "Application Files\*"  -Recurse | Where-Object {!$_.PSIsContainer -and $_.Name -notlike "*.manifest" -and $_.Name -notlike "*.application" -and $_.Name -notlike "*.gif" -and $_.Name -notlike "*.png"} | Rename-Item -NewName {$_.Name + ".deploy"}

1 个答案:

答案 0 :(得分:0)

所以我想通了..不确定原始脚本出了什么问题,但决定回到基础并将其分解成以下部分:

$mage = "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\mage.exe"
$path = $OctopusParameters["Octopus.Action[deploy click once app].Output.deploymentPath"]

Set-Location -Path $path 

write-host "mage: " $mage

$appNameShort = "myappSetupTool"
$appName = "$appNameShort.application"

$folderName = $OctopusParameters["Octopus.Action[setup version number].Output.clickOnceVersion"]
$version = $folderName.Replace("_", ".")
$folderSegment = "Application Files\$appNameShort" + "_$folderName"

$deploymentApplicaitonPath = "$path\$folderSegment\$appNameShort.application"
$deploymentManifestRelativePath = "$folderSegment\$appNameShort.exe.manifest"
$deploymentManifestPath = "$path\$deploymentManifestRelativePath"

$appApplicationPath = "$path\$appName"
$certFilePath = "$path\$certFileName"

$setupPath = "$path\setup.exe"

$url  = "$publishUrl/$appName"

write-host "deployment application path: " $deploymentApplicaitonPath
write-host "deployment manifest path: " $deploymentManifestPath

write-host "application file path: " $appApplicationPath
write-host "cert file path: " $certFilePath
write-host "setup.exe path: " $setupPath

write-host "publish url: " $url






##
## order of process
##
## 1) remove all .deploy extensions
## 2) set properties on the applicaiton manifest file
## 3) update applicaiton manifest file directly
##
## 4) set properties on .application file
## 5) update .application file directly
##
## 6) sign application manifest
## 7) sign .application file
## 8) update setup.exe
##
## 9) put .deploy back on files
##

##### 1

write-host "renaming all .deploy files to remove deploy extension"
#Need to resign the application manifest, but before we do we need to rename all the files back to their original names (remove .deploy)
Get-ChildItem "$path\$folderSegment\*.deploy" -Recurse | Rename-Item -NewName { $_.Name -replace '\.deploy','' }


##### 2




##### 3

& "$mage" -Update "$deploymentManifestPath" -CertFile "$certFilePath" -Password $certPassword


##### 4

write-host "Running: $mage -Update $appApplicationPath -ProviderUrl $url"
& "$mage" -Update "$appApplicationPath" -ProviderUrl $url

write-host "Running: $mage -Update $deploymentApplicaitonPath -ProviderUrl $url"
& "$mage" -Update "$deploymentApplicaitonPath" -ProviderUrl $url


##### 5

write-host "Running: $mage -Update $appApplicationPath -AppManifest $deploymentManifestRelativePath"
& "$mage" -Update "$appApplicationPath" -AppManifest "$deploymentManifestRelativePath"


##### 6

write-host "Running: $mage -Sign $deploymentManifestPath -CertFile $certFilePath -Password $certPassword"
& "$mage" -Sign "$deploymentManifestPath" -CertFile "$certFilePath" -Password $certPassword



##### 7

write-host "Running: $mage -Sign $appApplicationPath -CertFile $certFilePath  -Password $certPassword"
& "$mage" -Sign "$appApplicationPath" -CertFile "$certFilePath" -Password $certPassword



##### 8

write-host "Running: $setupPath -url=$publishUrl/"
& "$setupPath" "-url=$publishUrl/"



##### 9

write-host "update files to have deploy extension again"
#Rename files back to the .deploy extension, skipping the files that shouldn't be renamed
Get-ChildItem -Path "$folderSegment\*"  -Recurse | Where-Object {!$_.PSIsContainer -and $_.Name -notlike "*.manifest" -and $_.Name -notlike "*.application"} | Rename-Item -NewName {$_.Name + ".deploy"}