arcade icon indicating copy to clipboard operation
arcade copied to clipboard

Arcade scripting ignores DOTNET_INSTALL_DIR if additional runtimes are specified

Open mmitche opened this issue 2 years ago • 3 comments

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

mmitche avatar Dec 13 '23 15:12 mmitche

Related: https://github.com/dotnet/arcade/issues/14283

mmitche avatar Jan 03 '24 19:01 mmitche

@tkapin Is this a ProdCon issue?

missymessa avatar Jan 11 '24 21:01 missymessa

Yes, UB, but belongs to arcade. Labelled the issue accordingly.

tkapin avatar Jan 19 '24 13:01 tkapin