0

I am trying to apply config transformation in one of my C# projects. I can see the transformation applied when I do "Preview transform" on my QA config file but when I do publish with QA profile, I can still see the default config (not the transformed one) in deployment. I do not want the transformation on the build (I know slowcheetah helps in that), I would need that on publishing only. Is there any changes we need to do in the .csproj file to enable the transformations on publishing.

EDIT: Adding the sample config request by gkb. We have entry in web.config:

<connectionStrings>
        <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\xxxx.mdf;Initial Catalog=xxxx;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>

AND I have below in my web.Debug-QA.config:

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

<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
  </connectionStrings>
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
  </system.web>
</configuration>
  • can you include a sample setting from your QA config to the question? – gkb Mar 21 '18 at 05:58
  • Added the sample config – Sandeep Tripathi Mar 21 '18 at 09:14
  • One clue I got is that When I am doing publish from Visual Studio 2015, build in "Release" mode gets triggered, doesn't matter which mode the project was build in or what build mode is selected from build dropdown list at the top in VS. Can anyone tell me why it would pick build mode as the release when I do Publish? – Sandeep Tripathi Mar 21 '18 at 11:41
  • Got it, my bad. Sometimes I wonder how stupid one can think when struggling with something. Option to select the profile is there in Settings tab of Publish Web dialog Window – Sandeep Tripathi Mar 21 '18 at 12:13
  • Is your issue fixed? If yes then please post what you did to solve it and mark it as the answer. – gkb Mar 22 '18 at 09:32
  • The issue is fixed, but not able to post answer as I don't have enough repo here. If you are really interested, let me know, I can mail for you to share here. – Sandeep Tripathi Mar 22 '18 at 20:45

1 Answers1

0

In our projects we have two different steps:

  1. transform with slow cheetah on build time
    (i know you wrote you do not want to use it but give it a try)

On build time we create tokens in our configs. app.release file looks like this:

<?xml version="1.0"?>
<!-- For more information on using app.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <appSettings>
    <add key="InstrumentationKey" value="__InstrumentationKey__" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
  </appSettings>
</configuration>

E.g. after a release build our app config looks like this:

<configuration>
    <appSettings>
        <add key="InstrumentationKey" value="__InstrumentationKey__" />
    </appSettings>
</configuration>
  1. on release time we do a replacement for the tokens for each specific environment

I don't know your release process... But in our case we have a list of replacements for each environment.

When we do a release all the Tokens (the guys with the two underscores) get replaced with the specific values for each environment.

Daniel
  • 9,491
  • 12
  • 50
  • 66