Skip to content

Arcade scripting ignores DOTNET_INSTALL_DIR if additional runtimes are specified #14283

@mmitche

Description

@mmitche

Source-build uses DOTNET_INSTALL_DIR to force use of a specific SDK across all repos. However, if a repo specifies a set of additional runtimes to install this value is ignored.

Source-build avoids this issue today altogether by setting the toolset restore project (_InitializeToolset) to the path of the arcade SDK project. This short circuits the .NET SDK install process and thus we don't get a reset of the DOTNET_INSTALLR_DIR

  if ($useInstalledDotNetCli -and (-not $globalJsonHasRuntimes) -and ($env:DOTNET_INSTALL_DIR -eq $null)) {
    $dotnetExecutable = GetExecutableFileName 'dotnet'
    $dotnetCmd = Get-Command $dotnetExecutable -ErrorAction SilentlyContinue

    if ($dotnetCmd -ne $null) {
      $env:DOTNET_INSTALL_DIR = Split-Path $dotnetCmd.Path -Parent
    }
  }

  $dotnetSdkVersion = $GlobalJson.tools.dotnet

  # Use dotnet installation specified in DOTNET_INSTALL_DIR if it contains the required SDK version,
  # otherwise install the dotnet CLI and SDK to repo local .dotnet directory to avoid potential permission issues.
  if ((-not $globalJsonHasRuntimes) -and (-not [string]::IsNullOrEmpty($env:DOTNET_INSTALL_DIR)) -and (Test-Path(Join-Path $env:DOTNET_INSTALL_DIR "sdk\$dotnetSdkVersion"))) {
    $dotnetRoot = $env:DOTNET_INSTALL_DIR
  } else {
    $dotnetRoot = Join-Path $RepoRoot '.dotnet'

    if (-not (Test-Path(Join-Path $dotnetRoot "sdk\$dotnetSdkVersion"))) {
      if ($install) {
        InstallDotNetSdk $dotnetRoot $dotnetSdkVersion
      } else {
        Write-PipelineTelemetryError -Category 'InitializeToolset' -Message "Unable to find dotnet with SDK version '$dotnetSdkVersion'"
        ExitWithExitCode 1
      }
    }

    $env:DOTNET_INSTALL_DIR = $dotnetRoot
  }

We probably need the runtimes for the VMR build? (Unsure on this one)

T-Shirt Size: Medium

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-product-constructionIssues owned by the Product Construction team. Used to label epics and untriaged, loose issues.area-unified-build

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions