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

查看:170
本文介绍了在开发和生产环境中使用不同的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.

应用程序通过 WebConfigurationManager.AppSettings 属性。

我使用Build / Publish命令部署应用程序生产服务器通过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时,您可以在解决方案资源管理器中展开该文件,您将看到两个文件:

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

它们包含可用于


  • 更改连接字符串

  • 删除调试跟踪和设置

  • 注册错误页面

href =http://msdn.microsoft.com/en-us/library/dd465326(VS.100).aspx =nofollow noreferrer> Web.config Web应用程序项目部署的转换语法 MSDN获取更多信息。

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

尽管官方不支持,也可以对非web应用程序应用相同的转换 app.config 文件。请参阅 Phil 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.

这是一个很长的在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天全站免登陆