Skip to content

Commit b8b5889

Browse files
committed
C#: Work around dead NuGet feeds
1 parent 62ab608 commit b8b5889

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

rewrite-csharp/csharp/OpenRewrite/CSharp/SolutionParser.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,39 @@ public static async Task<RestoreResult> RunAsync(string path, CancellationToken
7777
}
7878
}
7979

80+
/// <summary>
81+
/// Replacement NuGet feeds for defunct dotnet.myget.org sources.
82+
/// MyGet was shut down; packages migrated to Azure DevOps Artifacts (dnceng).
83+
/// </summary>
84+
private static readonly string AdditionalNuGetSources = string.Join(";",
85+
"https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json",
86+
"https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json",
87+
"https://pkgs.dev.azure.com/dnceng/public/_packaging/myget-legacy/nuget/v3/index.json");
88+
8089
private static async Task<RestoreResult> RunCoreAsync(string path, CancellationToken ct)
8190
{
8291
Log.Debug("dotnet restore: starting for {Path}", path);
8392
var sw = Stopwatch.StartNew();
84-
// Disable NuGet vulnerability audit — audit warnings treated as errors
85-
// (NU1902/NU1903) would fail restore, but we only need packages for parsing.
86-
var psi = new ProcessStartInfo("dotnet", $"restore \"{path}\" /p:NuGetAudit=false --ignore-failed-sources")
93+
// Relax restore for LST parsing: disable NuGet vulnerability audit
94+
// (NU1902/NU1903 would fail restore), ignore dead NuGet sources,
95+
// and add replacement feeds for defunct MyGet sources.
96+
var restoreArgs = string.Join(" ",
97+
$"restore \"{path}\"",
98+
"/p:NuGetAudit=false",
99+
"/p:RestoreIgnoreFailedSources=true",
100+
$"/p:RestoreAdditionalProjectSources=\"{AdditionalNuGetSources}\"",
101+
"--ignore-failed-sources");
102+
var psi = new ProcessStartInfo("dotnet", restoreArgs)
87103
{
88104
WorkingDirectory = Path.GetDirectoryName(path) ?? ".",
89105
RedirectStandardOutput = true,
90106
RedirectStandardError = true,
91107
UseShellExecute = false,
92108
CreateNoWindow = true
93109
};
110+
// Reduce NuGet retry attempts so dead feeds fail fast
111+
psi.Environment["NUGET_ENHANCED_MAX_NETWORK_TRY_COUNT"] = "1";
112+
psi.Environment["NUGET_ENHANCED_NETWORK_RETRY_DELAY_MILLISECONDS"] = "100";
94113

95114
using var process = Process.Start(psi);
96115
if (process == null)

0 commit comments

Comments
 (0)