When adding an Application Configuration file to a .Net project in Visual Studio it will be named app.config and will be renamed (on build) to ApplicationName.config.
I have a solution with about 40 projects. I want to add log4net functionality to quite a few of them. So for every project I would add a file app.log4net. I would then declare a post-build event like this:
copy $(ProjectDir)app.log4net $(TargetPath).log4net
That works just fine. But I was wondering whether there was a built-in way to achieve the same without an explicit post-build event.
Edit: While I like both solutions proposed by JaredPar and Simon Mourier, they don’t provide what I was hoping for. Having a custom tool or MsBuild rule for this makes it less transparent (for other programmers on the project) or at least more complicated than using the post-build event I am currently using. Nevertheless, I feel like MsBuild would be the correct place to solve similar issues.
In this case it’s not Visual Studio which is updating the name of app.config but instead it’s a core MSBuild rule which is independent of Visual Studio. If you want to emulate the app.config model this is the approach you should take
The two parts of the build sequence which control the copying of app.config are found in Microsoft.Common.targets.
First the name of the file is calculated
Next it is actually copied as a part of the build