Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ClickOnceBuildAndDeploy.ps1
param(
[Parameter()]
[string]
$Version,
[Parameter()]
[string]
$packageName,
[Parameter()]
[string]
$confituration,
[Parameter()]
[string]
$networkDeployPath,
[Parameter()]
[string]
$winformsProjLocation,
[Parameter()]
[string]
$packageOutDir
)
$appFileFolder="$($packageName)_$($version.replace(".", "_"))"
#This stuff stays the same
$applicationFileSubFolder="Application Files"
$msbuildPath = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin"
$buildOutputDir = "$packageOutDir\bin"
#Automated build below here. Unless something really changes this should never change
#Lets Clean things up
remove-item -recurse $buildOutputDir
&"$msbuildPath\MSBuild.exe" /t:Clean $winformsProjLocation
#Now build the application
&"$msbuildPath\MSBuild.exe" -p:Configuration=$confituration -p:OutDir=$buildOutputDir /p:Version=$Version /p:ThisProjectNameOverrideAssemblyName=$packageName $winformsProjLocation
#Remove some stuff that shouldn't get released
remove-item -recurse "$buildOutputDir\ref"
#Build our local version of the network file path
$appFileDir = "$packageOutDir\$applicationFileSubFolder\$appFileFolder"
if(!(test-path $appFileDir)){
New-Item -Path $appFileDir -ItemType Directory
}
#Copy the files
copy-item -recurse "$buildOutputDir\*" $appFileDir
#Lets use mage for the clickonce package build
#Have to add a launcher
dotnet mage -al "$packageName.exe" -td $appFileDir
#now lets create a file manifest
$manifestName = "$appFileDir\$packageName.manifest"
#Its always new because its a new deploy folder
dotnet mage -new Application -t $manifestName -fd $appFileDir -v $Version
#Now lets create or update our click once app
$clickOnceAppFile = "$packageOutDir\$packageName.application"
if(!(test-path $clickOnceAppFile)){
dotnet mage -new Deployment -Install true -pub "Sunset Transportation" -v $Version -AppManifest $manifestName -t $clickOnceAppFile
} else{
dotnet mage -Update $clickOnceAppFile -Install true -pub "Sunset Transportation" -v $Version -AppManifest $manifestName
}
copy-item -recurse "$appFileDir" "$networkDeployPath\$applicationFileSubFolder\$appFileFolder"
copy-item $clickOnceAppFile $networkDeployPath
The MIT License (MIT)
Copyright © 2021 Jay Oursler
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment