Skip to content

Commit 93b6be2

Browse files
benrr101MichelZ
andauthored
Pipelines | Fix dotnet Installation on ARM64 (#3175)
* Use script to install .NET because of ARM bug * YAML * Add back steps: * Fix name * Try without ./ * Maybe they need to hang back a level * Replace CURL * Switch to powershell * Need a Windows & non-Windows version * YAML * Use .0 for WIndows and .X for other * Update install command to include Quality and only install Runtime when SDK is false * Improve way to specify SDK vs Runtime * Make it a string * Use whole number only * We don't need to use " * Add additional options, make output cleaner * Runtime variables like Agent.OS do not work * Path to ensure-dotnet-version * Condition not possible on template * Improve version detection * String * booleans... * Use SDK for X86, use installDir * InstallDir * PS String comparison * Cosmetics * Add new steps to sln, formatting * Cleaning up dotnet install task. * Fixing call to the new task * Same operation in a different file * Default to LTS ? * Version vs channel is kind of annoying * Fix logic for determining which task to use, just always using 9.x * ??? * Reinstate installing dotnet as part of ci-project-build-steps Replace remaining CI usages of UseDotNet with ensure-dotnet-version * Just don't use preview builds. * Debug agent OS * debug part 2 * Debug part 3? * DEBUG PART 4. * This should be the right way to get the agent os. Powershell task should be running on windows. * Isn't this what I had originally? * Ok but if that's right, then why won't the powershell task run? * Well I'm dumb. Can't use templates with a runtime variable. * More quotes. * Replace 9.x and 8.x with 9.0 and 8.0, append .x to end of UseDotNetTask version param, add more notes about what is and isn't supported from version parameter. * shouldn't have the $ * Very hacky attempt at fixing x86 dotnet installation for test runtime * Make x86 version variable be loaded during runtime * One more time ... --------- Co-authored-by: Michel Zehnder <MichelZ@users.noreply.github.com>
1 parent 4b6cefc commit 93b6be2

File tree

7 files changed

+173
-52
lines changed

7 files changed

+173
-52
lines changed

eng/pipelines/common/templates/jobs/ci-code-coverage-job.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ jobs:
4444
- task: NuGetAuthenticate@1
4545
displayName: 'NuGet Authenticate'
4646

47-
- task: UseDotNet@2
48-
displayName: 'Use .NET SDK 8.0.x'
49-
inputs:
50-
version: 8.0.x
47+
- template: ../steps/ensure-dotnet-version.yml@self
48+
parameters:
49+
packageType: 'sdk'
50+
version: '8.0'
5151

5252
- ${{ parameters.downloadArtifactsSteps }}
5353

eng/pipelines/common/templates/jobs/ci-run-tests-job.yml

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -231,26 +231,41 @@ jobs:
231231
referenceType: ${{ parameters.buildType }}
232232
testSet: ${{ parameters.testSet }}
233233
operatingSystem: ${{ parameters.operatingSystem }}
234-
235-
- ${{ if and(eq(parameters.enableX86Test, true), eq(parameters.operatingSystem, 'Windows')) }}: # run x86 tests
236-
- powershell: |
237-
dotnet --info
238-
239-
Invoke-WebRequest https://builds.dotnet.microsoft.com/dotnet/scripts/v1/dotnet-install.ps1 -OutFile dotnet-install.ps1
240-
241-
# install .net x86
242-
$version = "LTS"
243-
if (!"${{parameters.targetFramework }}".StartsWith("net4"))
244-
{
245-
$version = "${{parameters.targetFramework }}".Substring(3, "${{parameters.targetFramework }}".Length-3)
246-
}
247-
248-
.\dotnet-install.ps1 -Channel $version -Architecture x86 -InstallDir "$(dotnetx86RootPath)"
249-
250-
$(dotnetx86RootPath)dotnet.exe --info
251-
displayName: 'Install .NET x86 '
252-
condition: ne(variables['dotnetx86RootPath'], '')
253-
234+
235+
- ${{ if and(eq(parameters.enableX86Test, true), eq(parameters.operatingSystem, 'Windows')) }}:
236+
# Set up for x86 tests by manually installing dotnet for x86 to an alternative location. This
237+
# is only used to execute the test runtime (framework to test is specified in build params), so
238+
# it should be acceptable to just install a specific version in all cases.
239+
# @TODO: This setup is very confusing. Ideally we should just be utilizing the dotnet installation
240+
# earlier in the job. There has to be a cleaner way of doing this.
241+
# As it stands now, we install dotnet LTS if we're running netfx tests, and the appropriate netX
242+
# version if we're running netcore tests. Technically LTS is not supported by the UseDotNet task
243+
# but we know we're using install-dotnet since we're on windows (for now ... this will not work
244+
# forever and needs a serious rethinking).
245+
- ${{ if ne(variables['dotnetx86RootPath'], '') }}:
246+
- ${{ if startswith(parameters.targetFramework, 'net4')}}:
247+
- template: ../steps/ensure-dotnet-version.yml
248+
parameters:
249+
installDir: "$(dotnetx86RootPath)"
250+
packageType: "sdk"
251+
usePreview: "false"
252+
version: "LTS"
253+
windowsArchitecture: "x86"
254+
- ${{ else }}:
255+
- script: |
256+
set FrameworkVersion=${{ parameters.targetFramework }}
257+
echo %FrameworkVersion%
258+
set TrimmedFrameworkVersion=%FrameworkVersion:~3%
259+
echo %TrimmedFrameworkVersion%
260+
echo ##vso[task.setvariable variable=netVersionX86]%TrimmedFrameworkVersion%
261+
displayName: "Trim dotnet version"
262+
- template: ../steps/ensure-dotnet-version.yml
263+
parameters:
264+
installDir: "$(dotnetx86RootPath)"
265+
packageType: "sdk"
266+
usePreview: "false"
267+
version: $(netVersionX86)
268+
254269
- template: ../steps/run-all-tests-step.yml@self
255270
parameters:
256271
debug: ${{ parameters.debug }}

eng/pipelines/common/templates/steps/ci-prebuild-step.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ parameters:
2020
- Package
2121

2222
steps:
23-
- task: UseDotNet@2
24-
displayName: 'Use .NET 9.x sdk'
25-
inputs:
23+
- template: ensure-dotnet-version.yml
24+
parameters:
2625
packageType: sdk
27-
version: '9.x'
26+
usePreview: false
27+
version: 9.0
2828

29-
- task: UseDotNet@2
30-
displayName: 'Install .NET 8.x runtime'
31-
inputs:
29+
- template: ensure-dotnet-version.yml
30+
parameters:
3231
packageType: runtime
33-
version: '8.x'
32+
usePreview: false
33+
version: 8.0
3434

3535
- ${{if eq(parameters.debug, true)}}:
3636
- powershell: |

eng/pipelines/common/templates/steps/ci-project-build-step.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,15 @@ parameters:
3535
- allNoDocs
3636

3737
steps:
38-
- task: UseDotNet@2
39-
displayName: 'Use .NET 9.x sdk'
40-
inputs:
41-
packageType: sdk
42-
version: '9.x'
38+
- template: ./ensure-dotnet-version.yml@self
39+
parameters:
40+
packageType: 'sdk'
41+
version: '9.0'
4342

44-
- task: UseDotNet@2
45-
displayName: 'Install .NET 8.x runtime'
46-
inputs:
47-
packageType: runtime
48-
version: '8.x'
43+
- template: ./ensure-dotnet-version.yml@self
44+
parameters:
45+
packageType: 'runtime'
46+
version: '8.0'
4947

5048
- ${{ if or(eq(parameters.operatingSystem, 'Windows'), eq(parameters.operatingSystem, 'deferedToRuntime')) }}:
5149
- ${{ if or(eq(parameters.build, 'MDS'), eq(parameters.build, 'all'), eq(parameters.build, 'allNoDocs')) }}:
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#################################################################################
2+
# Licensed to the .NET Foundation under one or more agreements. #
3+
# The .NET Foundation licenses this file to you under the MIT license. #
4+
# See the LICENSE file in the project root for more information. #
5+
#################################################################################
6+
7+
# Installs dotnet sdk/runtime using UseDotNet on non-windows agents, but uses a custom ps script
8+
# for installation on Windows.
9+
#
10+
# Reason for not using UseDotNet task:
11+
# [BUG]: UseDotNet task installs x86 build on Windows arm64
12+
# https://github.com/microsoft/azure-pipelines-tasks/issues/20300
13+
14+
parameters:
15+
- # Directory where dotnet binaries should be installed. If not specified, defaults to the
16+
# agent's tools directory.
17+
name: installDir
18+
type: string
19+
default: ''
20+
21+
- # Whether to install the full SDK or the "dotnet" runtime
22+
name: packageType
23+
type: string
24+
values:
25+
- runtime
26+
- sdk
27+
28+
- # Whether to enable preview versions of dotnet
29+
name: usePreview
30+
type: boolean
31+
default: false
32+
33+
- # Version to install - supports full major.minor.patch, but can be shortened to major.minor
34+
# to get the latest within a given channel. Do not append .x to the end (as per UseDotNet),
35+
# it is not supported by dotnet-install script, and we will add it if we use UseDotNet task.
36+
name: version
37+
type: string
38+
39+
- # Specifies the architecture to install, only applies on Windows agents. If not provided,
40+
# defaults to the same architecture as the agent.
41+
name: windowsArchitecture
42+
type: string
43+
default: '<auto>'
44+
values:
45+
- '<auto>'
46+
- 'x86'
47+
- 'x64'
48+
- 'arm64'
49+
50+
steps:
51+
# Note: as much as I'd love to use template expressions here, I can't because ${{ }} is
52+
# evaluated at compile time, while Agent is not known until runtime.
53+
- powershell: |-
54+
# Propagate parameters from pipeline #######################
55+
$agentToolsDir = '$(Agent.ToolsDirectory)'
56+
echo "agentToolsDir= $agentToolsDir"
57+
58+
$architecture = '${{ parameters.windowsArchitecture }}'
59+
echo "architecture= $architecture"
60+
61+
$installDir = '${{ parameters.installDir }}'
62+
echo "installDir= $installDir"
63+
64+
$packageType = '${{ parameters.packageType }}'
65+
echo "packageType= $packageType"
66+
67+
$usePreview = '${{ parameters.usePreview }}'
68+
echo "usePreview= $usePreview"
69+
70+
$version = '${{ parameters.version }}'
71+
echo "version= $version"
72+
73+
# Install dotnet ###########################################
74+
Invoke-WebRequest -Uri "https://builds.dotnet.microsoft.com/dotnet/scripts/v1/dotnet-install.ps1" -OutFile "dotnet-install.ps1"
75+
76+
$installDir = If ($installDir) { $installDir } Else { $agentToolsDir }
77+
$installParams = @{
78+
Architecture = $architecture
79+
Channel = $version
80+
InstallDir = $installDir
81+
Quality = If ($usePreview) { "GA" } Else { "preview" }
82+
}
83+
84+
if ($packageType -eq 'runtime') {
85+
$installParams.add('Runtime', 'dotnet')
86+
}
87+
88+
& ./dotnet-install.ps1 @installParams
89+
Remove-Item dotnet-install.ps1 -ErrorAction:Ignore
90+
91+
# Propagate values back out to pipeline ####################
92+
Write-Host "##vso[task.setvariable variable=DOTNET_ROOT]${installDir}"
93+
Write-Host "##vso[task.prependpath]${installDir}"
94+
displayName: 'Install dotnet ${{ parameters.version }} ${{ parameters.packageType }} for Windows ${{ parameters.windowsArchitecture }}'
95+
condition: eq(variables['Agent.OS'], 'Windows_NT')
96+
97+
- task: UseDotNet@2
98+
displayName: 'Install dotnet ${{ parameters.version }} ${{ parameters.packageType }}'
99+
inputs:
100+
${{ if ne(parameters.installDir, '') }}:
101+
installationPath: '${{ parameters.installDir }}'
102+
${{ else }}:
103+
installationPath: '$(Agent.ToolsDirectory)'
104+
packageType: '${{ parameters.packageType }}'
105+
version: '${{ parameters.version }}.x'
106+
107+
includePreviewVersions: '${{ parameters.usePreview }}'
108+
condition: ne(variables['Agent.OS'], 'Windows_NT')

eng/pipelines/common/templates/steps/pre-build-step.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44
# See the LICENSE file in the project root for more information. #
55
#################################################################################
66
steps:
7-
- task: UseDotNet@2
8-
displayName: 'Use .NET 9.x sdk'
9-
inputs:
10-
packageType: sdk
11-
version: '9.x'
7+
- template: ./ensure-dotnet-version.yml@self
8+
parameters:
9+
packageType: 'sdk'
10+
version: '9.0'
1211

13-
- task: UseDotNet@2
14-
displayName: 'Install .NET 8.x runtime'
15-
inputs:
16-
packageType: runtime
17-
version: '8.x'
12+
- template: ./ensure-dotnet-version.yml@self
13+
parameters:
14+
packageType: 'runtime'
15+
version: '8.0'
1816

1917
- script: SET
2018
displayName: 'Print Environment Variables'

src/Microsoft.Data.SqlClient.sln

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "steps", "steps", "{EABE3A3E
270270
..\eng\pipelines\common\templates\steps\run-all-tests-step.yml = ..\eng\pipelines\common\templates\steps\run-all-tests-step.yml
271271
..\eng\pipelines\common\templates\steps\update-config-file-step.yml = ..\eng\pipelines\common\templates\steps\update-config-file-step.yml
272272
..\eng\pipelines\common\templates\steps\update-nuget-config-local-feed-step.yml = ..\eng\pipelines\common\templates\steps\update-nuget-config-local-feed-step.yml
273+
..\eng\pipelines\common\templates\steps\configure-sql-server-macos-step.yml = ..\eng\pipelines\common\templates\steps\configure-sql-server-macos-step.yml
274+
..\eng\pipelines\common\templates\steps\ensure-dotnet-version.yml = ..\eng\pipelines\common\templates\steps\ensure-dotnet-version.yml
273275
EndProjectSection
274276
EndProject
275277
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libraries", "libraries", "{75BAE755-3A1F-41F2-9176-9F8FF9FEE2DD}"

0 commit comments

Comments
 (0)