Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS2010 Clean Web.configs - not updating

I'm messing around with MVC 2.0 on VS2010 and am having an issue getting the clean web config feature working.

Basically in my Web.debug.config I have

<connectionStrings xdt:Transform="Replace">
  <add name="ApplicationServices" 
    connectionString="Server=localhost;Database=SITE_DB;User ID=dbuser;Password=P@ssw0rd;Trusted_Connection=False;" />
</connectionStrings>

and in my `Web.config` I have

      <connectionStrings>
        <add name="ApplicationServices"
             connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
             providerName="System.Data.SqlClient" />
      </connectionStrings>

When I run the site in debug mode, I'd expect that xdt:Transform="Replace" would replace the entire connectionStrings section with what is in the Web.debug.config.

Am I assuming wrong? Or am I doing something else incorrect. Not much info posted around this and I'd figure I'd ask you guys.

like image 408
cw. Avatar asked Apr 14 '10 01:04

cw.


2 Answers

The .config transforms only occur when you publish or deploy the application in some way. If you're just debugging, the transforms don't happen.

This sounds crazy, but it's straight from the mouth of an MS rep: http://forums.asp.net/p/1532038/3711423.aspx

like image 107
Jared Harding Avatar answered Oct 10 '22 01:10

Jared Harding


You can enable this behavior, but you will need to make a "template" file to store your pre-transform state in a file that is not named Web.config, otherwise you would just overwrite your template with your transformed changes. You also need to add a transform task to your project file in order for it to execute when you debug.

<PropertyGroup>  
    <BuildDependsOn>  
        CustomWebConfigTransform;  
        $(BuildDependsOn);  
    </BuildDependsOn>  
</PropertyGroup>  
<Target Name="CustomWebConfigTransform">  
    <TransformXml source="Web.template.config"  
        transform="Web.$(Configuration).config"  
        destination="Web.config" />
</Target>  

The above example assumes you have a template web.config file named Web.template.config and will apply your transformation and create a Web.config file when you run the project.

Reference: http://www.kongsli.net/nblog/2012/01/13/enabling-web-transforms-when-debugging-asp-net-apps/

like image 20
NightOwl888 Avatar answered Oct 10 '22 00:10

NightOwl888