环境变量中的"include"和"names"属性有何区别?

5

以下是“什么是...”和“如何使用...”之间的区别:

<environment include="...">...

并且

<environment names="...">...

官方文档对我来说并没有帮助区分它们:
ASP.NET Core 中的环境标签助手

names

... If any of the provided environment names match the current environment, the enclosed content is rendered ... Environment values are compared to the current value returned by IWebHostEnvironment.EnvironmentName

The content is rendered if the hosting environment is Staging or Production

<environment names="Staging,Production">
    <strong>IWebHostEnvironment.EnvironmentName is Staging or Production</strong>
</environment>

include

The include property exhibits similar behavior to the names attribute. An environment listed in the include attribute value must match the app's hosting environment (IWebHostEnvironment.EnvironmentName) to render the content of the tag.

<environment include="Staging,Production">
    <strong>IWebHostEnvironment.EnvironmentName is Staging or Production</strong>
</environment>

甚至他们的代码片段都使用完全相同的自我描述:“IWebHostEnvironment.EnvironmentName is Staging or Production”。

它们之间有什么区别?

1个回答

2
“names”似乎是较早的方式,“include/exclude”是较新的方式。
EnvironmentTagHelper中的新“exclude”属性可让您轻松地告诉EnvironmentTagHelper在除了指定的环境之外的所有环境中呈现。还有一个新的“include”属性,其行为与ASP.NET Core 1中的“names”相同。
我猜Microsoft保留了旧的“names”以实现向后兼容。不知道为什么文档没有反映这一点。
基于我的经验、官方文档和上述文章,name和include之间没有功能差异。只是include这个名称更好地配对了exclude。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接