vstest
vstest copied to clipboard
Need a way to specify the config file for dotnet test
Description
This is coming up more and more with users porting from .NET Framework to .NET Core and looks like it might become critical for 3.0. For example: https://github.com/dotnet/corefx/issues/22101. System.Configuration loads configuration files next to the launching "app". In the case of dotnet test
the configuration file is testhost.dll.config
.
On .NET Framework you customize your default configuration file by tweaking AppDomainSetup and manually creating a domain. There are no domains in .NET Core, so the only real way to do this if you're going to insert yourself in front of the "app" is to copy the app's config to your location.
What this means is that there needs to be a way to specify the desired config file for vstest
and have it copy it to / into testhost.dll.config
. Or at the very least it should take what would normally be picked up and copy it. This, of course, requires testhost.dll
being copied local (or preferably hard linked) to the test assembly if it isn't already.
We're also looking at whether or not there may be a way to safely pipe through a configuration file name for 3.0. https://github.com/dotnet/corefx/issues/32095.
cc: @danmosemsft
@ShreyasRmsft any update on this? with the csproj nuget version allowing "*" the dotnet test fails
https://github.com/dotnet/runtime/issues/931 is fixed in .NET 6. Can I now expect that dotnet test
will be fixed one day to consider the right app.config
file?
We are thinking about using the built exe directly as the testhost, so that might fix it.
even with dotnet/runtime#931 I'm unable to get tests that depend on ConfigurationManager to read from the correct file in .NET6. I've added this to our [OneTimeSetUp]:
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", $"{Assembly.GetExecutingAssembly().Location}.config");
..it doesn't seem to have any effect at runtime it's still reading from testhost.dll.config when using the Test Explorer in VS, and when run from nunit-console from TeamCity it's reading nunit-agent.dll.config from nunit-console's bin path(!).
I can use a build hack to copy the settings file to testhost.dll.config which will get the local Test Explorer working but it still bombs on the build server. It looks like some people had momentary success messing with ConfigurationManager's internals via reflection but those methods aren't working in .NET6.