简体   繁体   English

NuGet - NU5131:在 nuspec 文件中声明的引用没有被打包

[英]NuGet - NU5131: References declared in the nuspec file are not being packaged

I'm trying to reference two .dll files in a nupkg.我正在尝试在 nupkg 中引用两个 .dll 文件。 I've added the files as references in the nuspec file:我已将文件添加为 nuspec 文件中的引用:

<references>
   <reference file="Project.Modules.ModuleA.dll" />
   <reference file="Project.Modules.ModuleB.dll" />
</references>

When i try to pack, i get the following warning and the package does not include the referenced files.当我尝试打包时,我收到以下警告,并且该包不包含引用的文件。

WARNING: NU5131: References were found in the nuspec, but some reference assemblies were not found in both the nuspec and ref folder.警告:NU5131:在 nuspec 中找到了引用,但在 nuspec 和 ref 文件夹中都找不到一些引用程序集。 Add the following reference assemblies: - Add Project.Modules.ModuleA.dll to the ref/any/ directory - Add Project.Modules.ModuleB.dll to the ref/any/ directory添加以下参考程序集: - 将 Project.Modules.ModuleA.dll 添加到 ref/any/ 目录 - 将 Project.Modules.ModuleB.dll 添加到 ref/any/ 目录

Where do i place the files in order to get the package to include the required files?我应该把文件放在哪里才能让包包含所需的文件?

Since I was using .net core 3.1, turns out all I had to do was to make some tweaks in the project.csproj file of the nupkg.由于我使用的是 .net core 3.1,结果我所要做的就是在 nupkg 的 project.csproj 文件中进行一些调整。 Here's what I did:这是我所做的:

Add an item group:添加项目组:

<ItemGroup>
    <ProjectReference Include="..\..\Project.Modules.ModuleA.csproj" >
      <PrivateAssets>all</PrivateAssets>
      <ReferenceOutputAssembly>true</ReferenceOutputAssembly>
      <IncludeAssets>Project.Modules.ModuleA.dll</IncludeAssets>
    </ProjectReference>
    <ProjectReference Include="..\Project.Modules.ModuleB.csproj" >
      <PrivateAssets>all</PrivateAssets>
      <ReferenceOutputAssembly>true</ReferenceOutputAssembly>
      <IncludeAssets>Project.Modules.ModuleB.dll</IncludeAssets>
    </ProjectReference>
  </ItemGroup>

Then add a target:然后添加一个目标:

<Target DependsOnTargets="ResolveReferences" Name="CopyProjectReferencesToPackage">
    <ItemGroup>
      <BuildOutputInPackage Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))"/>
    </ItemGroup>
  </Target>

And finally add this inside the PropertyGroup element:最后将其添加到 PropertyGroup 元素中:

<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>

Works like a charm for me对我来说就像一种魅力

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM