fix(http-client-csharp): resolve PackageReference assemblies for cust…#10229
Open
JoshLove-msft wants to merge 5 commits intomicrosoft:mainfrom
Open
fix(http-client-csharp): resolve PackageReference assemblies for cust…#10229JoshLove-msft wants to merge 5 commits intomicrosoft:mainfrom
JoshLove-msft wants to merge 5 commits intomicrosoft:mainfrom
Conversation
…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>
commit: |
Contributor
|
No changes needing a change description found. |
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…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