Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 29, 2026

dotnet up makes HTTP requests from two sources: the Microsoft.Deployment.DotNet.Releases library (for release metadata) and DotnetArchiveDownloader (for archive downloads). Both were using the same or no custom user-agent, making usage metrics indistinguishable.

Changes

  • New ReleaseLibraryInitializer: Uses reflection to set custom user-agent on the library's internal static HttpClient

    • Library calls: dotnetup-library/{version}
    • Direct dnup calls: dotnetup-dotnet-installer/{version} (unchanged)
  • Initialization: Called early in InstallerOrchestratorSingleton.Install() and SdkInstallCommand.Execute() before first library use

  • Error handling: Graceful degradation if reflection fails; logs to Debug output but doesn't break functionality

Implementation

The library's Utils.s_httpClient is accessed via reflection since it's internal:

var utilsType = Type.GetType("Microsoft.Deployment.DotNet.Releases.Utils, Microsoft.Deployment.DotNet.Releases");
var httpClientField = utilsType.GetField("s_httpClient", BindingFlags.Static | BindingFlags.NonPublic);
var httpClient = httpClientField.GetValue(null) as HttpClient;
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd($"dotnetup-library/{version}");

Thread-safe singleton pattern with _initialized flag prevents redundant reflection attempts.

Original prompt

This section details on the original issue you should resolve

<issue_title>dotnet up should use a separate header for library calls</issue_title>
<issue_description>dotnet up uses a custom agent header for http requests so our websites can figure out usage metrics and also prevent our client from being throttled. It uses the same metadata regardless of if the request if coming from the library or dnup itself in the ReleaseManifest, so we should try to differentiate the two. </issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Update header for library calls in dotnet up Differentiate user-agent headers for library vs dnup HTTP calls Jan 29, 2026
Copilot AI requested a review from nagilson January 29, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants