locked
How can i use a different web.config for QA or Dev environment ? RRS feed

  • Question

  • User1253338400 posted

    Hi ,

    I have a web project and a main / default web.config , but I have different environment, a Debug, QA, Dev, Release. 

    Now if I want to run on the Dev environment I need to manually copy the webDev.config as the web.config for the app, likewise if testing on QA.

    Is there an automation process for this ?

    I have looked at web transforms , but there are more than just connection string changes .

    Any suggestions as to how I can do this ?

    thanks

    Tuesday, March 26, 2019 5:19 AM

Answers

  • User-1174608757 posted

    Hi , robby32

    According to your description, visual studio transforms only web.config files by default, If you need custom config file with transformation for DEV, UAT, PROD, etc environments, then you could try below:

    1.Use custom extensions for Visual Studio like  SlowCheetah - XML Transforms for Config transformation preview functionality. You should download this package.

    This package allows you to automatically transform your app.config (or any file) when you press F5 in Visual Studio. You can have different transformations based on the build configuration. This will enable you to easily have different app settings, connection strings, etc for Debug versus Release. If you want to transform other files you can do that too. Here is the link, I hope it could help you.

    https://marketplace.visualstudio.com/items?itemName=vscps.SlowCheetah-XMLTransforms

    2.You could install SlowCheetah to your webapplcation 

    Here is the link, I hope it could help you.

    https://stackoverflow.com/questions/34735132/how-to-add-config-transformations-for-a-custom-config-file-in-visual-studio

    Best Regards

    Wei

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 27, 2019 7:15 AM

All replies

  • User-1038772411 posted

    Try with this, may be this will help you.

    The <appSettings> tag in web.config supports a file attribute that will load an external config with it's own set of key/values. These will override any settings you have in your web.config or add to them. We take advantage of this by modifying our web.config at install time with a file attribute that matches the environment the site is being installed to. We do this with a switch on our installer.

    For example;

    <appSettings file=".\EnvironmentSpecificConfigurations\dev.config">

    <appSettings file=".\EnvironmentSpecificConfigurations\qa.config">

    <appSettings file=".\EnvironmentSpecificConfigurations\production.config">

    Note:

    Changes to the .config specified by the attribute won't trigger a restart of the asp.net worker process

    Tuesday, March 26, 2019 7:58 AM
  • User1253338400 posted

    Hi,

    Is there an example to illustrate this .. how and where required changes are needed. 

    I sort of get what you mean. But where can I start to make changes.

    See I have in my app a web.config as the default and below that are 4 mor config files, webqa.config, webdev.config, webrelease.config, webtest.config.

    Now when I run the app , I want to be able to tell VS that if its run under a Dev environment then use the webdev.config as the web.config file.

    Also I use a CI tool and want to be able to tell when the CI pipeline is running in a particular mode then take that config file.

    thanks

    Tuesday, March 26, 2019 10:12 AM
  • User-1174608757 posted

    Hi , robby32

    According to your description, visual studio transforms only web.config files by default, If you need custom config file with transformation for DEV, UAT, PROD, etc environments, then you could try below:

    1.Use custom extensions for Visual Studio like  SlowCheetah - XML Transforms for Config transformation preview functionality. You should download this package.

    This package allows you to automatically transform your app.config (or any file) when you press F5 in Visual Studio. You can have different transformations based on the build configuration. This will enable you to easily have different app settings, connection strings, etc for Debug versus Release. If you want to transform other files you can do that too. Here is the link, I hope it could help you.

    https://marketplace.visualstudio.com/items?itemName=vscps.SlowCheetah-XMLTransforms

    2.You could install SlowCheetah to your webapplcation 

    Here is the link, I hope it could help you.

    https://stackoverflow.com/questions/34735132/how-to-add-config-transformations-for-a-custom-config-file-in-visual-studio

    Best Regards

    Wei

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 27, 2019 7:15 AM