Thursday, April 19, 2007 11:09 AM
I have the following pre-build commands:
copy "$(ProjectDir)$(ConfigurationName).appSettings.config" "$(ProjectDir)$(OutDir)appSettings.config" /Y
copy "$(ProjectDir)$(ConfigurationName).databaseConfig.config" "$(ProjectDir)$(OutDir)databaseConfig.config" /Y
Which copy environmental specific config files accross to my output directory. E.g.
if working in localhost, the localhost.appSettings.config gets copied accross to bin/localhost/appSettings.config. This is so my single app.config can just reference the right sections using configSource="" but have the files physically vary depending on the kind of release
This all works fine, but how do I make it work in conjunction with a setup project?
When I look at the primary output for the project it shows my exe and app.config file but not the two new files. How can I reference a file using this tool that it wont know about until build time? Should I try some way to write some commands to copy to the setup directory as well?
Thursday, April 19, 2007 1:30 PMModeratorYou have two options, have the primary build always favor the release version of the config, or write a custom action to the installation process which asks the user to select a configuration which is appropriate.
Here are some links to get you started
Visual Studio Setup - projects and custom actions
ClickOnce and Setup & Deployment Projects (MSDN Forum)
Setup and Deployment Project FAQ
Thursday, April 19, 2007 2:44 PMYou can add them as files to the setup application folder.
Thursday, April 19, 2007 6:12 PMModerator
The files you copy should be copied to the project directory (not the output directory) and those files should be in the project and marked as "Content".
For example, change your pre-build event to copy "$(ProjectDir)$(ConfigurationName).appSettings.config" "$(ProjectDir)appSettings.config" /Y
Ensure your solution looks like something like this:
Solution 'My Solution' (1 projects)
and the properties for appSettings.config have "Build Action" equal to "Content".
By having appSettings.config in the project (i.e. you see it in the solution explorer) and marked as "Content" means Visual Studio will manage copying that file to the output directory (regardless of solution configuration selected, much the same as using $(OutDir)); but the file is version controlled and will automatically be included in a setup/deployment project (because it's tagged as "content").
Drawback is, if you're using revision control you may need to add something to your pre-build script to remove read-only attributes before copying.
If what you really want is to do this with app.config, you don't need the "Build Action" set to "Content"; Visual Studio does all that for you (app.config is "special").
Thursday, April 19, 2007 7:54 PM
Thanks for all your help guys.
In the end this is how I did it - (1) add another two lines to the pre-build event that copies the appropriate .config files to the output directory. These new lines take the copied files and make another copy to the setup project folder. (2) add "dummy" files (before the solution is built for the first time at least) to the setup project. (3) tell the setup to include these in the build of the MSI. Because the setup project gets built last it now should always bundle the .config files in with the setup.