在开发和生产环境使用不同的Web.config

编程入门 行业动态 更新时间:2024-10-10 14:28:42
本文介绍了在开发和生产环境使用不同的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属性。

我用建/发布命令部署通过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.

这是一个长期承受在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

本文发布于:2023-11-01 01:16:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547822.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:环境   Web   config

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!