Nuget 包“contentFiles”没有被复制到项目中

Nuget package `contentFiles` are not getting copied into the project

我有一个由 msbuild.exe -t:"Pack" 命令生成的 Nuget 包。 NUSPEC 文件如下所示。

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>
    <id>LibraryId</id>
    <version>1.0.0</version>
    <authors>Developer</authors>
    <owners>Company</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Package Description</description>
    <repository type="git" url="https://github.com/cilerler/fake.git" />
    <dependencies>
      <group targetFramework=".NETFramework4.8">
        <dependency id="Microsoft.ClearScript" version="6.0.2" exclude="Build,Analyzers" />
        <dependency id="Microsoft.Extensions.Logging.Abstractions" version="3.1.5" exclude="Build,Analyzers" />
        <dependency id="Microsoft.Extensions.Primitives" version="3.1.5" exclude="Build,Analyzers" />
        <dependency id="Microsoft.NETCore.Platforms" version="3.1.1" exclude="Build,Analyzers" />
        <dependency id="NETStandard.Library" version="2.0.3" exclude="Build,Analyzers" />
        <dependency id="Newtonsoft.Json" version="12.0.3" exclude="Build,Analyzers" />
        <dependency id="System.Buffers" version="4.5.1" exclude="Build,Analyzers" />
        <dependency id="System.ComponentModel" version="4.3.0" exclude="Build,Analyzers" />
        <dependency id="System.Memory" version="4.5.4" exclude="Build,Analyzers" />
        <dependency id="System.Numerics.Vectors" version="4.5.0" exclude="Build,Analyzers" />
      </group>
    </dependencies>
    <frameworkAssemblies>
      <frameworkAssembly assemblyName="Microsoft.CSharp" targetFramework=".NETFramework4.8" />
      <frameworkAssembly assemblyName="mscorlib" targetFramework=".NETFramework4.8" />
      <frameworkAssembly assemblyName="System.Core" targetFramework=".NETFramework4.8" />
      <frameworkAssembly assemblyName="System.Data.DataSetExtensions" targetFramework=".NETFramework4.8" />
      <frameworkAssembly assemblyName="System.Data" targetFramework=".NETFramework4.8" />
      <frameworkAssembly assemblyName="System" targetFramework=".NETFramework4.8" />
      <frameworkAssembly assemblyName="System.Net.Http" targetFramework=".NETFramework4.8" />
      <frameworkAssembly assemblyName="System.Numerics" targetFramework=".NETFramework4.8" />
      <frameworkAssembly assemblyName="System.Xml" targetFramework=".NETFramework4.8" />
      <frameworkAssembly assemblyName="System.Xml.Linq" targetFramework=".NETFramework4.8" />
    </frameworkAssemblies>
    <contentFiles>
      <files include="any/net48/MyFile.txt" buildAction="Content" />
    </contentFiles>
  </metadata>
</package>

当我将包添加到 plain.NetFramework4.8 控制台应用程序时,MyFile.txt 没有出现在树中,也没有被复制进入 bin/Debug 文件夹。

知道它可能是什么吗?提前致谢

内容文件仅在 NuGet 4.0+ 中受支持,并且仅在您的项目中使用 PackageReference 时才受支持。但是,它们未复制到输出文件夹的原因是这是默认选项。如果您希望它们被复制,您必须在 files 标签中使用 copyToOutput="true" 明确指定它,如下所示:

<files include="any/net48/MyFile.txt" buildAction="Content" copyToOutput="true"/>