diff --git a/eng/pipelines/common/templates/jobs/ci-code-coverage-job.yml b/eng/pipelines/common/templates/jobs/ci-code-coverage-job.yml index 833f2da39c..c5e6118731 100644 --- a/eng/pipelines/common/templates/jobs/ci-code-coverage-job.yml +++ b/eng/pipelines/common/templates/jobs/ci-code-coverage-job.yml @@ -44,10 +44,10 @@ jobs: - task: NuGetAuthenticate@1 displayName: 'NuGet Authenticate' - - task: UseDotNet@2 - displayName: 'Use .NET SDK 8.0.x' - inputs: - version: 8.0.x + - template: ../steps/ensure-dotnet-version.yml@self + parameters: + packageType: 'sdk' + version: '8.0.x' - ${{ parameters.downloadArtifactsSteps }} diff --git a/eng/pipelines/common/templates/jobs/ci-run-tests-job.yml b/eng/pipelines/common/templates/jobs/ci-run-tests-job.yml index dcd3166c88..9ce139f113 100644 --- a/eng/pipelines/common/templates/jobs/ci-run-tests-job.yml +++ b/eng/pipelines/common/templates/jobs/ci-run-tests-job.yml @@ -231,26 +231,20 @@ jobs: referenceType: ${{ parameters.buildType }} testSet: ${{ parameters.testSet }} operatingSystem: ${{ parameters.operatingSystem }} - - - ${{ if and(eq(parameters.enableX86Test, true), eq(parameters.operatingSystem, 'Windows')) }}: # run x86 tests - - powershell: | - dotnet --info - - Invoke-WebRequest https://dot.net/v1/dotnet-install.ps1 -OutFile dotnet-install.ps1 - - # install .net x86 - $version = "LTS" - if (!"${{parameters.targetFramework }}".StartsWith("net4")) - { - $version = "${{parameters.targetFramework }}".Substring(3, "${{parameters.targetFramework }}".Length-3) - } - - .\dotnet-install.ps1 -Channel $version -Architecture x86 -InstallDir "$(dotnetx86RootPath)" - - $(dotnetx86RootPath)dotnet.exe --info - displayName: 'Install .NET x86 ' - condition: ne(variables['dotnetx86RootPath'], '') - + + - ${{ if and(eq(parameters.enableX86Test, true), eq(parameters.operatingSystem, 'Windows')) }}: + # Set up for x86 tests by manually installing dotnet for x86 to an alternative location. This + # is only used to execute the test runtime (framework to test is specified in build params), so + # it should be acceptable to just install a specific version in all cases. + - ${{ if ne(variables['dotnetx86RootPath'], '') }}: + - template: ../steps/ensure-dotnet-version.yml + parameters: + installDir: $(dotnetx86RootPath) + packageType: sdk + usePreview: false + version: 9.x + windowsArchitecture: x86 + - template: ../steps/run-all-tests-step.yml@self parameters: debug: ${{ parameters.debug }} diff --git a/eng/pipelines/common/templates/steps/ci-prebuild-step.yml b/eng/pipelines/common/templates/steps/ci-prebuild-step.yml index b8771702dd..2bbaa5d15a 100644 --- a/eng/pipelines/common/templates/steps/ci-prebuild-step.yml +++ b/eng/pipelines/common/templates/steps/ci-prebuild-step.yml @@ -20,17 +20,17 @@ parameters: - Package steps: -- task: UseDotNet@2 - displayName: 'Use .NET 9.x sdk' - inputs: +- template: ensure-dotnet-version.yml + parameters: packageType: sdk - version: '9.x' + usePreview: false + version: 9.x -- task: UseDotNet@2 - displayName: 'Install .NET 8.x runtime' - inputs: +- template: ensure-dotnet-version.yml + parameters: packageType: runtime - version: '8.x' + usePreview: false + version: 8.x - ${{if eq(parameters.debug, true)}}: - powershell: | diff --git a/eng/pipelines/common/templates/steps/ci-project-build-step.yml b/eng/pipelines/common/templates/steps/ci-project-build-step.yml index 9f0d7ad863..7bbea49032 100644 --- a/eng/pipelines/common/templates/steps/ci-project-build-step.yml +++ b/eng/pipelines/common/templates/steps/ci-project-build-step.yml @@ -34,17 +34,15 @@ parameters: - all steps: -- task: UseDotNet@2 - displayName: 'Use .NET 9.x sdk' - inputs: - packageType: sdk - version: '9.x' +- template: ./ensure-dotnet-version.yml@self + parameters: + packageType: 'sdk' + version: '9.x' -- task: UseDotNet@2 - displayName: 'Install .NET 8.x runtime' - inputs: - packageType: runtime - version: '8.x' +- template: ./ensure-dotnet-version.yml@self + parameters: + packageType: 'runtime' + version: '8.x' - ${{ if or(eq(parameters.operatingSystem, 'Windows'), eq(parameters.operatingSystem, 'deferedToRuntime')) }}: - ${{ if or(eq(parameters.build, 'MDS'), eq(parameters.build, 'all')) }}: diff --git a/eng/pipelines/common/templates/steps/ensure-dotnet-version.yml b/eng/pipelines/common/templates/steps/ensure-dotnet-version.yml new file mode 100644 index 0000000000..de940d9869 --- /dev/null +++ b/eng/pipelines/common/templates/steps/ensure-dotnet-version.yml @@ -0,0 +1,105 @@ +################################################################################# +# Licensed to the .NET Foundation under one or more agreements. # +# The .NET Foundation licenses this file to you under the MIT license. # +# See the LICENSE file in the project root for more information. # +################################################################################# + +# Installs dotnet sdk/runtime using UseDotNet on non-windows agents, but uses a custom ps script +# for installation on Windows. +# +# Reason for not using UseDotNet task: +# [BUG]: UseDotNet task installs x86 build on Windows arm64 +# https://github.com/microsoft/azure-pipelines-tasks/issues/20300 + +parameters: + - # Directory where dotnet binaries should be installed. If not specified, defaults to the + # agent's tools directory. + name: installDir + type: string + default: '' + + - # Whether to install the full SDK or the "dotnet" runtime + name: packageType + type: string + values: + - runtime + - sdk + + - # Whether to enable preview versions of dotnet + name: usePreview + type: boolean + default: false + + - # Version to install - supports full major.minor.patch, but can be shortened to major.minor + # to get the latest within a given channel. + name: version + type: string + + - # Specifies the architecture to install, only applies on Windows agents. If not provided, + # defaults to the same architecture as the agent. + name: windowsArchitecture + type: string + default: '' + values: + - '' + - 'x86' + - 'x64' + - 'arm64' + +steps: + - ${{ if eq(Agent.OS, 'Windows_NT') }}: + - powershell: |- + # Propagate parameters from pipeline ####################### + $agentToolsDir = '$(Agent.ToolsDirectory)' + echo "agentToolsDir= $agentToolsDir" + + $architecture = '${{ parameters.windowsArchitecture }}' + echo "architecture= $architecture" + + $installDir = '${{ parameters.installDir }}' + echo "installDir= $installDir" + + $packageType = '${{ parameters.packageType }}' + echo "packageType= $packageType" + + $usePreview = ${{ parameters.usePreview }} + echo "usePreview= $usePreview" + + $version = ${{ parameters.version }} + echo "version= $version" + + # Install dotnet ########################################### + Invoke-WebRequest -Uri "https://dot.net/v1/dotnet-install.ps1" -OutFile "dotnet-install.ps1" + + $installDir = If ($installDir) { $installDir } Else { $agentToolsDir } + $installParams = @{ + Architecture = $architecture + Channel = $version + InstallDir = $installDir + Quality = If ($usePreview) { "GA" } Else { "preview" } + } + + if ($packageType -eq 'runtime') { + $installParams.add('Runtime', 'dotnet') + } + + & ./dotnet-install.ps1 @installParams + Remove-Item dotnet-install.ps1 -ErrorAction:Ignore + + # Propagate values back out to pipeline #################### + Write-Host "##vso[task.setvariable variable=DOTNET_ROOT]${$installDir}" + Write-Host "##vso[task.prependpath]${$installDir}" + displayName: 'Install dotnet ${{ parameters.version }} ${{ parameters.packageType }} for Windows ${{ parameters.windowsArchitecture }}' + + - ${{ else }}: + - task: UseDotNet@2 + displayName: 'Install dotnet ${{ parameters.version }} ${{ parameters.packageType }}' + inputs: + ${{ if ne(parameters.installDir, '') }}: + installationPath: '${{ parameters.installDir }}' + ${{ else }}: + installationPath: '$(Agent.ToolsDirectory)' + packageType: '${{ parameters.packageType }}' + version: '${{ parameters.version }}' + + includePreviewVersions: '${{ parameters.usePreview }}' diff --git a/eng/pipelines/common/templates/steps/pre-build-step.yml b/eng/pipelines/common/templates/steps/pre-build-step.yml index fed1a8d93e..1d83828533 100644 --- a/eng/pipelines/common/templates/steps/pre-build-step.yml +++ b/eng/pipelines/common/templates/steps/pre-build-step.yml @@ -4,16 +4,14 @@ # See the LICENSE file in the project root for more information. # ################################################################################# steps: -- task: UseDotNet@2 - displayName: 'Use .NET 9.x sdk' - inputs: - packageType: sdk +- template: ./ensure-dotnet-version.yml@self + parameters: + packageType: 'sdk' version: '9.x' -- task: UseDotNet@2 - displayName: 'Install .NET 8.x runtime' - inputs: - packageType: runtime +- template: ./ensure-dotnet-version.yml@self + parameters: + packageType: 'runtime' version: '8.x' - script: SET diff --git a/src/Microsoft.Data.SqlClient.sln b/src/Microsoft.Data.SqlClient.sln index a2608cc803..9d6b224554 100644 --- a/src/Microsoft.Data.SqlClient.sln +++ b/src/Microsoft.Data.SqlClient.sln @@ -269,6 +269,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "steps", "steps", "{EABE3A3E ..\eng\pipelines\common\templates\steps\run-all-tests-step.yml = ..\eng\pipelines\common\templates\steps\run-all-tests-step.yml ..\eng\pipelines\common\templates\steps\update-config-file-step.yml = ..\eng\pipelines\common\templates\steps\update-config-file-step.yml ..\eng\pipelines\common\templates\steps\update-nuget-config-local-feed-step.yml = ..\eng\pipelines\common\templates\steps\update-nuget-config-local-feed-step.yml + ..\eng\pipelines\common\templates\steps\configure-sql-server-macos-step.yml = ..\eng\pipelines\common\templates\steps\configure-sql-server-macos-step.yml + ..\eng\pipelines\common\templates\steps\ensure-dotnet-version.yml = ..\eng\pipelines\common\templates\steps\ensure-dotnet-version.yml EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libraries", "libraries", "{75BAE755-3A1F-41F2-9176-9F8FF9FEE2DD}"