ASP.NET Web.Debug和Web.Release文件转换

问题描述 投票:0回答:1

首先,我知道有几个页面是关于这个问题的,例如 Web.Config DebugRelease, Web.config转换语法现在可通用于任何XML配置文件。Web.config文件转换. 但他们大多是过时的,没有明确提到所有的三个文件。Web.config, Web.Debug.config, Web.Release.config.

所以,假设我有以下设置,用于 Web.config:

Web.config。

<appSettings>
    <add key="ClientId" value="xxxxx"/>
    <add key="ClientSecret" value="xxxxx"/>
</appSettings>

我想在调试和发布中使用这些设置,方法如下:

Web.Debug.config:

<appSettings>
    <add key="ClientId" value="ddddd"/>
    <add key="ClientSecret" value="ddddd"/>
</appSettings>

Web.Release.config:

<appSettings>
    <add key="ClientId" value="rrrrr"/>
    <add key="ClientSecret" value="rrrrr"/>
</appSettings>

1) 准确地执行这个程序是什么?我想虽然 调试出版在Visual Studio运行和发布对话框中,根据我选择的Debug或Release,这些设置会自动使用。是这样吗?

2) 移到Web.Debug.config和Web.Release.config后,我是否应该删除Web.config中的这些设置?

3) VS中 "发布 "对话框的 "配置 "栏中的 "测试 "选择是什么?

如果有任何帮助,将不胜感激。

c# asp.net asp.net-mvc visual-studio web-config
1个回答
1
投票

我建议阅读关于Web.config转换工作原理的概述。

https:/blog.elmah.ioweb-config-transformations-the-definitive-syntax-guide。

一般来说,Web.*.config文件会根据Visual Studio中选定的发布配置对Web.config文件进行修改。 例如,如果你想在调试发布中更新替换一个值,你的Web.Debug.config文件应该是这样的。

<configuration xmlns:xdt="...">
  <appSettings>
    <add key"ClientId" value="ddddd" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
    <add key"ClientSecret" value="ddddd" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
  </appSettings>
</configuration>

这里是当前微软关于这些工作方式的文档。https:/docs.microsoft.comen-usaspnetcorehost-and-deployiistransform-webconfig?view=aspnetcore -3.

© www.soinside.com 2019 - 2024. All rights reserved.