86

I am having a website developed in Visual Studio 2012. The web.config is currently containing following files in its transformation: - web.Debug.config - web.Release.config

I have recently added a new build configuration (named as "Staging") in my project. How can I create a "web.Staging.config" transformation file?

Nirman
  • 6,715
  • 19
  • 72
  • 139

3 Answers3

133

There are two ways for the web.config transform files to be generated within VS:

  1. If you have a web application project, Right-click on web.config and choose Add Config Transform. This will add any config transforms that are missing from your project based on build configurations (i.e. if you have Production and Staging build configs, both will get a transform added).
    • This method is not supported for Website projects as they do not support multiple build configurations.
  2. In either web project type, right click on a publish profile (.pubxml) and choose Add Config Transform. This will add a new config transform for that profile only.
    • This requires VS2012 Update 2 or the Azure SDK 2.0 for VS2010 (I think).
    • In a web site project, the new transform file will not be nested under web.config as VS doesn't support that behavior. Just look for it in the root folder.
Jimmy
  • 27,142
  • 5
  • 87
  • 100
  • 4
    In a Website project type, find the _.pubxml_ under the /App_Data/PublishProfiles/ subdirectory. VS2012 creates this when you set up a Publish Web Site project (by right clicking the Web Site in Solution Explorer). – subsci Oct 01 '13 at 20:11
  • See these instructions for creating a profile. No need to click the "Publish" button at the end of the wizard if you are manually publishing the application. http://stackoverflow.com/questions/13441692/how-to-add-publishing-profile-to-a-new-sln-in-vs2012 – JustBeingHelpful Jun 02 '14 at 21:13
  • 1
    See spadelives answer if you right click but do not see "Add Config Transform" as an option – Tom Gerken Jun 18 '15 at 01:04
  • 8
    Right clicking on web.config does not show any **Add Config Transform** command. – Jonathan Wood Jun 13 '17 at 19:39
51

IN VS 2012:

  1. Go to Build->Configuration Manager
  2. Click on the Active solutions configuration and select "New".
  3. Enter the name of your new configuration and click Save.
  4. Right click on your Web.config file and select Add Config Transform.

Your new transform file will be automatically created.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
spadelives
  • 1,588
  • 13
  • 23
  • 5
    No such option appears when right clicking *web.config* for me. – Jonathan Wood Jun 13 '17 at 19:40
  • 3
    Years later I know, but you won't see this option if you *already have* a web config transform for all of the existing Build configurations - i.e. if you have Debug and Realease build configs, and you already have Web.Debug.config and Web.Release.config transforms, you won't see the option - you would have to add a *new* build configuration, hence the instruction in the answer above! – Breeno Dec 11 '17 at 21:45
  • Ran into this issue when adding a new project to a solution that had other configurations. Eventually realized that the profile didn't exist on my project, only at the solution level and within the old existing projects. So you may need to double check your project is not defaulting to another configuration when added. – Brandon Barkley Aug 20 '19 at 18:23
  • Only thing that worked for me, thanks! I am using Visual Studio 2017. – Niveditha Karmegam Sep 11 '19 at 04:21
  • This is not supported to web project type. – Hammad Sajid Nov 01 '22 at 21:26
6

You need to first install the Configure Transform extension [Extensions -> Manage Extensions -> Online section] to see the option when right-clicking your web.{environment}.config files.

silkfire
  • 24,585
  • 15
  • 82
  • 105