Question

First of all, we're not using the Web Application project, we're using the Web Site type of project.

In our project we have 3 build configurations, which are: Dev (for development), Demo (for testing) and Live (final release of course).

We have two files (but in the end it'll be 4) which are:

  • Web.config
  • Web.Dev.config

A snippet from the first:

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="SomeConnectionString" connectionString="oldConnStr" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <system.web>
    <compilation targetFramework="4.0" debug="false">
      <assemblies>
        <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
      </assemblies>
    </compilation>
  </system.web>
</configuration>

And this is the transformation:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <connectionStrings>
    <add name="SomeConnectionString" connectionString="newConnString" providerName="System.Data.SqlClient" xdt:Transform="Replace" xdt:Locator="Match(name)" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" xdt:Transform="SetAttributes(debug)" />
  </system.web>
</configuration>

It doesn'work at all, neither does the Web.config become 'expandable', screenshot:

Web.config isn't expandable
The icons are from Team Foundation Server

Does anyone know how to make this work?

Was it helpful?

Solution

I found out this can't be done in a Web Site project. It requires a .csproj file, and Web Site's don't have that.

OTHER TIPS

You need a configuration instance to match your web.config transformations. For example, in order for Web.Dev.config to compile and transform (during a web deploy etc.) you need to compile the project in the 'Dev' configuration.

If you don't have a Dev configuration defined (by default you usually get a Debug and Release configuration when starting a new VS project) you can click the drop-down box with all the available configurations listed. You can usually find this next to the green 'play' (start debugging) button in Visual Studio. Select the 'Configuration Manager ' option and then for your selected project, select the configuration drop down and select . You can then create a configuration called Dev (and copy the settings from an existing configuration if you need to). Be sure to refresh your project tree once this is done.

It's also worth noting that trasnformations are not applied during standard in VS builds (i.e Ctrl+Shift+B) builds. These usually applied when the application is released via Web Deploy or a deployment tool of some kind. The transformation applied will depend on the selected build configuration. I.e. deploy in 'Dev' configuration and your web.dev.config transformations will be applied.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top