.Net 标准 DLL 项目中的构建文件夹中缺少 Nuget Pkg Dll.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?

查看:19
本文介绍了.Net 标准 DLL 项目中的构建文件夹中缺少 Nuget Pkg Dll.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.

我将 Build and Run 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:UsersJames.nugetpackageswatsontcp2.0.7lib
etstandard2.0WatsonTcp.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 属性的信息.通过包参考和 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>

例如:使用上面的脚本会将 log4netNewTonSoft.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 Dll.dll不是本地复制?在 Visual Studio 2019 中修复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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