22 [Parameter (Mandatory = $false )][string ] $Configuration = " Release" ,
33 [Parameter (Mandatory = $false )][string ] $VersionSuffix = " " ,
44 [Parameter (Mandatory = $false )][string ] $OutputPath = " " ,
5- [Parameter (Mandatory = $false )][switch ] $SkipTests ,
6- [Parameter (Mandatory = $false )][switch ] $DisableCodeCoverage
5+ [Parameter (Mandatory = $false )][switch ] $SkipTests
76)
87
8+ # These make CI builds faster
9+ $env: DOTNET_MULTILEVEL_LOOKUP = " 0"
10+ $env: DOTNET_SKIP_FIRST_TIME_EXPERIENCE = " true"
11+ $env: NUGET_XMLDOC_MODE = " skip"
12+
913$ErrorActionPreference = " Stop"
1014$ProgressPreference = " SilentlyContinue"
1115
@@ -52,10 +56,16 @@ else {
5256}
5357
5458if ($installDotNetSdk -eq $true ) {
55- $env: DOTNET_INSTALL_DIR = Join-Path " $ ( Convert-Path " $PSScriptRoot " ) " " .dotnetcli"
59+
60+ if (($null -ne $env: TF_BUILD )) {
61+ $env: DOTNET_INSTALL_DIR = Join-Path $env: ProgramFiles " dotnet"
62+ } else {
63+ $env: DOTNET_INSTALL_DIR = Join-Path " $ ( Convert-Path " $PSScriptRoot " ) " " .dotnetcli"
64+ }
65+
5666 $sdkPath = Join-Path $env: DOTNET_INSTALL_DIR " sdk\$dotnetVersion "
5767
58- if (! (Test-Path $sdkPath )) {
68+ if (( $null -ne $ env: TF_BUILD ) -or ( ! (Test-Path $sdkPath ) )) {
5969 if (! (Test-Path $env: DOTNET_INSTALL_DIR )) {
6070 mkdir $env: DOTNET_INSTALL_DIR | Out-Null
6171 }
@@ -64,12 +74,15 @@ if ($installDotNetSdk -eq $true) {
6474 Invoke-WebRequest " https://dot.net/v1/dotnet-install.ps1" - OutFile $installScript - UseBasicParsing
6575 & $installScript - Version " $dotnetVersion " - InstallDir " $env: DOTNET_INSTALL_DIR " - NoPath
6676 }
67-
68- $env: PATH = " $env: DOTNET_INSTALL_DIR ;$env: PATH "
69- $dotnet = Join-Path " $env: DOTNET_INSTALL_DIR " " dotnet.exe"
7077}
7178else {
72- $dotnet = " dotnet"
79+ $env: DOTNET_INSTALL_DIR = Split-Path - Path (Get-Command dotnet.exe ).Path
80+ }
81+
82+ $dotnet = Join-Path " $env: DOTNET_INSTALL_DIR " " dotnet.exe"
83+
84+ if (($installDotNetSdk -eq $true ) -And ($null -eq $env: TF_BUILD )) {
85+ $env: PATH = " $env: DOTNET_INSTALL_DIR ;$env: PATH "
7386}
7487
7588function DotNetPack {
@@ -89,48 +102,29 @@ function DotNetPack {
89102function DotNetTest {
90103 param ([string ]$Project )
91104
92- if ($DisableCodeCoverage -eq $true ) {
93- if ($null -ne $env: TF_BUILD ) {
94- & $dotnet test $Project -- output $OutputPath -- logger trx
95- }
96- else {
97- & $dotnet test $Project -- output $OutputPath
98- }
99- }
100- else {
101-
102- if ($installDotNetSdk -eq $true ) {
103- $dotnetPath = $dotnet
104- }
105- else {
106- $dotnetPath = (Get-Command " dotnet.exe" ).Source
107- }
105+ $nugetPath = Join-Path $env: USERPROFILE " .nuget\packages"
106+ $propsFile = Join-Path $solutionPath " Directory.Build.props"
107+ $reportGeneratorVersion = (Select-Xml - Path $propsFile - XPath " //PackageReference[@Include='ReportGenerator']/@Version" ).Node.' #text'
108+ $reportGeneratorPath = Join-Path $nugetPath " ReportGenerator\$reportGeneratorVersion \tools\netcoreapp2.0\ReportGenerator.dll"
108109
109- $nugetPath = Join-Path $env: USERPROFILE " .nuget\packages "
110- $propsFile = Join-Path $solutionPath " Directory.Build.props "
110+ $coverageOutput = Join-Path $OutputPath " coverage.cobertura.xml "
111+ $reportOutput = Join-Path $OutputPath " coverage "
111112
112- $reportGeneratorVersion = (Select-Xml - Path $propsFile - XPath " //PackageReference[@Include='ReportGenerator']/@Version" ).Node.' #text'
113- $reportGeneratorPath = Join-Path $nugetPath " ReportGenerator\$reportGeneratorVersion \tools\netcoreapp2.0\ReportGenerator.dll"
114-
115- $coverageOutput = Join-Path $OutputPath " coverage.cobertura.xml"
116- $reportOutput = Join-Path $OutputPath " coverage"
117-
118- if ($null -ne $env: TF_BUILD ) {
119- & $dotnetPath test $Project -- output $OutputPath -- logger trx
120- }
121- else {
122- & $dotnetPath test $Project -- output $OutputPath
123- }
113+ if ($null -ne $env: TF_BUILD ) {
114+ & $dotnet test $Project -- output $OutputPath -- logger trx
115+ }
116+ else {
117+ & $dotnet test $Project -- output $OutputPath
118+ }
124119
125- $dotNetTestExitCode = $LASTEXITCODE
120+ $dotNetTestExitCode = $LASTEXITCODE
126121
127- & $dotnet `
128- $reportGeneratorPath `
129- `" - reports:$coverageOutput `" `
130- `" - targetdir:$reportOutput `" `
131- - reporttypes:HTML `
132- - verbosity:Warning
133- }
122+ & $dotnet `
123+ $reportGeneratorPath `
124+ `" - reports:$coverageOutput `" `
125+ `" - targetdir:$reportOutput `" `
126+ - reporttypes:HTML `
127+ - verbosity:Warning
134128
135129 if ($dotNetTestExitCode -ne 0 ) {
136130 throw " dotnet test failed with exit code $dotNetTestExitCode "
@@ -141,10 +135,8 @@ Write-Host "Packaging solution..." -ForegroundColor Green
141135
142136DotNetPack $libraryProject
143137
144- if ($SkipTests -eq $false ) {
145- Write-Host " Running tests..." - ForegroundColor Green
146- Remove-Item - Path (Join-Path $OutputPath " coverage.json" ) - Force - ErrorAction SilentlyContinue | Out-Null
147- ForEach ($testProject in $testProjects ) {
148- DotNetTest $testProject
149- }
138+ Write-Host " Running tests..." - ForegroundColor Green
139+ Remove-Item - Path (Join-Path $OutputPath " coverage.json" ) - Force - ErrorAction SilentlyContinue | Out-Null
140+ ForEach ($testProject in $testProjects ) {
141+ DotNetTest $testProject
150142}
0 commit comments