Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceAssemblies doesn't use NuGet config for current working directory #1209

Open
NWalker1208 opened this issue Feb 13, 2025 · 1 comment

Comments

@NWalker1208
Copy link

Currently, the Microsoft.CodeAnalysis.Analyzer.Testing.ReferenceAssemblies class has very limited configurability when it comes to the settings for NuGet. It allows you to specify a single NuGet config file, or none at all. If you don't specify a NuGet config file, it uses the system- and user-level config, but not the config for the current working directory. That is, it doesn't traverse the directory hierarchy searching for NuGet config files that should apply to the current directory. This is because, at this line in the code, it passes null as the root directory when loading NuGet settings. The root path is what the NuGet configuration library uses to identify configuration files that should apply to a given directory. By passing null, ReferenceAssemblies ignores all directory-scoped configuration files.

This causes problems for setups where essential config is located in multiple config files, and one or more of them are scoped to a directory. Specifying any single config file wouldn't capture everything that's required, and ReferenceAssemblies ignores all of the directory-scoped config files. In my case, I need ReferenceAssemblies to make use of a specific NuGet source that is configured in a directory-scoped config file generated by a CI pipeline. However, I can't point it to just that config file, as that would break my ability to run tests locally.
 
I would propose that the ReferenceAssemblies class should, at a minimum, allow one to specify the root path via something like WithNuGetConfigRoot(string root). Having it use the current working directory by default would likely be a breaking change, but at least allowing consumers of the class to configure that value would help a ton.

@sharwell
Copy link
Member

I would propose that the ReferenceAssemblies class should, at a minimum, allow one to specify the root path via something like WithNuGetConfigRoot(string root).

This seems fine.

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

No branches or pull requests

2 participants