Skip to content

Commit

Permalink
Use simpler scheme contained in global.json for alternate SDK versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
vatsan-madhavan committed Nov 13, 2019
1 parent 3fcda59 commit ee00ec6
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,4 @@ _Pvt_Extensions
# FAKE - F# Make
.fake/
*.binlog
/.dotnet
5 changes: 3 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ stages:
Copy-Item .\eng\$(_TargetFramework).json global.json -Force -Verbose
displayName: Update global.json to match TargetFramework of the Build
- powershell: ./eng/EnsureGlobalJsonSdk.ps1 -g global.json -i "$(Agent.ToolsDirectory)/dotnet" -a $(_ToolPlatform)
- powershell: ./eng/EnsureGlobalJsonSdk.ps1 -g global.json -i "$(Agent.ToolsDirectory)/dotnet" -a $(_ToolPlatform) -f $(_TargetFramework) -Verbose
displayName: Install .NET Core

- powershell: |
Expand Down Expand Up @@ -192,7 +192,8 @@ stages:
targetType: 'inline'
script: |
# Write your PowerShell commands here.
git checkout global.json
git clean -xdf
- task: DotNetCoreCLI@2
Expand Down
72 changes: 70 additions & 2 deletions eng/EnsureGlobalJsonSdk.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,43 @@ param(

[string] [Alias('a')]
[Parameter(HelpMessage='Architecture')]
$architecture=$env:PROCESSOR_ARCHITECTURE
$architecture=$env:PROCESSOR_ARCHITECTURE,

[string] [Alias('f')]
[Parameter(HelpMessage='TargetFramework to match from global.json/altsdk section for an alternate SDK version')]
[ValidateSet('', $null, 'netcoreapp3.0', 'netcoreapp3.1', 'netcoreapp5.0', IgnoreCase=$true)]
$TargetFramework=''
)

Function IIf($If, $Then, $Else) {
If ($If -IsNot "Boolean") {$_ = $If}
If ($If) {If ($Then -is "ScriptBlock") {&$Then} Else {$Then}}
Else {If ($Else -is "ScriptBlock") {&$Else} Else {$Else}}
}

Function Get-Tfm {
param(
[string]$SdkVersion
)

$WellKnownTFMs = @(
'netcoreapp1.0',
'netcoreapp1.1',
'netcoreapp2.0',
'netcoreapp2.1',
'netcoreapp2.2',
'netcoreapp3.0',
'netcoreapp3.1',
'netcoreapp5.0'
)

$tfm = ('netcoreapp' + $SdkVersion.Substring(0,3)).Trim().ToLowerInvariant()

return IIf ($WellKnownTFMs -icontains $tfm) $tfm ""
}



# Use-RunAs function from TechNet Script Gallery
# https://gallery.technet.microsoft.com/scriptcenter/63fd1c0d-da57-4fb4-9645-ea52fc4f1dfb
function Use-RunAs {
Expand Down Expand Up @@ -55,7 +89,29 @@ function Use-RunAs {

Use-RunAs
if (Test-Path $globalJson) {
$sdk_version = (Get-Content $globalJson | ConvertFrom-Json).sdk.version
$json = Get-Content $globalJson | ConvertFrom-Json

<#
If the $TargetFramework is no different from
that of the version supplied in global.json/sdk.version, don't
use it for further decisions.
#>
if ($TargetFramework -ieq (Get-Tfm -SdkVersion $json.sdk.version)) {
$TargetFramework = ''
}

if (-not $TargetFramework) {
$sdk_version = $json.sdk.version
} else {
Write-Verbose "Alternate TargetFramework requested - reading from altsdk section in global.json"
$sdk_version = $json.altsdk.$TargetFramework
if ($sdk_version) {
Write-Verbose "Alternate SDK Version: $sdk_version"
} else {
Write-Verbose "Alternate SDK Version not found"
}
}

if ($sdk_version) {
$dotnet_install = "$env:TEMP\dotnet-install.ps1"

Expand All @@ -70,5 +126,17 @@ if (Test-Path $globalJson) {

Write-Host "##vso[task.prependpath]$installPath"
Write-Verbose "Added $installPath to Azure Pipelines PATH variable"

<#
If $TargetFramework is specified, then an alternate SDK was requested.
This means that the build requires an updated global.json as well.
This is a destructive change. The global.json should be restored by doing this after a build:
git checkout global.json
#>
if ($TargetFramework) {
$dotnet = Join-Path $installPath 'dotnet.exe'
& $dotnet new globaljson --sdk-version $sdk_version --force
}
}
}
5 changes: 0 additions & 5 deletions eng/netcoreapp3.0.json

This file was deleted.

5 changes: 0 additions & 5 deletions eng/netcoreapp3.1.json

This file was deleted.

5 changes: 0 additions & 5 deletions eng/netcoreapp5.0.json

This file was deleted.

4 changes: 4 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"sdk": {
"version": "3.0.100"
},
"altsdk": {
"netcoreapp3.1": "3.1.100-preview2-014538",
"netcoreapp5.0": "5.0.100-alpha1-014879"
}
}

0 comments on commit ee00ec6

Please sign in to comment.