Last post Aug 12, 2014 03:20 PM by MetalAsp.Net
Aug 12, 2014 01:07 PM|vmhatup|LINK
Part of my web.config currently looks like the following. As you can see, there are two exact keys for
EmailCC and ConnString; when I test locally, I comment one. When I publish, I have to comment the other one:
<!--<add key="EmailCC" value="LIST OF MANY USERS FROM PRODUCTION ENVIRONMENT"/>-->
<add key="EmailCC" value="JUST ME, FOR TESTING"/>
<!--<add name="ConnString" connectionString="Data Source=LIVE_SERVER;Initial Catalog=DB;Persist Security Info=True;User ID=LIVE;Password=LIVE;" providerName="System.Data.SqlClient"/>-->
<add name="ConnString" connectionString="Data Source=STAGING;Initial Catalog=DB;Persist Security Info=True;User ID=STAGING;Password=STAGING;" providerName="System.Data.SqlClient"/>
What would I need to do so that my local debugging automatically reads from web.debug.config, and when I publish it'll copy web.config? I've read about this, but what I've found is not clear.
My project already has web.debug.config and web.release.config, so "Add Config Transformations" is disabled.
We have VS2010 and framework 4.0.
Aug 12, 2014 01:24 PM|MetalAsp.Net|LINK
This page explains Web.config transformations: http://msdn.microsoft.com/en-us/library/dd465326(v=vs.110).aspx
so the idea is that when you select Debug and build it'll use the stuff in web.debug.config and when you select Release it'll use the web.release.config. You can, of course, create more/other build configurations as needed.
Aug 12, 2014 02:31 PM|vmhatup|LINK
Thanks, I had already seen that link.
I understand that in theory, that's the purpose. But the link you provided doesn't seem to explain it correctly.
The first example in the link shows the contents of a transform file that changes the contents of web.config. It doesn't show how it's created, its name, and definitely doesn't show the use of web.debug.config.
I just want to see a simple example of how web.debug.config will be used when debugging. So essentially, web.debug.config and web.config should be practically identical.
Aug 12, 2014 02:49 PM|vmhatup|LINK
Looking at web.debug.config, it looks like the following:
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an atrribute "name" that has a value of "MyDB".
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
What I did to test: I uncommented that section in web.debug.config and changed text "MyDB" to "ConnString", which is the name I use to get the connection string. So in theory, when I debug the site, everything should break since I don't have a server called
"ReleaseSQLServer". Unfortunately, everything works and data is displayed, which means that it didn't read from web.debug.config but from web.config.
Aug 12, 2014 03:07 PM|vmhatup|LINK
Finally understood it.
Only when publishing, the contents of web.config will be replaced with the contents that matches the attribute in web.debug.config or web.release.config. With xdt:Transform="Replace" and I'm publishing in Debug, then the whole line
in web.config will be replaced by the attribute in web.debug.config. If I publish in Release mode, then it will use web.release.config. xdt:Transform="SetAttribute"
just sets the attribute of the key.
I appreciate the help, but that link is just horrible. I'm not sure how something so simple can look so complex and confusing in a document.
Aug 12, 2014 03:20 PM|MetalAsp.Net|LINK
The contents of Web.config are transformed based on what you have in Web.debug. config or Web.release.config bard on whether you select Debug/Release for the build configuration. When I first used transformation n that wad the link I used and I just played
around with it a bit to get it to work and to prove that it works. And it does!
So I suggest you do the same. Just transform a simple attribute, say the connectionstring value for example. Use a different value in debug.config than in release.config. then simply build in debug and write out the connectionstring value to the page. Then
build in release and do the same. You'll be pleasantly surprised.