This commit is contained in:
James Newton-King
2017-04-09 15:16:53 +12:00
parent 82f694d261
commit b145964dd0
3 changed files with 73 additions and 100 deletions
+69 -98
View File
@@ -22,19 +22,22 @@
$releaseDir = "$baseDir\Release" $releaseDir = "$baseDir\Release"
$workingDir = "$baseDir\$workingName" $workingDir = "$baseDir\$workingName"
$workingSourceDir = "$workingDir\Src" $workingSourceDir = "$workingDir\Src"
$nugetPath = "$buildDir\Temp\nuget.exe" $nugetPath = "$buildDir\Temp\nuget.exe"
$vswhereVersion = "1.0.58" $vswhereVersion = "1.0.58"
$vswherePath = "$buildDir\Temp\vswhere.$vswhereVersion" $vswherePath = "$buildDir\Temp\vswhere.$vswhereVersion"
$nunitConsoleVersion = "3.6.1" $nunitConsoleVersion = "3.6.1"
$nunitConsolePath = "$buildDir\Temp\NUnit.ConsoleRunner.$nunitConsoleVersion" $nunitConsolePath = "$buildDir\Temp\NUnit.ConsoleRunner.$nunitConsoleVersion"
$builds = @( $builds = @(
@{Name = "Newtonsoft.Json.Roslyn"; TestsName = "Newtonsoft.Json.Tests.Roslyn"; BuildFunction = "NetCliBuild"; TestsFunction = "NetCliTests"; NuGetDir = "netstandard1.0,netstandard1.3"; TestDir = "netcoreapp1.0,netcoreapp1.1"; Framework=$null; Enabled=$true}, @{Framework = "netstandard1.3"; TestsFunction = "NetCliTests"; TestFramework = "netcoreapp1.1"; Enabled=$true},
@{Name = "Newtonsoft.Json"; TestsName = "Newtonsoft.Json.Tests"; BuildFunction = $null; TestsFunction = "NUnitTests"; NuGetDir = "net45"; Framework="net-4.0"; Enabled=$true}, @{Framework = "netstandard1.0"; TestsFunction = "NetCliTests"; TestFramework = "netcoreapp1.0"; Enabled=$true},
@{Name = "Newtonsoft.Json.Portable"; TestsName = "Newtonsoft.Json.Tests.Portable"; BuildFunction = $null; TestsFunction = "NUnitTests"; NuGetDir = "portable-net45+win8+wpa81+wp8"; TestDir = "net452"; Framework="net-4.0"; Enabled=$true}, @{Framework = "net45"; TestsFunction = "NUnitTests"; NUnitFramework="net-4.0"; Enabled=$true},
@{Name = "Newtonsoft.Json.Portable40"; TestsName = "Newtonsoft.Json.Tests.Portable40"; BuildFunction = $null; TestsFunction = "NUnitTests"; NuGetDir = "portable-net40+win8+wpa81+wp8+sl5"; TestDir = "net451"; Framework="net-4.0"; Enabled=$true}, @{Framework = "net40"; TestsFunction = "NUnitTests"; NUnitFramework="net-4.0"; Enabled=$true},
@{Name = "Newtonsoft.Json.Net40"; TestsName = "Newtonsoft.Json.Tests.Net40"; BuildFunction = $null; TestsFunction = "NUnitTests"; NuGetDir = "net40"; Framework="net-4.0"; Enabled=$true}, @{Framework = "net35"; TestsFunction = "NUnitTests"; NUnitFramework="net-2.0"; Enabled=$true},
@{Name = "Newtonsoft.Json.Net35"; TestsName = "Newtonsoft.Json.Tests.Net35"; BuildFunction = $null; TestsFunction = "NUnitTests"; NuGetDir = "net35"; Framework="net-2.0"; Enabled=$true}, @{Framework = "net20"; TestsFunction = "NUnitTests"; NUnitFramework="net-2.0"; Enabled=$true},
@{Name = "Newtonsoft.Json.Net20"; TestsName = "Newtonsoft.Json.Tests.Net20"; BuildFunction = $null; TestsFunction = "NUnitTests"; NuGetDir = "net20"; Framework="net-2.0"; Enabled=$true} @{Framework = "portable-net45+win8+wpa81+wp8"; TestsFunction = "NUnitTests"; TestFramework = "net452"; NUnitFramework="net-4.0"; Enabled=$true},
@{Framework = "portable-net40+win8+wpa81+wp8+sl5"; TestsFunction = "NUnitTests"; TestFramework = "net451"; NUnitFramework="net-4.0"; Enabled=$true}
) )
} }
@@ -56,10 +59,14 @@ task Clean {
Write-Host "Creating working directory $workingDir" Write-Host "Creating working directory $workingDir"
New-Item -Path $workingDir -ItemType Directory New-Item -Path $workingDir -ItemType Directory
} }
# Build each solution, optionally signed # Build each solution, optionally signed
task Build -depends Clean { task Build -depends Clean {
$script:enabledBuilds = $builds | ? {$_.Enabled}
Write-Host -ForegroundColor Green "Found $($script:enabledBuilds.Length) enabled builds"
mkdir "$buildDir\Temp" -Force mkdir "$buildDir\Temp" -Force
EnsureNuGetExists EnsureNuGetExists
EnsureNuGetPacakge "vswhere" $vswherePath $vswhereVersion EnsureNuGetPacakge "vswhere" $vswherePath $vswhereVersion
@@ -82,57 +89,36 @@ task Build -depends Clean {
Edit-XmlNodes -doc $xml -xpath "/Project/PropertyGroup/PackageId" -value $packageId Edit-XmlNodes -doc $xml -xpath "/Project/PropertyGroup/PackageId" -value $packageId
Edit-XmlNodes -doc $xml -xpath "/Project/PropertyGroup/VersionPrefix" -value $majorWithReleaseVersion Edit-XmlNodes -doc $xml -xpath "/Project/PropertyGroup/VersionPrefix" -value $majorWithReleaseVersion
Edit-XmlNodes -doc $xml -xpath "/Project/PropertyGroup/VersionSuffix" -value $nugetPrerelease Edit-XmlNodes -doc $xml -xpath "/Project/PropertyGroup/VersionSuffix" -value $nugetPrerelease
$xml.save("$workingSourceDir\Newtonsoft.Json\Newtonsoft.Json.Roslyn.csproj") $xml.save("$workingSourceDir\Newtonsoft.Json\Newtonsoft.Json.Roslyn.csproj")
foreach ($build in $builds) $projectPath = "$workingSourceDir\Newtonsoft.Json\Newtonsoft.Json.Roslyn.csproj"
{
$name = $build.Name
$enabled = $build.Enabled
if ($name -ne $null)
{
Write-Host -ForegroundColor Green "Building " $name
Write-Host -ForegroundColor Green "Signed " $signAssemblies
Write-Host -ForegroundColor Green "Key " $signKeyPath
Write-Host -ForegroundColor Green "Enabled " $enabled
if ($enabled -and $build.BuildFunction) NetCliBuild
{
& $build.BuildFunction $build
}
}
}
} }
# Optional build documentation, add files to final zip # Optional build documentation, add files to final zip
task Package -depends Build { task Package -depends Build {
foreach ($build in $builds) foreach ($build in $script:enabledBuilds)
{ {
$name = $build.TestsName $finalDir = $build.Framework
$finalDirs = $build.NuGetDir.Split(",")
$enabled = $build.Enabled
if ($enabled) $sourcePath = "$workingSourceDir\Newtonsoft.Json\bin\Release\$finalDir"
if (!(Test-Path -path $sourcePath))
{ {
foreach ($finalDir in $finalDirs) throw "Could not find $sourcePath"
{
$sourcePath = "$workingSourceDir\Newtonsoft.Json\bin\Release\$finalDir"
if (!(Test-Path -path $sourcePath))
{
throw "Could not find $sourcePath"
}
robocopy $sourcePath $workingDir\Package\Bin\$finalDir *.dll *.pdb *.xml /NFL /NDL /NJS /NC /NS /NP /XO /XF *.CodeAnalysisLog.xml | Out-Default
}
} }
robocopy $sourcePath $workingDir\Package\Bin\$finalDir *.dll *.pdb *.xml /NFL /NDL /NJS /NC /NS /NP /XO /XF *.CodeAnalysisLog.xml | Out-Default
} }
if ($buildNuGet) if ($buildNuGet)
{ {
Write-Host -ForegroundColor Green "Creating NuGet package" Write-Host -ForegroundColor Green "Creating NuGet package"
exec { & $script:msBuildPath "/t:pack" "/p:IncludeSource=true" "/p:Configuration=Release" "$workingSourceDir\Newtonsoft.Json\Newtonsoft.Json.Roslyn.csproj" } $targetFrameworks = ($script:enabledBuilds | Select-Object @{Name="Framework";Expression={$_.Framework}} | select -expand Framework) -join ";"
exec { & $script:msBuildPath "/t:pack" "/p:IncludeSource=true" "/p:Configuration=Release" "/p:TargetFrameworks=`"$targetFrameworks`"" "$workingSourceDir\Newtonsoft.Json\Newtonsoft.Json.Roslyn.csproj" }
mkdir $workingDir\NuGet mkdir $workingDir\NuGet
move -Path $workingSourceDir\Newtonsoft.Json\bin\Release\*.nupkg -Destination $workingDir\NuGet move -Path $workingSourceDir\Newtonsoft.Json\bin\Release\*.nupkg -Destination $workingDir\NuGet
@@ -142,8 +128,8 @@ task Package -depends Build {
if ($buildDocumentation) if ($buildDocumentation)
{ {
$mainBuild = $builds | where { $_.Name -eq "Newtonsoft.Json" } | select -first 1 $mainBuild = $script:enabledBuilds | where { $_.Framework -eq "net45" } | select -first 1
$mainBuildFinalDir = $mainBuild.NuGetDir $mainBuildFinalDir = $mainBuild.Framework
$documentationSourcePath = "$workingDir\Package\Bin\$mainBuildFinalDir" $documentationSourcePath = "$workingDir\Package\Bin\$mainBuildFinalDir"
$docOutputPath = "$workingDir\Documentation\" $docOutputPath = "$workingDir\Documentation\"
Write-Host -ForegroundColor Green "Building documentation from $documentationSourcePath" Write-Host -ForegroundColor Green "Building documentation from $documentationSourcePath"
@@ -173,16 +159,32 @@ task Deploy -depends Package {
# Run tests on deployed files # Run tests on deployed files
task Test -depends Deploy { task Test -depends Deploy {
foreach ($build in $script:enabledBuilds)
foreach ($build in $builds)
{ {
if ($build.Enabled -and $build.TestsFunction -ne $null) Write-Host "Calling $($build.TestsFunction)"
{ & $build.TestsFunction $build
& $build.TestsFunction $build
}
} }
} }
function NetCliBuild()
{
$projectPath = "$workingSourceDir\Newtonsoft.Json.Roslyn.sln"
$libraryFrameworks = ($script:enabledBuilds | Select-Object @{Name="Framework";Expression={$_.Framework}} | select -expand Framework) -join ";"
$testFrameworks = ($script:enabledBuilds | Select-Object @{Name="Resolved";Expression={if ($_.TestFramework -ne $null) { $_.TestFramework } else { $_.Framework }}} | select -expand Resolved) -join ";"
$additionalConstants = switch($signAssemblies) { $true { "SIGNED" } default { "" } }
Write-Host -ForegroundColor Green "Restoring packages for $libraryFrameworks in $projectPath"
Write-Host
exec { & $script:msBuildPath "/t:restore" "/p:Configuration=Release" "/p:LibraryFrameworks=`"$libraryFrameworks`"" "/p:TestFrameworks=`"$testFrameworks`"" $projectPath | Out-Default } "Error restoring $projectPath"
Write-Host -ForegroundColor Green "Building $libraryFrameworks in $projectPath"
Write-Host
exec { & $script:msBuildPath "/t:build" $projectPath "/p:Configuration=Release" "/p:LibraryFrameworks=`"$libraryFrameworks`"" "/p:TestFrameworks=`"$testFrameworks`"" "/p:AssemblyOriginatorKeyFile=$signKeyPath" "/p:SignAssembly=$signAssemblies" "/p:TreatWarningsAsErrors=$treatWarningsAsErrors" "/p:AdditionalConstants=$additionalConstants" }
}
function EnsureNuGetExists() function EnsureNuGetExists()
{ {
if (!(Test-Path $nugetPath)) if (!(Test-Path $nugetPath))
@@ -210,79 +212,48 @@ function GetMsBuildPath()
return join-path $path 'MSBuild\15.0\Bin\MSBuild.exe' return join-path $path 'MSBuild\15.0\Bin\MSBuild.exe'
} }
function NetCliBuild($build)
{
$name = $build.Name
$projectPath = "$workingSourceDir\Newtonsoft.Json.Roslyn.sln"
$additionalConstants = switch($signAssemblies) { $true { "SIGNED" } default { "" } }
Write-Host -ForegroundColor Green "Restoring packages for $name"
Write-Host
exec { & $script:msBuildPath "/t:restore" $projectPath | Out-Default } "Error restoring $projectPath"
Write-Host -ForegroundColor Green "Building for $name"
Write-Host
exec { & $script:msBuildPath "/t:build" $projectPath "/p:Configuration=Release" "/p:AssemblyOriginatorKeyFile=$signKeyPath" "/p:SignAssembly=$signAssemblies" "/p:TreatWarningsAsErrors=$treatWarningsAsErrors" "/p:AdditionalConstants=$additionalConstants" }
}
function NetCliTests($build) function NetCliTests($build)
{ {
$name = $build.TestsName
$projectPath = "$workingSourceDir\Newtonsoft.Json.Tests\Newtonsoft.Json.Tests.Roslyn.csproj" $projectPath = "$workingSourceDir\Newtonsoft.Json.Tests\Newtonsoft.Json.Tests.Roslyn.csproj"
$location = "$workingSourceDir\Newtonsoft.Json.Tests" $location = "$workingSourceDir\Newtonsoft.Json.Tests"
$finalDirs = $build.TestDir.Split(",") $testDir = if ($build.TestFramework -ne $null) { $build.TestFramework } else { $build.Framework }
$enabled = $build.Enabled
exec { .\Tools\Dotnet\dotnet-install.ps1 -Version $netCliVersion | Out-Default } exec { .\Tools\Dotnet\dotnet-install.ps1 -Version $netCliVersion | Out-Default }
if ($enabled) try
{ {
try Set-Location $location
{
Set-Location $location
exec { dotnet --version | Out-Default } exec { dotnet --version | Out-Default }
Write-Host -ForegroundColor Green "Running tests for $name" Write-Host -ForegroundColor Green "Running tests for $testDir"
Write-Host Write-Host
foreach ($finalDir in $finalDirs) exec { dotnet test $projectPath -f $testDir -c Release -l trx | Out-Default }
{ copy-item -Path "$location\TestResults\*.trx" -Destination $workingDir
Write-Host -ForegroundColor Green "Test target $finalDir" }
Write-Host finally
{
exec { dotnet test $projectPath -f $finalDir -c Release -l trx | Out-Default } Set-Location $baseDir
copy-item -Path "$location\TestResults\*.trx" -Destination $workingDir
}
}
finally
{
Set-Location $baseDir
}
} }
} }
function NUnitTests($build) function NUnitTests($build)
{ {
$name = $build.TestsName $testDir = if ($build.TestFramework -ne $null) { $build.TestFramework } else { $build.Framework }
$finalDir = $build.NuGetDir $framework = $build.NUnitFramework
$testDir = if ($build.TestDir -ne $null) { $build.TestDir } else { $finalDir } $testRunDir = "$workingDir\Deployed\Bin\$($build.Framework)"
$framework = $build.Framework
$testRunDir = "$workingDir\Deployed\Bin\$finalDir"
Write-Host -ForegroundColor Green "Copying test assembly $name to deployed directory" Write-Host -ForegroundColor Green "Copying test assembly $testDir to deployed directory"
Write-Host Write-Host
robocopy "$workingSourceDir\Newtonsoft.Json.Tests\bin\Release\$testDir" $testRunDir /MIR /NFL /NDL /NJS /NC /NS /NP /XO | Out-Default robocopy "$workingSourceDir\Newtonsoft.Json.Tests\bin\Release\$testDir" $testRunDir /MIR /NFL /NDL /NJS /NC /NS /NP /XO | Out-Default
Write-Host -ForegroundColor Green "Running NUnit tests " $name Write-Host -ForegroundColor Green "Running NUnit tests " $testDir
Write-Host Write-Host
try try
{ {
Set-Location $testRunDir Set-Location $testRunDir
exec { & $nunitConsolePath\tools\nunit3-console.exe "$testRunDir\Newtonsoft.Json.Tests.dll" --framework=$framework --result=$workingDir\$name.xml | Out-Default } "Error running $name tests" exec { & $nunitConsolePath\tools\nunit3-console.exe "$testRunDir\Newtonsoft.Json.Tests.dll" --framework=$framework --result=$workingDir\$testDir.xml | Out-Default } "Error running $testDir tests"
} }
finally finally
{ {
@@ -6,7 +6,8 @@
</ItemGroup> </ItemGroup>
</Target> </Target>
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net45;net451;net452;net40;net35;net20;netcoreapp1.1;netcoreapp1.0</TargetFrameworks> <TargetFrameworks Condition="'$(TestFrameworks)'==''">net45;net451;net452;net40;net35;net20;netcoreapp1.1;netcoreapp1.0</TargetFrameworks>
<TargetFrameworks Condition="'$(TestFrameworks)'!=''">$(TestFrameworks)</TargetFrameworks>
<VersionPrefix>1.0</VersionPrefix> <VersionPrefix>1.0</VersionPrefix>
<Authors>James Newton-King</Authors> <Authors>James Newton-King</Authors>
<NeutralLanguage>en-US</NeutralLanguage> <NeutralLanguage>en-US</NeutralLanguage>
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net45;net40;net35;net20;netstandard1.0;netstandard1.3;portable-net45+win8+wpa81+wp8;portable-net40+win8+wpa81+wp8+sl5</TargetFrameworks> <TargetFrameworks Condition="'$(LibraryFrameworks)'==''">net45;net40;net35;net20;netstandard1.0;netstandard1.3;portable-net45+win8+wpa81+wp8;portable-net40+win8+wpa81+wp8+sl5</TargetFrameworks>
<TargetFrameworks Condition="'$(LibraryFrameworks)'!=''">$(LibraryFrameworks)</TargetFrameworks>
<VersionPrefix>10.0.1</VersionPrefix> <VersionPrefix>10.0.1</VersionPrefix>
<VersionSuffix>beta1</VersionSuffix> <VersionSuffix>beta1</VersionSuffix>
<Authors>James Newton-King</Authors> <Authors>James Newton-King</Authors>