简体   繁体   English

什么是Web.Debug.config和Web.Release.Config文件?

[英]What are the Web.Debug.config and Web.Release.Config files for?

I just upgraded to Visual Studio 2010 and MVC 2.0 and I noticed the Web.config has two additional files attached to it? 我刚刚升级到Visual Studio 2010和MVC 2.0,我注意到Web.config附加了两个附加文件? Are these files used to specify debug and release specific settings, so you don't clutter up the main Web.config? 这些文件是否用于指定调试和发布特定设置,因此您不会混淆主Web.config?

Does it even make sense to place a connection string in the root Web.config file if I have a local and remote one in the debug and release Web.configs respectively? 如果在调试和发布Web.configs中分别有本地和远程连接字符串,那么在根Web.config文件中放置连接字符串是否有意义?

Thanks! 谢谢!

It's the new Web.config transformation feature of Visual Studio 2010. More information here . 这是Visual Studio 2010的新Web.config转换功能。 更多信息,请点击此处


Edit: 编辑:

Are these files used to specify debug and release specific settings, so you don't clutter up the main web.config? 这些文件是否用于指定调试和发布特定设置,因此您不会使主web.config混乱?

It isn't limited to three files, you could (in theory) have as many files as you have environments. 它不限于三个文件,您(理论上)可以拥有与环境一样多的文件。 The "top level" Web.config provides a template of your web config. “顶级”Web.config提供了Web配置的模板。 The files under it provide replacement values specific to that environment (like if you have different connection strings for local/stage/test/whatever). 它下面的文件提供特定于该环境的替换值(例如,如果您有local / stage / test / whatever的不同连接字符串)。

Does it even make sense to place a connection string in the root web.config file if I have have a local and remote one in the debug and release web.configs respectively. 如果我在调试和发布web.configs中分别有本地和远程连接字符串,那么在根web.config文件中放置连接字符串是否有意义。

It would only make sense if it wasn't going to change between environments. 如果它不会在环境之间改变,那将是有意义的。 Sounds like in your case it does so, in your case no, it would not make sense to leave it in the Web.config. 听起来像你的情况一样,在你的情况下没有,将它留在Web.config中是没有意义的。

These are Web.config transformations files. 这些是Web.config转换文件。 From ASP.NET Web Deployment using Visual Studio: Web.config File Transformations : 使用Visual Studio的ASP.NET Web部署:Web.config文件转换

There are two ways to automate the process of changing Web.config file settings: Web.config transformations and Web Deploy parameters. 有两种方法可以自动更改Web.config文件设置的过程:Web.config转换和Web Deploy参数。 A Web.config transformation file contains XML markup that specifies how to change the Web.config file when it is deployed. Web.config转换文件包含XML标记,该标记指定在部署Web.config文件时如何更改它。 You can specify different changes for specific build configurations and for specific publish profiles. 您可以为特定的构建配置和特定的发布配置文件指定不同的更改。 The default build configurations are Debug and Release, and you can create custom build configurations. 默认构建配置是Debug和Release,您可以创建自定义构建配置。 A publish profile typically corresponds to a destination environment. 发布配置文件通常对应于目标环境。

In case anyone is interested, here is something I wrote up to have a dynamic connection string per environment. 如果有人感兴趣,我写的是每个环境都有一个动态连接字符串。 I wanted to deploy the code to any environment (Dev, Test, Pre-Prod, Prod...) without having to worry about changing connection strings. 我想将代码部署到任何环境(Dev,Test,Pre-Prod,Prod ...),而不必担心更改连接字符串。 I couldn't really find a good way to do this with Asp.Net MVC 4, so I came up with my own way to rely on a properties file per environment. 我无法找到一个很好的方法来使用Asp.Net MVC 4,所以我想出了一种依靠每个环境的属性文件的方法。

There may be a better solution, I come from a Wicket/Java background and recently started developing with MVC 4 so, it's possible a better solution exists. 可能有一个更好的解决方案,我来自Wicket / Java背景,最近开始使用MVC 4进行开发,因此可能存在更好的解决方案。 But here is a link to my question and answer for a dynamic connection string: 但这里有一个链接到我的动态连接字符串的问题和答案:

Asp.net MVC 4 dynamic connection string Asp.net MVC 4动态连接字符串

That was something long needed in VS. 这是VS中长期需要的东西。 Unfortunately there seems to be a problem with the implementation. 不幸的是,实施似乎存在问题。 For example consider this scenario (VS.2010 Ultimate, all SP): 例如,考虑这种情况(VS.2010 Ultimate,所有SP):

Web.Config Web.Config中

  • No connectionStrings section 没有connectionStrings部分
  • Full Membership User/Role/etc. 完全会员用户/角色/等。 Provider configuration using connectionStringName="test" 使用connectionStringName =“test”的提供程序配置

Web.Release.Config Web.Release.Config

  • No membership configuration (already specified in main web.config) 没有成员资格配置(已在主web.config中指定)
  • connectionStrings section including the CS named "test" connectionStrings部分包括名为“test”的CS

Web.Debug.Config Web.Debug.Config

  • No membership configuration (already specified in main web.config) 没有成员资格配置(已在主web.config中指定)
  • connectionStrings section including the CS named "test" connectionStrings部分包括名为“test”的CS

When executing the application gives the following error: 执行应用程序时出现以下错误:

The connection name 'test' was not found in the applications configuration or the connection string is empty. 在应用程序配置中找不到连接名称“test”,或者连接字符串为空。

In other words, because the connection string elements are in the Release/Debug designer files and used by configuration elements in the main (Web.config) file, it is unable to resolve it. 换句话说,因为连接字符串元素位于Release / Debug设计器文件中并由main(Web.config)文件中的配置元素使用 ,所以它无法解析它。

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

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