安装在 netstandard 2.0 项目中的 nuget 包是否不支持 xdt 转换?

Are xdt transforms not supported in nuget packages installed in a netstandard 2.0 project?

我有一个 nuget 包,其中包含 app.config 文件的 .xdt 转换。 xdt 文件包含在构建 nuget 包的 netstandard 2.0 项目中。他们的构建操作设置为 content/do 而不是复制。当我在 .net 框架项目中安装包时,xdt 转换工作正常,但是当我在 netstandard 2.0 项目中安装包时,xdt 文件不转换配置文件,而是通过构建添加到项目中C# 编译器的动作。 nuget 不支持 netstandard 项目上的 xdt 转换吗?

你说得对,PackageReference 环境不支持 xdt 转换。这包括基于 sdk 的项目以及使用 PackageReference 而不是 packages.config 的经典 .net 框架项目。您可以关注 this GitHub issue for more details. There is also a sample package,其中展示了如何使用构建时逻辑来应用转换,而不是在所有环境中工作。

另请注意,.NET Standard 和 .NET Core 项目没有可应用转换的 app.config 文件。这仅与 .NET Framework / 经典 Web 应用程序相关。 (ASP.NET 核心应用的 IIS 设置可能是个例外,但它们不会影响应用本身,只会影响 IIS 托管环境)。