Sunday, March 1, 2015

How to have different local web config settings for a Visual Studio ASP NET C Web TFS Project

Today we started an ASP.NET C# Project under VisualStudio 2012 using Team Foundation Server. We ran into the problem that we need to store some local path settings in the web.config file, but they are different on every developers computer.

How-I-fixed-it:
The solution is, to split the web.config up into several files and just reference the files using the configSource="sectionName.config" Attribute in the corresponding section in the web.config. Dont add these local files to the project, to not get them overwritten by each other.

Heres a sample:

web.config:
<applicationSettings>

<KCM.Properties.Settings configSource="KCM.Properties.Settings.config" />

</applicationSettings>

KCM.Properties.Settings.config:

xml version="1.0" encoding="utf-8" ?>

<KCM.Properties.Settings>

<setting name="DataStoragePath" serializeAs="String">

<value>D:inetpubftproot</value>

</setting>

</KCM.Properties.Settings>

Here i found the right information to get the solution:

http://code-inside.de/blog/2009/11/03/howto-eine-eigene-configsection-schreiben-custom-configsections/

http://blog.andreloker.de/post/2008/06/16/Keep-your-config-clean-with-external-config-files.aspx

http://www.tomot.de/en-us/article/5/asp.net/how-to-use-web.config-transforms-to-replace-appsettings-and-connectionstrings

https://devio.wordpress.com/2013/04/24/handling-web-config-variants-in-source-control-based-solutions/
for details click below

No comments:

Post a Comment