I am trying to publish a click once with the following process:
- Github commit
- Teamcity builds and creates basic (unsigned artifact)
- push to Octopus Deploy
- Octopus changes publish URL and app setting
- Octopus uses mage to change the above, recreate app file and manifect and resign
- Octopus pushes files to deployment site
I had the above roughly working until I needed to change the app setting, with the following caveat:
- only the publish url was changed
- used mage to re sign the files but did not regenerate any files.
It will now publish the files and get as far as downloading and trying to run / install the app and gives the following error:
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.
To get Octopus deploy to do the config transform for me I had to add a script to OD during the deployment. In the pre deployment section it copies the "myappSetupTool.exe.config.deploy" file and removes the ".deploy" extension so that OD will see it as a config and replace the appsetting automatically.
In the post deployment section I copy the file back to have the ".deploy" extension.
I release that this changes the files hash and thats why it would not work, so I thought that I had to regenerate the .application and .manifest files to compensate.
question 1:
Do I need to regenerate these files whilst the files have the .deploy extension or without them?
question 2:
If I need to remove the ".deploy" extension do I need to put the files back the way they were? i.e. rename them back to "*.deploy"?
question 3:
what would be the steps to achieve this? I have put my powershell script in below.
$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"}
So I figured it out.. not sure what was wrong with the original script, but decided to go back to basics and break it down into sections, script below: