Skip to content

Instantly share code, notes, and snippets.

@junxy
Last active May 27, 2016 10:43
Show Gist options
  • Select an option

  • Save junxy/edee61347b69cce3e5fbbfac48ff7f01 to your computer and use it in GitHub Desktop.

Select an option

Save junxy/edee61347b69cce3e5fbbfac48ff7f01 to your computer and use it in GitHub Desktop.
psake & nuget scripts
Framework 4.5.1
properties {
$base_dir = (Get-Item (Resolve-Path .)).Parent.FullName
$bin_dir = "$base_dir\bin"
$sln_path = "$base_dir\XXX.sln"
$config = "Release"
# $tests_path = "$base_dir\src\log4net.ElasticSearch.Tests\bin\$config\log4net.ElasticSearch.Tests.dll"
# $xunit_path = "$base_dir\src\packages\xunit.runners.1.9.2\tools\xunit.console.clr4.exe"
$dirs = @($bin_dir)
# $artefacts = @("$base_dir\LICENSE", "$base_dir\readme.txt")
$nuget_path = "$base_dir\tools\nuget\NuGet.exe"
$nuspec_path = "$base_dir\scripts\XXX.nuspec"
$sharedAssemblyInfo = "$base_dir\bin\lib\net40\xxx.dll"
}
#Include "packages\Hangfire.Build.0.1.3\tools\psake-common.ps1"
task default -depends Clean, Compile
task Package -depends default, CreateNugetPackage
task Clean {
$dirs | % { Recreate-Directory $_ }
}
task Compile {
echo "config: $config"
exec {
msbuild $sln_path /p:Configuration=$config /t:"Clean,Build" /v:Quiet /nologo
}
}
task Test {
exec {
& $xunit_path $tests_path
}
}
task CopyArtefactsToBinDirectory {
$artefacts | % { CopyTo-BinDirectory $_ }
}
task CreateNugetPackage {
#$version = Get-SharedVersion
# Now load the assembly
#$Myasm = [System.Reflection.Assembly]::Loadfile($sharedAssemblyInfo)
# Get name, version and display the results
#$Aname = $Myasm.GetName()
#$version = $Aname.version
$version =(Get-Item $sharedAssemblyInfo).VersionInfo.ProductVersion
exec {
& $nuget_path pack $nuspec_path -Basepath $bin_dir -OutputDirectory $bin_dir -Version $version
}
}
task ? -Description "Helper to display task info" {
Write-Documentation
}
function Recreate-Directory($directory) {
if (Test-Path $directory) {
Write-Host -NoNewline "`tDeleting $directory"
Remove-Item $directory -Recurse -Force | out-null
Write-Host "...Done"
}
Write-Host -NoNewline "`tCreating $directory"
New-Item $directory -Type Directory | out-null
Write-Host "...Done"
}
function CopyTo-BinDirectory($artefact) {
Write-Host -NoNewline "`tCopying $artefact to $bin_dir"
Copy-Item $artefact $bin_dir
Write-Host "...Done"
}
#function Get-SharedVersion {
# $line = Get-Content "$sharedAssemblyInfo" | where {$_.Contains("AssemblyVersion")}
# $line.Split('"')[1]
#}
@echo off
if '%1'=='/?' goto help
if '%1'=='-help' goto help
if '%1'=='-h' goto help
tools\nuget\nuget.exe restore Log4net.RequestId.Helper.sln
powershell -NoProfile -ExecutionPolicy Bypass -Command "& '%~dp0\packages\psake.4.6.0\tools\psake.ps1' '%~dp0\scripts\build.ps1' %*; if ($psake.build_success -eq $false) { exit 1 } else { exit 0 }"
exit /B %errorlevel%
:help
powershell -NoProfile -ExecutionPolicy Bypass -Command "& '%~dp0\packages\psake.4.6.0\tools\psake.ps1' -help"
@junxy

junxy commented May 27, 2016

Copy link
Copy Markdown
Author

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