Friday, 23 January 2015

How can I easily have different app.config files for different build configurations in MSBUILD?

There are a few different proposed solutions I have seen suggested, some including recommendations involving 3rd party tools and Visual Studio Transformation Extensions. The following is the simplest method I have found. It involves a violation of the DRY principle (Don't Repeat Yourself) as the app.config files are duplicated (due to the lack of transforms) - but I considered this to be a small sacrifice based on the simplicity of the solution.

Steps:
1) Unload your Project file (csproj) file in Visual Studio and Right click and select "Edit {My Project Name}.csproj" on that same file to edit it.
2) Add a folder for each MSBUILD configuration that you want and put your different App.Config files in those subfolders e.g. \Release\App.config and \Debug\App.Config
2) Find the section in your csproj project file <None Include="App.config" /> and replace it with the following conditional Include statements for each of your MSBUILD configurations:
<None Condition=" '$(Configuration)' == 'Debug' " Include="Debug\App.config" />
<None Condition=" '$(Configuration)' == 'Release' " Include="Release\App.config" />

When you build, it will use either of the application configuration files that you have created and put them in the relevant build configuration output directory.

DDK

9 comments:

Anonymous said...

Hey did you hear about Togaf Training ? TOGAF Certification is one of the top 10 in demand skills in technology, and people with that skill are making money or more. Learn how to get certified quickly and give wings to your carrer.‬

Devi.Angularjs said...

I have read your blog its very attractive and impressive. I like it your blog.

.Net Training in Chennai | .Net Online Training

Dot Net Online Training | LINQ Online Training ASP.NET Online Training

Mobile app development company in Gurgaon said...

Mobile app development company in Canada

Unknown said...

Rice Packaging Bags Manufacturers
Pouch Manufacturers

Unknown said...

we have provide the best ppc service in Gurgaon.
ppc services in gurgaon
website designing company in Gurgaon
PPC Expert For Technical Support

Unknown said...

we have provide the best fridge repair service.
fridge repair in faridabad
Bosch Fridge Repair in Faridabad
Godrej Fridge Repair in Faridabad
Haier Fridge Repair in Faridabad
Videocon Fridge Repair in Faridabad

Unknown said...

Bali Honeymoon Packages From Delhi
Bali Honeymoon Packages From Chennai
Hong Kong Packages From Delhi
Europe Packages from Delhi

IT Tutorials said...

Really useful information. Thank you so much for sharing.It will help everyone.Keep Post. RPA training in chennai | RPA training in Chennai with placement | UiPath training in Chennai | UiPath Chennai

Rithi Rawat said...

Outstanding blog thanks for sharing such wonderful blog with us ,after long time came across such knowlegeble blog. keep sharing such informative blog with us.

machine learning training in chennai
artificial intelligence and machine learning course in chennai
big data course in chennai
big data training and placement in chennai