From c09bd5ac0feabdb3374fd735aa050f94535bb107 Mon Sep 17 00:00:00 2001 From: Jimmy Campbell Date: Mon, 6 Jun 2022 18:29:01 -0700 Subject: [PATCH 1/2] Build with .NET 6 --- .pipelines/pipeline.user.windows.yml | 17 ++++++++++++----- build.cmd | 8 -------- build.ps1 | 6 ++++-- build/CallPowerShell.cmd | 1 + build/ChoosePowerShell.cmd | 23 ----------------------- build/install-dotnet.ps1 | 8 ++++++++ build/resolve-dotnet.ps1 | 14 ++++++++++++++ pack.cmd | 8 -------- pack.ps1 | 4 +++- test.cmd | 3 --- test.ps1 | 7 +++++++ 11 files changed, 49 insertions(+), 50 deletions(-) delete mode 100644 build.cmd create mode 100644 build/CallPowerShell.cmd delete mode 100644 build/ChoosePowerShell.cmd create mode 100644 build/install-dotnet.ps1 create mode 100644 build/resolve-dotnet.ps1 delete mode 100644 pack.cmd delete mode 100644 test.cmd create mode 100644 test.ps1 diff --git a/.pipelines/pipeline.user.windows.yml b/.pipelines/pipeline.user.windows.yml index 28c87dcb..db1b0b3d 100644 --- a/.pipelines/pipeline.user.windows.yml +++ b/.pipelines/pipeline.user.windows.yml @@ -7,16 +7,21 @@ environment: restore: commands: + - !!defaultcommand + name: 'Install .NET Core 6' + command: 'build/CallPowerShell.cmd' + arguments: 'build/install-dotnet.ps1 -RestoreOnly' - !!defaultcommand name: 'Restore' - command: 'build.cmd' - arguments: '-RestoreOnly' + command: 'build/CallPowerShell.cmd' + arguments: 'build.ps1 -RestoreOnly' build: commands: - !!buildcommand name: 'Dotnet Build' - command: 'build.cmd' + command: 'build/CallPowerShell.cmd' + arguments: 'build.ps1' logs: - from: 'buildlogs' to: 'Build Logs' @@ -32,7 +37,8 @@ package: commands: - !!buildcommand name: 'Dotnet Pack' - command: 'pack.cmd' + command: 'build/CallPowerShell.cmd' + arguments: 'pack.ps1' logs: - from: 'buildlogs' to: 'Build Logs' @@ -48,7 +54,8 @@ test: commands: - !!testcommand name: 'Dotnet Test' - command: 'test.cmd' + command: 'build/CallPowerShell.cmd' + arguments: 'test.ps1' fail_on_stderr: false testresults: - title: 'Unit Tests' diff --git a/build.cmd b/build.cmd deleted file mode 100644 index df877382..00000000 --- a/build.cmd +++ /dev/null @@ -1,8 +0,0 @@ -call %~dp0build\ChoosePowerShell.cmd - -IF %ERRORLEVEL% NEQ 0 ( - - exit /B 1 -) - -%PowerShell% "%~dp0build.ps1" %* \ No newline at end of file diff --git a/build.ps1 b/build.ps1 index 02d792fd..cd90b5c9 100644 --- a/build.ps1 +++ b/build.ps1 @@ -26,15 +26,17 @@ if ((Test-Path -Path $LogDirectory) -ne $true) { New-Item -ItemType Directory -Path $LogDirectory | Write-Verbose } +$dotnet = & "$PSScriptRoot/build/resolve-dotnet.ps1" + if ($RestoreOnly) { # Restore - dotnet restore "$Solution" + & $dotnet restore "$Solution" } else { # Build - dotnet build -c $BuildConfig "$Solution" | Tee-Object -FilePath "$LogDirectory\build.log" + & $dotnet build -c $BuildConfig "$Solution" | Tee-Object -FilePath "$LogDirectory\build.log" } exit $LASTEXITCODE diff --git a/build/CallPowerShell.cmd b/build/CallPowerShell.cmd new file mode 100644 index 00000000..fd8eb280 --- /dev/null +++ b/build/CallPowerShell.cmd @@ -0,0 +1 @@ +PowerShell %~dp0..\%* \ No newline at end of file diff --git a/build/ChoosePowerShell.cmd b/build/ChoosePowerShell.cmd deleted file mode 100644 index 45798129..00000000 --- a/build/ChoosePowerShell.cmd +++ /dev/null @@ -1,23 +0,0 @@ -:: where.exe does not exist in windows container, application specific test must be used to check for existence - -pwsh -Command Write-Host "a" - -IF %ERRORLEVEL% == 0 ( - - set PowerShell=pwsh - - exit /B 0 -) - -PowerShell -Command Write-Host "a" - -IF %ERRORLEVEL% == 0 ( - - set PowerShell=PowerShell - - exit /B 0 -) - -echo Could not find a suitable PowerShell executable. - -EXIT /B 1 diff --git a/build/install-dotnet.ps1 b/build/install-dotnet.ps1 new file mode 100644 index 00000000..7088094f --- /dev/null +++ b/build/install-dotnet.ps1 @@ -0,0 +1,8 @@ +# Installs .NET Core 2.1 and .NET 6 for CI/CD environment +# see: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script#examples + +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; + +&([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) -Version 2.1.816 + +&([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) diff --git a/build/resolve-dotnet.ps1 b/build/resolve-dotnet.ps1 new file mode 100644 index 00000000..79219a8b --- /dev/null +++ b/build/resolve-dotnet.ps1 @@ -0,0 +1,14 @@ +# Resolves dotnet execution path +# Locations considered include dotnet install script default location and somewhere on path +$CI_CD_INSTALL_PATH = "$env:LOCALAPPDATA\Microsoft\dotnet\dotnet.exe" + +if (Test-Path $CI_CD_INSTALL_PATH) +{ + $CI_CD_INSTALL_PATH + + return +} + +$dotnet = Get-Command dotnet.exe -ErrorAction Stop + +$dotnet.Source \ No newline at end of file diff --git a/pack.cmd b/pack.cmd deleted file mode 100644 index 209cd5e0..00000000 --- a/pack.cmd +++ /dev/null @@ -1,8 +0,0 @@ -call %~dp0build\ChoosePowerShell.cmd - -IF %ERRORLEVEL% NEQ 0 ( - - exit /B 1 -) - -%PowerShell% "%~dp0pack.ps1" %* \ No newline at end of file diff --git a/pack.ps1 b/pack.ps1 index a05e485c..12434211 100644 --- a/pack.ps1 +++ b/pack.ps1 @@ -29,12 +29,14 @@ if ((Test-Path -Path $LogDirectory) -ne $true) { New-Item -ItemType Directory -Path $LogDirectory | Write-Verbose } +$dotnet = & "$PSScriptRoot/build/resolve-dotnet.ps1" + foreach ($project in $targetProjects) { $projectPath = "$PSScriptRoot\src\$project\$project.csproj" $outputPath = "$PSScriptRoot\src\$project\$PublishRelativePath" - dotnet pack -c $BuildConfig -o "$outputPath" "$projectPath" --no-build | Tee-Object -FilePath "$LogDirectory\build.log" + & $dotnet pack -c $BuildConfig -o "$outputPath" "$projectPath" --no-build | Tee-Object -FilePath "$LogDirectory\build.log" } exit $LASTEXITCODE diff --git a/test.cmd b/test.cmd deleted file mode 100644 index 6b02a979..00000000 --- a/test.cmd +++ /dev/null @@ -1,3 +0,0 @@ -cd /D "%~dp0" - -dotnet test tests\Tests.FeatureManagement\Tests.FeatureManagement.csproj --logger trx || exit /b 1 diff --git a/test.ps1 b/test.ps1 new file mode 100644 index 00000000..8cf5fdc2 --- /dev/null +++ b/test.ps1 @@ -0,0 +1,7 @@ +$ErrorActionPreference = "Stop" + +$dotnet = & "$PSScriptRoot/build/resolve-dotnet.ps1" + +& $dotnet test "$PSScriptRoot\tests\Tests.FeatureManagement\Tests.FeatureManagement.csproj" --logger trx + +exit $LASTEXITCODE \ No newline at end of file From fa809a661c839bdff435d9ab3973249ffd460a5c Mon Sep 17 00:00:00 2001 From: Jimmy Campbell Date: Tue, 7 Jun 2022 10:13:23 -0700 Subject: [PATCH 2/2] Update build step name. --- .pipelines/pipeline.user.windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pipelines/pipeline.user.windows.yml b/.pipelines/pipeline.user.windows.yml index db1b0b3d..4750d66c 100644 --- a/.pipelines/pipeline.user.windows.yml +++ b/.pipelines/pipeline.user.windows.yml @@ -8,7 +8,7 @@ environment: restore: commands: - !!defaultcommand - name: 'Install .NET Core 6' + name: 'Install .NET' command: 'build/CallPowerShell.cmd' arguments: 'build/install-dotnet.ps1 -RestoreOnly' - !!defaultcommand