.Net标准DLL项目中的“生成”文件夹中缺少Nuget Pkg Dlls。 dll不是本地复制?在Visual Studio 2019中修复? [英] Nuget Pkg Dlls Missing from Build Folder in .Net Standard DLL Project. dlls are Not Copy Local? Fix in Visual Studio 2019?

查看:330
本文介绍了.Net标准DLL项目中的“生成”文件夹中缺少Nuget Pkg Dlls。 dll不是本地复制?在Visual Studio 2019中修复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Visual Studio 2019社区版

I have Visual Studio 2019 Community Edition

重现步骤:

我加载VS并开始一个全新的C#.Net标准库项目。
我转到Nuget Pkg Manager并安装 ANY nuget软件包。
我在Class1.cs中添加了一行以使用包中的Type。

I load up VS and start a brand new C# .Net Standard Library project. I go to Nuget Pkg Manager and install ANY nuget package. I add a single line to Class1.cs to use a Type from the package.

例如,如果我安装了WatsonTCP nuget包,则更改了Class1。 cs看起来像这样:

For instance, if I install WatsonTCP nuget package, I change Class1.cs to look like this:

using System;
using WatsonTcp;

namespace NugetTest
{
    public class Class1
    {
        public Class1()
        {
            WatsonTcpClient client = new WatsonTcpClient("", 0);
        }
    }
}

我点击了重建解决方案。我检查bin / Debug文件夹,并且没有nuget软件包的dll在那里。对于发布版本,bin / Release也是如此。

I hit Rebuild Solution. I check the bin/Debug folder and none of the dlls for the nuget package are there. Same thing with bin/Release for a Release build.

我已经尽我所能解决了许多SO问题。我已经阅读了有关nuget的MSDN文档。

I have poored through as many SO issues as I can. I've read the MSDN documentation on nuget.

我将构建和运行MSBuild设置设置为详细。在生成日志中,对于每个单个dll,我都会看到以下输出

I set Build and Run MSBuild settings to Detailed. In the build log, I see something like the following output for every single dll:

Primary reference "WatsonTcp, Version=2.0.7.0, Culture=neutral, PublicKeyToken=null".
Resolved file path is "C:\Users\James\.nuget\packages\watsontcp\2.0.7\lib\netstandard2.0\WatsonTcp.dll".
Reference found at search path location "{HintPathFromItem}".
This reference is not "CopyLocal" because at least one source item had "Private" set to "false" and no source items had "Private" set to "true".

我猜这是关于CopyLocal的通知,这是在构建文件夹中未输出任何内容的原因。但是我不确定100%。

I'm guessing this notice about CopyLocal is the reason nothing is being output in the build folder. But I'm not 100% sure.

SO大多包含较旧的问题,这些问题与.Net Core和.Net Standard之前的程序包参考时代有关。结果,每当我搜索与 CopyLocal有关的问题时,都会获得有关在DLL参考上显式设置CopyLocal属性的信息。我发现没有任何有用的信息通过Package Reference和RAR系统自动确定CopyLocal来解决我的问题。

SO mostly contains older questions that pertain to the pre-"package reference" era before .Net Core and .Net Standard. As a result, any time I search for issues pertaining to "CopyLocal", I get information on setting the CopyLocal property explicitly on a DLL Reference. I'm not finding anything helpful to fix my issue with automatic determination of CopyLocal by the Package Reference and RAR system.

有人可以帮助吗?

推荐答案

打开您的 xx.csproj 在VS中,双击解决方案资源管理器,或右键单击project => unload => edit ... ),然后向其中添加 CopyLocalLockFileAssemblies 属性,将其值设置为 true ,它将在构建过程中将所有程序集从nuget包复制到输出文件夹。

Open your xx.csproj(In VS, double-click the project name in Solution explorer, or right-click project=>unload=>edit...) and add the CopyLocalLockFileAssemblies property into it, set its value to true and it will copy all your assemblies from nuget packages to output folder during build process.

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <!--Add this line-->
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  </PropertyGroup>

如果您的项目中有太多的nuget包,而您只想要其中的一部分,请尝试使用 PrivateAssets = All 可以防止VS将指定的一个复制到输出文件夹。

And if you have too many nuget packages in your project and you only want part of them, try using PrivateAssets="All" to prevent VS from copying the specified one to output folder.

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <!--Add this line to copy everything.-->
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="log4net" Version="2.0.8" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3-beta1" />
    <PackageReference Include="WatsonTcp" Version="2.0.7" PrivateAssets="All"/>
  </ItemGroup>

例如:使用上面的脚本将复制 log4net NewTonSoft.Json 而不是 WatsonTcp 来输出文件夹。更多详细信息,请参见 github / dotnet / sdk#2235

Eg: Using script above will copy log4net and NewTonSoft.Json but not WatsonTcp to output folder. More details refer to github/dotnet/sdk#2235.

这篇关于.Net标准DLL项目中的“生成”文件夹中缺少Nuget Pkg Dlls。 dll不是本地复制?在Visual Studio 2019中修复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆