在开发和生产环境使用不同的Web.config [英] Using different Web.config in development and production environment

查看:129
本文介绍了在开发和生产环境使用不同的Web.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用不同的数据库连接字符串和SMTP服务器地址在我的ASP.NET应用程序取决于它在开发或生产环境中运行。

I need to use different database connection string and SMTP server address in my ASP.NET application depending on it is run in development or production environment.

应用程序通过<一个读取Web.config文件中的设置href=\"http://msdn.microsoft.com/en-us/library/system.web.configuration.webconfigurationmanager.appsettings.aspx\">WebConfigurationManager.AppSettings属性。

我用建/发布命令部署通过FTP应用到生产服务器,然后使用正确的手动替换远程Web.config文件。

I use Build/Publish command to deploy the application to production server via FTP and then manually replace remote Web.config with correct one.

是否有可能以某种方式简化部署的过程?谢谢!

Is it possible somehow simplify the process of deployment? Thanks!

推荐答案

在Visual Studio 2010和上面,你现在有这取决于构建配置转换应用到你的web.config的能力。

In Visual Studio 2010 and above, you now have the ability to apply a transformation to your web.config depending on the build configuration.

在创建一个web.config,可以扩大在Solution Explorer中的文件,你会看到两个文件:

When creating a web.config, you can expand the file in the solution explorer, and you will see two files:


  • Web.Debug.Config

  • Web.Release.Config

它们包含变换code可用于

They contains transformation code that can be used to


  • 更改连接字符串

  • 删除调试跟踪和设置

  • 注册错误页面

请参阅的Web.config转换语法Web应用程序项目部署的MSDN上了解更多信息。

See Web.config Transformation Syntax for Web Application Project Deployment on MSDN for more information.

也可以,尽管官方支持,以同一种改造应用到非Web应用程序的app.config 文件。见关于如何修改菲尔Bolduc博客项目文件到一个新的任务添加到MSBuild的。

It is also possible, albeit officially unsupported, to apply the same kind of transformation to an non web application app.config file. See Phil Bolduc blog concerning how to modify your project file to add a new task to msbuild.

这是一个长期承受<一个href=\"https://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2043217-support-web-config-style-transforms-on-any-file-in\"相对=nofollow>在Visual Studio UserVoice的的要求。

This is a long withstanding request on the Visual Studio Uservoice.

一个为Visual Studio 2010 及以上的新的扩展, SlowCheetah ,可采取创造变换的护理任何配置文件。

A new extension for Visual Studio 2010 and above, "SlowCheetah," is available to take care of creating transform for any config file.

这篇关于在开发和生产环境使用不同的Web.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆