Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions eng/common/tools.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,17 @@ function InitializeToolset() {
$downloadArgs += "--configfile"
$downloadArgs += $nugetConfig
}
DotNet @downloadArgs

# 'dotnet package download' fails outright if any source in the repo's NuGet.config is
# unavailable (for example a transport feed that was decommissioned after a release). The
# Arcade SDK is always published to the public dotnet-eng feed, so if the config-driven
# download fails, retry once against that feed directly (which ignores the other sources)
# before giving up, so a single dead source doesn't block the build.
$downloadExitCode = DotNet -ignoreFailure @downloadArgs
if ($downloadExitCode) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Create an issue in dotnet/sdk to support skipping unavailable sources when downloading a package.

Write-Host "Restoring the Arcade SDK from the configured sources failed; retrying from the public dotnet-eng feed."
DotNet @downloadArgs --source "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json"
}
Comment thread
akoeplinger marked this conversation as resolved.

$packageDir = Join-Path $nugetPackageCachePath (Join-Path 'microsoft.dotnet.arcade.sdk' $toolsetVersion)
$packageToolsetDir = Join-Path $packageDir 'toolset'
Expand Down Expand Up @@ -848,7 +858,7 @@ function MSBuild() {
# Executes a dotnet command with arguments passed to the function.
# Terminates the script if the command fails.
#
function DotNet() {
function DotNet([switch]$ignoreFailure) {
$dotnetRoot = InitializeDotNetCli -install:$restore
$dotnetPath = Join-Path $dotnetRoot (GetExecutableFileName 'dotnet')

Expand All @@ -867,6 +877,12 @@ function DotNet() {
$exitCode = Exec-Process $dotnetPath $cmdArgs

if ($exitCode -ne 0) {
# When -ignoreFailure is set, return the exit code to the caller so it can implement
# its own fallback logic instead of terminating the script.
if ($ignoreFailure) {
return $exitCode
}

Write-Host "dotnet command failed with exit code $exitCode. Check errors above." -ForegroundColor Red

if ($ci -and $env:SYSTEM_TEAMPROJECT -ne $null -and !$fromVMR) {
Expand Down
25 changes: 24 additions & 1 deletion eng/common/tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,16 @@ function InitializeToolset {
if [[ -n "$nuget_config" ]]; then
download_args+=("--configfile" "$nuget_config")
fi
DotNet "${download_args[@]}"

# 'dotnet package download' fails outright if any source in the repo's NuGet.config is
# unavailable (for example a transport feed that was decommissioned after a release). The
# Arcade SDK is always published to the public dotnet-eng feed, so if the config-driven
# download fails, retry once against that feed directly (which ignores the other sources)
# before giving up, so a single dead source doesn't block the build.
if ! DotNet true "${download_args[@]}"; then
echo "Restoring the Arcade SDK from the configured sources failed; retrying from the public dotnet-eng feed."
DotNet "${download_args[@]}" --source "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json"
fi

local package_dir="$_InitializeNuGetPackageCachePath/microsoft.dotnet.arcade.sdk/$toolset_version"

Expand Down Expand Up @@ -491,6 +500,15 @@ function StopProcesses {
}

function DotNet {
# When the first argument is 'true' or 'false' it controls the exit behavior on failure:
# 'true' returns the dotnet exit code to the caller (so it can implement its own fallback),
# while the default terminates the script. Any other first argument is treated as a dotnet argument.
local ignore_failure=false
if [[ "$1" == 'true' || "$1" == 'false' ]]; then
ignore_failure="$1"
shift
fi

InitializeDotNetCli $restore

local dotnet_path="$_InitializeDotNetCli/dotnet"
Expand All @@ -499,6 +517,11 @@ function DotNet {

"$dotnet_path" "$@" || {
local exit_code=$?

if [[ "$ignore_failure" == true ]]; then
return $exit_code
fi

echo "dotnet command failed with exit code $exit_code. Check errors above."

if [[ "$ci" == true && -n ${SYSTEM_TEAMPROJECT:-} && "$from_vmr" != true ]]; then
Expand Down
8 changes: 8 additions & 0 deletions src/Microsoft.DotNet.Arcade.Sdk/tools/ProjectDefaults.props
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@
{TargetFrameworkDirectory};
{RawFileName};
</AssemblySearchPaths>

<!--
Tolerate package sources that are unavailable (e.g. transport feeds that have been
decommissioned after a release). Restore falls back to the remaining sources instead
of failing outright. Can be overridden by setting RestoreIgnoreFailedSources explicitly.
See https://github.com/dotnet/runtime/issues/129694.
-->
<RestoreIgnoreFailedSources Condition="'$(RestoreIgnoreFailedSources)' == ''">true</RestoreIgnoreFailedSources>
</PropertyGroup>

<PropertyGroup>
Expand Down
Loading