Last active
May 10, 2023 15:44
-
-
Save nvnivs/9780385 to your computer and use it in GitHub Desktop.
Generic Psake build script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Properties { | |
$baseDir = Resolve-Path . | |
$project = Split-Path $baseDir -Leaf | |
$artifactDir = "$baseDir\Build\Packages" | |
$version = "1.0.1" | |
} | |
Task Default -Depends Build | |
Task Clean { | |
if (Test-Path "$baseDir\build") { | |
Remove-Item "$baseDir\Build" -Recurse -Force -ErrorAction Stop | |
} | |
} | |
Task RestorePackages { | |
Exec { .\.nuget\NuGet restore -PackagesDirectory .\packages } | |
} | |
Task UpdateAssemblyInfo { | |
(Get-ChildItem -Path $baseDir -Filter AssemblyInfo.cs -Recurse) | | |
Foreach-Object { | |
(Get-Content $_.FullName) | | |
Foreach-Object { | |
$_ -replace 'AssemblyVersion.+$',"AssemblyVersion(`"$version`")]" ` | |
-replace 'AssemblyFileVersion.+$',"AssemblyFileVersion(`"$version`")]" | |
} | | |
Out-File $_.FullName | |
} | |
} | |
Task Build -Depends Clean,RestorePackages,UpdateAssemblyInfo { | |
Exec { msbuild "$project.sln" /p:Configuration=Release /t:"Clean,Build" } | |
} | |
Task Package -Depends Build { | |
if (!(Test-Path($artifactDir))) { | |
New-Item -ItemType Directory -Force -Path $artifactDir | Out-Null | |
} | |
Exec { .\.nuget\NuGet pack $baseDir\$project\$project.csproj -OutputDirectory $artifactDir -Properties Configuration=Release -Version $version } | |
} | |
Task Publish -Depends Package { | |
Exec { .\.nuget\NuGet push "$artifactDir\$project.$version.nupkg" } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment