Reputation: 2008
Using VS 2012 C# .net 4.0, I have a project which builds a console application using ConfigurationManager for config. This all works very well.
I have a second project in the same solution which is used to test the first project (using nunit).
This nunit project includes the first project as a reference, and executes the first project's executable as a child process.
This doesn't work. Because, although the nunit project builds the first project's executable, it does not create the [first project executable].exe.config file.
Anyone know why not? And is there a button I can push to get [first project executable].exe.config created when I build the nunit project?
Upvotes: 0
Views: 565
Reputation: 2008
It might not be pretty, but adding pre-build event:
copy "$(SolutionDir)ConsoleApp\App.config" "$(TargetDir)ConsoleApp.exe.config"
solves my immediate problem.
Upvotes: 0
Reputation: 67296
Any time you use a config file, the file must be associated with the running process. In this case, the running process is your unit test project.
When you use ConfigurationManager
in the context of your unit tests, it will look for a config file (App.Config
) for the unit test project for the values.
You are referencing the console application assembly, but there is no way to reference the console application's configuration file inside of the unit test process.
So, you should add a new App.Config
to the unit test project and place your configuration values there.
Hope this helps.
Upvotes: 1