多个ASP.NET配置文件 [英] Multiple ASP.NET Configuration Files
问题描述
我发现在有一个Web部署多个ASP.NET配置文件的若干条信息。不过,我仍然不确定,如果我能做到我想要完成的任务。
I have found a number of pieces of information on having multiple ASP.NET configuration files for a web deployment. However, I am still unsure if I can accomplish what I want to accomplish.
基本上,我工作的网站可以被部署到三个不同的地点。根据其部署到网站上,需要更改的配置设置。我想这样做的是为每个可能的配置配置文件(全web.config文件中),然后可以告诉部署构建用于特定部署该配置文件(我可以编辑该手动如有必要)。
Basically, the website I am working on can be deployed to three different sites. Depending on the site that it is deployed to, the configuration settings need to be changed. What I would like to do is have configuration files for each possible configuration (full web.config files) and then be able to tell a deployment build which config file to use for a particular deployment (I can edit this manually if necessary).
有没有为指向一个不同的config文件一样简单的东西,或者我需要做一些更复杂?
Is there something as simple as pointing to a different .config file, or do I need to do something more sophisticated?
编辑:,我有一个特别值得关注的是,我还需要在system.net邮件设置等设置,因此,我不希望的只有的覆盖的appSettings。
One particular concern that I have is that I also need settings in system.net for mail settings, etc. So, I'm not looking to only override the appSettings.
感谢
推荐答案
任何配置部分 - 例如< SMTP>
- 可以被外部化,例如存储在外部文件中。
Any configuration section - such as <smtp>
- can be "externalized", e.g. stored in an external file.
除了文件=
语句&LT;的appSettings&GT;
(这是唯一的应用程序设置可供选择: - ()它不是一个额外的设置 - 你只是你的配置系统指向外部文件
Other than the file=
statement on <appSettings>
(which is available only for app settings :-() it's not a "additional" setting - you just point your config system to an external file.
所以,你可以在你的app.config / web.config中有这样的:
So you could have this in your app.config/web.config:
<system.net>
<mailSettings>
<smtp configSource="smtp.test.config" />
</mailSettings>
</system.net>
这在 smtp.test.config
:
<?xml version="1.0" encoding="utf-8" ?>
<smtp>
<network host="smtp.test.com" port="244" userName="test" password="secret" />
<specifiedPickupDirectory pickupDirectoryLocation="C:\temp\mails"/>
</smtp>
本工程为.NET 2.0(甚至1.x中),它适用于每个配置的栏目 - 但不是配置部分群体如&LT;的System.Web方式&gt;
This works as of .NET 2.0 (maybe even 1.x), and it works for every configuration section - but not for configuration section groups like <system.web>
.
当然,你现在可以创建额外的配置文件,如 smtp.staging.config
等等,现在你的问题已经降至替换一行你的web.config。
Of course, you can now create additional config files, like smtp.staging.config
and so forth, and now your problem has been reduced to replacing a single line in your web.config.
您可以使用安装脚本,一个XML preprocessor,甚至通过人为干预做到这一点。
You can do this using an installation script, a XML preprocessor, or even by human intervention.
它不会完全解决问题,因为<一href=\"http://blogs.msdn.com/webdevtools/archive/2009/05/04/web-deployment-web-config-transformation.aspx\"相对=nofollow>。NET 4和web.config文件转换的希望会的,但它是一个一步,一点帮助。
It doesn't completely solve the problem as .NET 4 and the web.config transformations hopefully will, but it's a step and a bit of help.
这篇关于多个ASP.NET配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!