开发者

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

开发者 https://www.devze.com 2023-01-04 01:30 出处:网络
Currently I can easily setup Web.config transform based on build configuration, e.g. use connectionString=server;.. for Debug and connectionString=./SQLExpress;.. for Release.

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 开发者_JAVA技巧publish profile? I.e. use connectionString=server1;.. for profile Server1 and connectionString=server2;.. for Server2 ?


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.


There could be a slightly different way to do this.

On your production servers create a dummy entry, for customdb, in the c:\windows\system32\drivers\etc\hosts file on each of the production machines. Each one pointing to the database that you want that machine to use. Then you only have to point to the connectionString=customdb; for all your production servers.

Only downside of this would be that you would need access to the hosts file and it would require you to use a db.

Hope this helps


I believe that the publishing profiles are independent of the build profiles, which is a bit of a shame, as you could easily accidentally deploy a debug configuration to your production servers.

However, if you're using MSDeploy, there are ways to modify the web.config in there. See MSDeploy - Changing Connection string parameter after deploying the package for more details.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号