locked
Setting up and checking config transforms for App.config RRS feed

  • Question

  • User1314407993 posted

    I read a couple articles on setting this up, such as this one: http://vishaljoshi.blogspot.com/2010/05/applying-xdt-magic-to-appconfig.html

    But I was left with a couple questions. First, the article said to add the following to the .csproj file: <ProjectConfigFileName>App.Config</ProjectConfigFileName>

    I get the squiggly line and an error saying this isn't a valid child element. The project still loads and builds, but this concerned me. Anyway, the point behind this was to override the default of using "Web.config" for the config files. 

    My second question is much more basic - how do I test these transforms? This is a console app project inside a solution with several others, including a web application. The transforms I have to set up are App.TEST.config and App.PROD.config. How can I cause the TEST/PROD configs to be generated so I can check they're working correctly?

    Thursday, September 15, 2016 5:35 PM

Answers

  • User2117486576 posted

    The AppSettings element of the web.config has a file attribute you can use to include settings from an external file.

    <appSettings file="appSettings.config">
        <add key="webpages:Version" value="3.0.0.0" />
        <add key="webpages:Enabled" value="false" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    </appSettings>

    I use an external appSettings file on my development machine but do any transforms directly in the <appSettings> element in the individual build configuration transforms.

    You can test the transform in Visual Studio by right clicking in Solution Explorer and selecting Preview Transform from the context menu.  For instance if you want to check the transform for the Release build, right click on Web.Release.config and select Preview Transform.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 16, 2016 1:52 PM
  • User-166373564 posted

    HI,

    This is the reference in config file:

    1. <Target Name="AfterBuild">  
    2.   <TransformXml Source="@(AppConfigWithTargetPath)" Transform="$(ProjectConfigTransformFileName)" Destination="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')" />  
    3. </Target>  

    Regards,

    Angie

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, September 17, 2016 11:08 PM

All replies

  • User2117486576 posted

    The AppSettings element of the web.config has a file attribute you can use to include settings from an external file.

    <appSettings file="appSettings.config">
        <add key="webpages:Version" value="3.0.0.0" />
        <add key="webpages:Enabled" value="false" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    </appSettings>

    I use an external appSettings file on my development machine but do any transforms directly in the <appSettings> element in the individual build configuration transforms.

    You can test the transform in Visual Studio by right clicking in Solution Explorer and selecting Preview Transform from the context menu.  For instance if you want to check the transform for the Release build, right click on Web.Release.config and select Preview Transform.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 16, 2016 1:52 PM
  • User-166373564 posted

    HI,

    This is the reference in config file:

    1. <Target Name="AfterBuild">  
    2.   <TransformXml Source="@(AppConfigWithTargetPath)" Transform="$(ProjectConfigTransformFileName)" Destination="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')" />  
    3. </Target>  

    Regards,

    Angie

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, September 17, 2016 11:08 PM