Skip to content

Instantly share code, notes, and snippets.

Last active Sep 25, 2021
What would you like to do?
Sample PowerShell build script to build C# code
[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