Skip to content

fix(http-client-csharp): resolve PackageReference assemblies for cust…#10229

Open
JoshLove-msft wants to merge 5 commits intomicrosoft:mainfrom
JoshLove-msft:fix/external-metadata-references
Open

fix(http-client-csharp): resolve PackageReference assemblies for cust…#10229
JoshLove-msft wants to merge 5 commits intomicrosoft:mainfrom
JoshLove-msft:fix/external-metadata-references

Conversation

@JoshLove-msft
Copy link
Copy Markdown
Contributor

…om code compilation

When custom code references types from external NuGet packages (e.g., Azure.Storage.Common.StorageSharedKeyCredential), the Roslyn compilation would fail because those assemblies weren't added as metadata references.

Parse the project's .csproj file for PackageReference items and resolve their assemblies from the NuGet global packages cache. This allows custom constructors and other user code that references external library types to compile correctly.

Fixes #10224

…om code compilation

When custom code references types from external NuGet packages (e.g.,
Azure.Storage.Common.StorageSharedKeyCredential), the Roslyn compilation
would fail because those assemblies weren't added as metadata references.

Parse the project's .csproj file for PackageReference items and resolve
their assemblies from the NuGet global packages cache. This allows
custom constructors and other user code that references external library
types to compile correctly.

Fixes microsoft#10224

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 1, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@10229

commit: 67ea3a7

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

No changes needing a change description found.

@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Apr 1, 2026
JoshLove-msft and others added 4 commits March 31, 2026 20:26
Parse .csproj PackageReference items and resolve assemblies from the
NuGet global cache. Fixes custom code that references external types
(e.g. StorageSharedKeyCredential) failing to compile.

Use fresh ProjectCollection to avoid MSBuild caching stale project
files. Use Configuration.PackageName for .csproj file discovery.

Tests:
- AddsReferencesFromCsproj: verifies assembly is added from NuGet cache
- SkipsWhenNoCsproj: no-op when project file doesn't exist
- SkipsPackageNotInCache: no-op when package isn't in cache

Fixes microsoft#10224

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When a PackageReference assembly isn't in the NuGet global cache,
download it from NuGet feeds using the existing NugetPackageDownloader.
This matches the pattern used by LoadBaselineContract and ensures
external references resolve even without a prior dotnet restore.

Update tests to async and verify graceful skip when packages can't
be found in cache or NuGet feeds.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Check existing metadata references before resolving from NuGet cache
or downloading. Packages already added (e.g., by a plugin via
AddMetadataReference) are skipped to avoid redundant downloads.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- SkipsAlreadyAddedReferences: verifies packages already in
  AdditionalMetadataReferences are not re-added
- AddsMultiplePackageReferences: verifies all PackageReference items
  are resolved, not just the first

Extract CreateFakeNuGetPackage helper to reduce duplication.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JoshLove-msft JoshLove-msft enabled auto-merge April 1, 2026 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Find a Solution to Handling External Metadata References

1 participant