简体   繁体   English

asp.net mvc web.config 和 web.debug.config 区别

[英]Asp.net mvc web.config and web.debug.config difference

There are Web.config and Web.debug.config and Web.release.config files in my visual studio solution window.我的 Visual Studio 解决方案窗口中有Web.configWeb.debug.configWeb.release.config文件。

I want to set different email configurations for release and debug.我想为发布和调试设置不同的电子邮件配置。

So I set Web.debug.config file所以我设置了 Web.debug.config 文件

  <system.net>
    <mailSettings>
      <smtp deliveryMethod="SpecifiedPickupDirectory">
        <network host="localhost" port="587" defaultCredentials="true"/>
        <specifiedPickupDirectory pickupDirectoryLocation="C:\Temp\Mail\Debug"/>
      </smtp>
    </mailSettings>
  </system.net>

And I set my Web.release.config我设置了我的 Web.release.config

  <system.net>
    <mailSettings>
      <smtp deliveryMethod="SpecifiedPickupDirectory">
        <network host="localhost" port="587" defaultCredentials="true"/>
        <specifiedPickupDirectory pickupDirectoryLocation="C:\Temp\Mail\Release"/>
      </smtp>
    </mailSettings>
  </system.net>

When I run the applciaitons, my settings does not load to SmtpClient object.当我运行应用程序时,我的设置不会加载到SmtpClient对象。

Why does not take settings from Web.debug.config为什么不从 Web.debug.config 中获取设置

在此处输入图片说明

This only works for when you publish a project, not in the IDE.这仅适用于发布项目时,而不适用于 IDE。 Read more here:在此处阅读更多信息:

https://msdn.microsoft.com/en-us/library/dd465318(v=vs.100).aspx https://msdn.microsoft.com/en-us/library/dd465318(v=vs.100).aspx

As mentioned before it is not a webconfig rather than transformations.如前所述,它不是 webconfig 而不是转换。 And a transformation is tranformed into the web.config when building/publishing in for example release mode.在例如发布模式下构建/发布时,转换会转换为 web.config。

You must set some meta information in the web.release.config how the tranformation should be treated, for example:您必须在 web.release.config 中设置一些元信息应该如何处理转换,例如:

<system.net>
    <mailSettings>
      <smtp deliveryMethod="SpecifiedPickupDirectory">
        <network host="localhost" port="587" defaultCredentials="true"/>
        <specifiedPickupDirectory pickupDirectoryLocation="C:\Temp\Mail\Release"/ xdt:Transform="Replace">
      </smtp>
    </mailSettings>
</system.net>

This will instruct the transformation to replace the specifiedPickupDirectory tag in the web.config with the one in web.release.config.这将指示转换将 web.config 中指定的PickupDirectory 标记替换为 web.release.config 中的标记。

If you want to make tranformations on build and not only when you publish, you have to add a TransformXml to a BeforeBuild section in your csproj.如果您想在构建时进行转换而不仅仅是在发布时进行转换,您必须将 TransformXml 添加到您的 csproj 中的 BeforeBuild 部分。

Like Merryweather said, this is a transform to apply on top of the base config.就像 Merryweather 所说的,这是一个应用在基本配置之上的转换。 SlowCheetah offers extensions that let you right click to preview the config transform. SlowCheetah 提供了一些扩展,让您可以右键单击以预览配置转换。 You can access those through the visual studio gallery:您可以通过 Visual Studio 库访问这些:

https://visualstudiogallery.msdn.microsoft.com/05bb50e3-c971-4613-9379-acae2cfe6f9e https://visualstudiogallery.msdn.microsoft.com/05bb50e3-c971-4613-9379-acae2cfe6f9e

https://devblogs.microsoft.com/aspnet/asp-net-web-projects-web-debug-config-web-release-config/ https://devblogs.microsoft.com/aspnet/asp-net-web-projects-web-debug-config-web-release-config/

Debug is for development environment Debug 是针对开发环境的

Release for production environment生产环境发布

Web.config is for local machine Web.config 用于本地机器

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

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