我还在NuGet 的文档 GitHub上问了这个问题,我得到的答案是没有对此的本机支持,所以我实现了一个解决方法,并将其发布在这里供其他人使用:
<!-- Generate also reference assembly. -->
<!-- See: -->
<!-- https://docs.microsoft.com/en-us/dotnet/standard/assembly/reference-assemblies#generating-reference-assemblies -->
<!-- https://github.com/dotnet/roslyn/blob/master/docs/features/refout.md -->
<PropertyGroup>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
</PropertyGroup>
<!-- This is a workaround until better support for \ref (Reference Assembly) is added in Pack target. -->
<!-- See: -->
<!-- https://docs.microsoft.com/en-us/nuget/create-packages/select-assemblies-referenced-by-projects#packagereference-support -->
<!-- Need a away to specify \ref (Reference Assembly) as target folder in Pack target (https://github.com/NuGet/Home/issues/4184) -->
<PropertyGroup>
<!-- Supress warning NU5131 (https://docs.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu5131) which is reported because .nuspec file is not updated -->
<!-- to contain <references> element (https://docs.microsoft.com/en-us/nuget/reference/nuspec#explicit-assembly-references) for all files inside the 'ref\' directory. -->
<NoWarn>$(NoWarn),NU5131</NoWarn>
<!-- See https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#targetsfortfmspecificcontentinpackage -->
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);AddRefAssemblyToPackage</TargetsForTfmSpecificContentInPackage>
</PropertyGroup>
<Target Name="AddRefAssemblyToPackage">
<!-- Add reference assembly and XML documentation to 'ref/'. -->
<ItemGroup Condition=" Exists('$(BaseOutputPath)$(Configuration)\$(TargetFramework)\ref\$(AssemblyName).dll') ">
<TfmSpecificPackageFile Include="$(BaseOutputPath)$(Configuration)\$(TargetFramework)\ref\$(AssemblyName).dll" PackagePath="ref/$(TargetFramework)" />
<TfmSpecificPackageFile Include="$(BaseOutputPath)$(Configuration)\$(TargetFramework)\$(AssemblyName).xml" PackagePath="ref/$(TargetFramework)" />
</ItemGroup>
</Target>