roslyn-sdk
roslyn-sdk copied to clipboard
ReferenceAssemblies doesn't use NuGet config for current working directory
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.