Skip to content

Instantly share code, notes, and snippets.

@sakapon
Created October 13, 2015 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sakapon/093252392a517c1a19c6 to your computer and use it in GitHub Desktop.
Save sakapon/093252392a517c1a19c6 to your computer and use it in GitHub Desktop.
BuildSample / Create ZIP with version (PowerShell)
# source assembly file path
if (-not ($Args[0])) { return 100 }
# target dir path
if (-not ($Args[1])) { return 101 }
Add-Type -AssemblyName System.IO.Compression.FileSystem
$assemblyName = [System.IO.Path]::GetFileNameWithoutExtension($Args[0])
$assembly = [System.Reflection.Assembly]::LoadFrom($Args[0])
$assemblyFileVersion = [System.Reflection.CustomAttributeExtensions]::GetCustomAttribute($assembly, [System.Reflection.AssemblyFileVersionAttribute])
if (-not ($assemblyFileVersion)) { return 200 }
$sourceDirPath = [System.IO.Path]::GetDirectoryName($Args[0])
$targetZipFileName = [string]::Format("{0}-{1}.zip", $assemblyName, $assemblyFileVersion.Version)
$targetZipFilePath = [System.IO.Path]::Combine($Args[1], $targetZipFileName)
[System.IO.Directory]::CreateDirectory($Args[1])
[System.IO.File]::Delete($targetZipFilePath)
[System.IO.Compression.ZipFile]::CreateFromDirectory($sourceDirPath, $targetZipFilePath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment