SharpCoder
SharpCoder

Reputation: 19165

MSBuild : app.config is getting transformed for given environment but app.exe.config is not getting transformed

I am using MSBuild.exe to build our application. Along with App.Config, I have App.prod.config, app.qa.config, app.dev.config files.

On the command line, I enter following

C:\XXX\MyProject> C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe myBuildFile.build /p:Configuration=DEV

Above command, looks for app.config and app.dev.config files, Transform placeholders in App.dev.config & generate app.config file with entries from app.dev.config file.

After project is compiled, app.exe.config file is created. All this is working fine for me.

But for production, I am getting correctly transformed app.config file but the app.exe.config file is same as the default app.config file (without any transformation)

Following is the app.prod.config file:

<?xml version="1.0" encoding="utf-8" ?>
<!-- For more information on using transformations 
     see the web.config examples at http://go.microsoft.com/fwlink/?LinkId=214134. -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <connectionStrings>
       <add name="EventStore"
             connectionString="XXXXXXXXXXX"
             providerName="System.Data.SqlClient"
             xdt:Transform="SetAttributes"
             xdt:Locator="Match(name)"/>
    <add name="Profile"
         connectionString="XXXXXX"
         providerName="System.Data.SqlClient"
         xdt:Transform="SetAttributes"
         xdt:Locator="Match(name)"/>
    <add name="IdentityDB"
         connectionString="XXXXXXXXXXXXXXXXXXXXXXXX"
         providerName="System.Data.OracleClient"
         xdt:Transform="SetAttributes"
         xdt:Locator="Match(name)"/>
  </connectionStrings>
  <appSettings>
    <add key="ApplicationName"
         value="PROD"
         xdt:Transform="SetAttributes"
         xdt:Locator="Match(key)"/>
     </appSettings>
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(Debug)" />
  </system.web>
</configuration>

Upvotes: 1

Views: 985

Answers (1)

Guy
Guy

Reputation: 3096

By default, web.config is transformed on publish only. If you want to transform app.config or an xml document, then the best option is to install a Visual Studio extension called SlowCheetah

Upvotes: 1

Related Questions