Skip to content

Instantly share code, notes, and snippets.

@rufer7
Last active September 25, 2021 02:37
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 rufer7/3366de827f8107456a90faf022390456 to your computer and use it in GitHub Desktop.
Save rufer7/3366de827f8107456a90faf022390456 to your computer and use it in GitHub Desktop.
Sample PowerShell build script to build C# code
Param
(
[string]$build = "Debug"
,
[switch]$test = $true
)
$msBuildPath = 'C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild';
$msTestPath = 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\';
$testResults = "TestResults.trx";
$env:Path = $env:Path + ";" + $msTestPath;
nuget restore .\src\ArbitrarySolution.sln -MSBuildVersion 12;
& $msBuildPath src\ArbitrarySolution.sln /property:Configuration=$build;
if ($test)
{
Write "Execute unit tests";
if (Test-Path $testResults)
{
rm $testResults;
}
MSTest.exe /testcontainer:.\src\ArbitrarySolution.Project1.Tests\bin\Debug\ArbitrarySolution.Project1.Tests.dll /testcontainer:.\src\ArbitrarySolution.Project2.Tests\bin\Debug\ArbitrarySolution.Project2.Tests.dll /resultsfile:$testResults;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment