Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to link Web.config transform with publishing profile?

Currently I can easily setup Web.config transform based on build configuration, e.g. use connectionString=server;.. for Debug and connectionString=./SQLExpress;.. for Release.

But is it possible to do some Web.config transformation basing on web publish profile? I.e. use connectionString=server1;.. for profile Server1 and connectionString=server2;.. for Server2 ?

like image 964
abatishchev Avatar asked Jun 21 '10 19:06

abatishchev


People also ask

Does dotnet publish create Web config?

Bookmark this question. Show activity on this post. dotnet publish -c Release doesn't create this web. config , so I created itself and put it in the solution (odd, because I've never had to do this before).

How do I create a new transformation in Web config?

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).

What is Web config transform?

A Web. config transformation file contains XML markup that specifies how to change the Web. config file when it is deployed. You can specify different changes for specific build configurations and for specific publish profiles.


1 Answers

We keep all machine/profile specific configuration in separate config files, then use configSource to include them like so...

    <connectionStrings configSource="cstrings.config"/>

This way Web.config is the same and doesn't require any transformations. We do this for connection strings, smtp settings and app settings.

We version control Web.config and "machine specific" files such as cstrings.config.production, cstrings.config.staging, etc.

Once you have this structure it's easy to generate images for different profiles. We have deployment scripts on each machine that read an environment variable and deploy appropriately. For example, the staging server build script copies cstrings.config.staging to cstrings.config, etc.

like image 176
Rob Avatar answered Sep 19 '22 10:09

Rob