Skip to content

Instantly share code, notes, and snippets.

@vardars
Created October 27, 2017 19:47
Show Gist options
  • Save vardars/6e39bae812a8436885b1b4818591903d to your computer and use it in GitHub Desktop.
Save vardars/6e39bae812a8436885b1b4818591903d to your computer and use it in GitHub Desktop.
msbuild publish powershell script
$solutionName = "$$$SOLUTION_NAME$$$"
$systemRoot = $env:systemroot
$msbuildExe = "$systemRoot\Microsoft.NET\Framework\v4.0.30319\msbuild.exe"
$currentPath = Convert-Path(".")
$currentDate = Get-Date -format yyyyMMdd-HHmm
function ZipFiles( $zipfilename, $sourcedir )
{
Add-Type -Assembly System.IO.Compression.FileSystem
$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
[System.IO.Compression.ZipFile]::CreateFromDirectory($sourcedir, $zipfilename, $compressionLevel, $false)
}
&$msbuildExe ("$currentPath\..\$solutionName", "/verbosity:q", "/p:DeployOnBuild=true", "/p:PublishProfile=DefaultPublish")
Remove-Item "$currentPath\temp\" -include *.config -Force -Recurse
ZipFiles "publish-package-$currentDate.zip" "$currentPath\temp\"
Remove-Item "$currentPath\temp\" -Force -Recurse
if (!$?) {
echo "!!! ABORTING !!!";pause;exit
}
@vardars
Copy link
Author

vardars commented Oct 27, 2017

change "$$$SOLUTION_NAME$$$" with .sln file name
change "DefaultPublish" with publish profile name
set "$currentPath..$solutionName" relative path from ps1 to sln path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment