Nuget包中的DLL。因为dll不是本地复制的?如何解决?

问题描述 投票:0回答:1

我有Visual Studio 2019社区版

复制步骤:

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

例如,如果我安装了WatsonTCP nuget包,则将Class1.cs更改为如下形式:

using System;
using WatsonTcp;

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

我点击了Rebuild Solution。我检查bin / Debug文件夹,并且没有nuget软件包的dll在那里。用于发布版本的bin / Release也是如此。

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

我将“构建并运行MSBuild”设置设置为“详细”。在构建日志中,我看到类似以下输出的内容[[对于每个单个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%。

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

有人可以帮忙吗?

.net visual-studio dll nuget .net-standard
1个回答
0
投票
打开xx.csproj

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

<PropertyGroup> <TargetFramework>netstandard2.0</TargetFramework> <!--Add this line--> <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> </PropertyGroup>
并且如果您的项目中有太多的nuget包,而您只想要其中的一部分,请尝试使用PrivateAssets="All"以防止VS将指定的nuget包复制到输出文件夹。 

<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
© www.soinside.com 2019 - 2024. All rights reserved.