简体   繁体   English

如何在VS2010中的新web.config配置中使用applicationSettings?

[英]How to use applicationSettings in the new web.config configuration in VS2010?

I'm used to use web deployment projects. 我习惯使用Web部署项目。 Currently I am developing a new web application with VS2010 and want to try to get along with the new web.config principle and deployment issues. 目前我正在使用VS2010开发一个新的Web应用程序,并希望尝试与新的web.config原则和部署问题相处。

How can I replace a simple setting like 我怎样才能替换像这样的简单设置

<applicationSettings>
  <NAMESPACE>
   <setting name="Testenvironment" serializeAs="String">
    <value>True</value>
   </setting>
  </NAMESPACE>
</applicationSettings>

I want to have this setting to be set to True in Debug, and false in Release. 我希望在Debug中将此设置设置为True,在Release中设置为false。 How must the entries in the Web.Debug.config and Web.Release.Config look like? Web.Debug.config和Web.Release.Config中的条目必须如何?

And by the way : Is there some documentation about the new web.config issue? 顺便说一句 :是否有关于新web.config问题的文档? Can't seem to google for the correct keywords. 似乎无法谷歌正确的关键字。

The best way would be to do the following: 最好的方法是执行以下操作:

<applicationSettings> 
  <NAMESPACE> 
   <setting name="Testenvironment" serializeAs="String"  xdt:Transform="Replace" xdt:Locator="Match(name)"> 
    <value>True</value> 
   </setting> 
  </NAMESPACE> 
</applicationSettings> 

Rather than Zubeyir suggestion as this one will only replace the specifed setting rather than replacing the WHOLE of the applicationSettings section. 而不是Zubeyir建议,因为这个只会替换指定的设置而不是替换applicationSettings部分的WHOLE。

You could also use this way; 你也可以用这种方式; for the prod environment for example. 例如,对于prod环境。

<applicationSettings xdt:Transform="Replace">
  <NAMESPACE> 
   <setting name="Testenvironment" serializeAs="String"> 
    <value>False</value> 
   </setting> 
  </NAMESPACE> 
</applicationSettings> 

Regards. 问候。

You should copy this setting to both web config files - Web.Debug.config and Web.Release.config and put the transformation attributes xdt:Transform="SetAttributes" xdt:Locator="Match(name)" . 您应该将此设置复制到Web配置文件 - Web.Debug.config和Web.Release.config并将转换属性xdt:Transform="SetAttributes" xdt:Locator="Match(name)"

You can see this video tutorial - http://chriskoenig.net/index.php/2010/04/08/how-do-i-web-config-transformations-in-vs2010/ 你可以看到这个视频教程 - http://chriskoenig.net/index.php/2010/04/08/how-do-i-web-config-transformations-in-vs2010/

Hope that helps. 希望有所帮助。

Here is a link with lots of samples on this theme: http://msdn.microsoft.com/en-us/library/dd465326.aspx . 以下是此主题的大量示例链接: http//msdn.microsoft.com/en-us/library/dd465326.aspx

But there seems to be a problem especially with Web.config transformations and applicationSettings: All answers on this query using xdt-Transform=“Replace” have the problem that they introduce additional white space into the deployed Web.config because of XML formatting. 但是,似乎存在一个问题,尤其是Web.config转换和applicationSettings:使用xdt-Transform=“Replace”此查询的所有答案都存在这样的问题:由于XML格式化,它们会在部署的Web.config中引入额外的空白区域。 This leads to faulty behavior if you consume the resulting settings. 如果您使用结果设置,则会导致错误行为。 There seems to be no solution. 似乎没有解决方案。 Here is my unanswered question on this problem: VS 2010 configuration transformation produces unwanted white space during deployment . 以下是关于此问题的未回答的问题: VS 2010配置转换在部署期间会产生不需要的空白区域

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM