Skip to content

Instantly share code, notes, and snippets.

@jonnii
Created May 7, 2012 14:41
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jonnii/2628150 to your computer and use it in GitHub Desktop.
Save jonnii/2628150 to your computer and use it in GitHub Desktop.
Creating a click once package using mage and powershell
task PrepareClickOnce {
write-host 'Add mage to our path'
$env:path += ";C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools"
write-host "Preparing install directory"
$installersRoot = '..\installers\app'
if (test-path $installersRoot) {
Write-Host "Cleaning installers root"
rm -r -force $installersRoot > $null
}
mkdir $installersRoot > $null
$version = gc ..\VERSION
$installerVersion = join-path $installersRoot $version
mkdir $installerVersion > $null
write-host "Prepare install directory for version $version"
cp -r -exclude *.xml ..\targets\appname\* $installerVersion
rm "$installerVersion\*vshost*"
write-host 'Creating manifest file'
$manifestFileName = join-path $installerVersion 'MyApp.exe.manifest'
mage -New Application `
-Processor x86 `
-ToFile $manifestFileName `
-name "My App" `
-Version $version `
-FromDirectory $installerVersion `
-IconFile icon.ico
# this part is optional, and is used to set up file associations
write-host ' -> Add file associations to manfest'
$fullPath = resolve-path($manifestFileName)
$doc = [xml](Get-Content -Path $fullPath)
$association = $doc.CreateElement('fileAssociation')
$association.SetAttribute('xmlns','urn:schemas-microsoft-com:clickonce.v1')
$association.SetAttribute('extension','.foo')
$association.SetAttribute('description','My App')
$association.SetAttribute('progid','Foo.Document')
$association.SetAttribute('defaultIcon','icon.ico')
$doc.assembly.AppendChild($association) > $null
$doc.Save($fullPath)
if($environmentConfiguration['signingThumbprint'] -ne '')
{
write-host " -> signing manifest file"
mage -Sign $manifestFileName -CertHash $environmentConfiguration['signingThumbprint']
}
else
{
write-host ' -> !!Skipping signing, no hash cert'
}
# create the deploy extension so we can serve from IIS
gci -exclude *.manifest -r $installerVersion | where { $_.PSIsContainer -eq $false } | rename-item -newname { $_.name + ".deploy" }
write-host "creating deployment manifest"
$applicationName = $configuration['applicationName']
write-host " -> Using application name: $applicationName"
$applicationFileName = join-path $installersRoot MyApp.application
mage -New Deployment `
-Processor x86 `
-Install true `
-Publisher "Your Co" `
-ProviderUrl "http://example.com/MyApp.application" `
-AppManifest $manifestFileName `
-Version $version `
-Name $applicationName `
-ToFile $applicationFileName `
-UseManifestForTrust true
# you need this to be able to use url parameters
write-host ' -> Enabling trustUrlParameters'
$fullPath = resolve-path($applicationFileName)
$doc = [xml](Get-Content -Path $fullPath)
$doc.assembly.deployment.SetAttribute("trustURLParameters", "true")
$doc.assembly.deployment.SetAttribute("mapFileExtensions", "true")
$doc.Save($fullPath)
write-host ' -> Updating application with MinVersion'
mage -Update $applicationFileName -MinVersion $version
write-host ' -> Changing expiration max age => before application start up'
$content = Get-Content $fullPath
$content -replace "<expiration maximumAge=`"0`" unit=`"days`" />", "<beforeApplicationStartup />" | set-content $fullPath
if($environmentConfiguration['signingThumbprint'] -ne '')
{
write-host " -> signing .application"
mage -Update $applicationFileName -CertHash $environmentConfiguration['signingThumbprint']
}
else
{
write-host ' -> !!Skipping signing, no hash cert'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment