ASP.NET Web.Debug和Web.Release文件转换 [英] ASP.NET Web.Debug and Web.Release file transformations

查看:127
本文介绍了ASP.NET Web.Debug和Web.Release文件转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我知道关于此问题的页面有很多,例如 Web.Config调试/发布

First of all I know there are several pages about this issue e.g. Web.Config Debug/Release, Web.config Transformation Syntax now generalized for any XML configuration file and Web.config File Transformations. But most of them are outdated and does not mentioned clearly about all of the three files: Web.config, Web.Debug.config, Web.Release.config.

因此,假设我对Web.config进行了以下设置:

So, assume that I have the following settings for Web.config:

Web.config:

Web.config:

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

我想通过以下方式在调试和发布中使用这些设置:

And I want to use these settings in debug and release in the following ways:

Web.Debug.config:

Web.Debug.config:

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

Web.Release.config:

Web.Release.config:

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

1)有什么程序可以准确地执行此操作?我认为在调试发布时,这些设置会根据我在Visual Studio运行和发布对话框中选择调试或发布而自动使用.是真的吗?

1) What is the procedures to perform this accurately? I think while debugging and publishing, these settings are used automatically according to my selection Debug or Release in Visual Studio run and publish dialog. Is that true?

2)在移至Web.Debug.config和Web.Release.config之后是否应该从Web.config中删除这些设置?

2) Should I remove these settings from Web.config after moving to Web.Debug.config and Web.Release.config?

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

3) What is the Test selection in the Configuration field of the Publish dialog in VS?

任何帮助将不胜感激.

推荐答案

我建议阅读有关web.config转换工作原理的概述:

I would recommend reading an overview of how web.config transforms work:

https://blog.elmah.io/Web配置转换最终语法指​​南/

通常,Web.*.config文件将根据Visual Studio中选定的发布配置对Web.config文件进行更改.例如,如果要更新/替换调试发布中的值,则Web.Debug.config文件应如下所示:

In general, the Web.*.config files will make changes to the Web.config file depending on the selected publish configuration in Visual Studio. For example, if you want to update/replace a value in a debug publish, your Web.Debug.config file should look like:

<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>

以下是有关这些工作方式的最新Microsoft文档: https://docs.microsoft.com/zh-CN/aspnet/core/host-and-deploy/iis/transform-webconfig?view=aspnetcore-3.1

Here is the current Microsoft documentation on how these work: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/transform-webconfig?view=aspnetcore-3.1

这篇关于ASP.NET Web.Debug和Web.Release文件转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆