I am using the solution to this question in order to apply configuration changes to App.config
in a Winforms project. I also have an installer project for the proj
First of all: it is impossible to make the Setup Project point to another app.config
file by using the Primary output
option. So my solution is going to be a work around. I hope you find it useful in your situation.
Overview:
The basic idea is:
app.config
from the Setup Project;app.config
, manually;vdproj
file, and change it to match the real output of the transformed app.config.Some drawbacks are:
Lets Work:
1) Go to your Setup Project, and select the Primary Output object, right click and go to Properties. There you will find the Exclude Filter
... add a filter for *.config
, so it will remove the hard-coded app.config.
2) Right click your Setup Project in the Solution Explorer -> Add -> File... select any file that ends with .config
.
3) Download MSBuild Community Tasks Project, I recomend the msi installer.
4) Unload your project (the csproj) and replace the code from the other question with this one:
Code:
$(TargetFileName).config
$(MSBuildProjectDirectory)\$(IntermediateOutputPath)$(TargetFileName).config
5) The previous code must be changed, so that it can find your vdproj file. I have placed a comment in the code, indicating where you need to make the change.
Now, everytime you build your main project, the MSBuild will change the Setup project, so that it uses the correct app.config file. It may have drawbacks, but this solution can be polished and become better. If you need leave a comment, and I'll try to respond ASAP.
Resources I Used
MSBuild 4.0 is needed because I need to use String's Replace function, to replace single "\" to double "\" in the path. See MSBuild Property Functions for details about using function in MSBuild.
I learned about the FileUpdate Task in this other question. The official project is MSBuild Community Tasks Project.
These two topics were important to my findings:
Trying to include configuration specific app.config files in a setup project
Problems with setup project - am I thick?