Jam*_*oux 12 .net dll visual-studio nuget .net-standard
我有 Visual Studio 2019 社区版
重现步骤:
我加载 VS 并启动一个全新的 C# .Net 标准库项目。我去 Nuget Pkg Manager 并安装任何nuget 包。我向 Class1.cs 添加一行以使用包中的类型。
例如,如果我安装 WatsonTCP nuget 包,我会将 Class1.cs 更改为如下所示:
using System;
using WatsonTcp;
namespace NugetTest
{
public class Class1
{
public Class1()
{
WatsonTcpClient client = new WatsonTcpClient("", 0);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我点击了重建解决方案。我检查了 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".
Run Code Online (Sandbox Code Playgroud)
我猜这个关于 CopyLocal 的通知是构建文件夹中没有输出任何内容的原因。但我不是 100% 确定。
SO 主要包含与 .Net Core 和 .Net Standard 之前的“包参考”时代相关的旧问题。因此,每当我搜索与“CopyLocal”有关的问题时,我都会获得有关在 DLL 引用上显式设置 CopyLocal 属性的信息。通过包参考和 RAR 系统自动确定 CopyLocal,我没有发现任何有助于解决我的问题。
任何人都可以帮忙吗?
Lan*_*SFT 36
打开您的xx.csproj(在 VS 中,双击解决方案资源管理器中的项目名称,或右键单击 project=>unload=>edit...)并将CopyLocalLockFileAssemblies属性添加到其中,将其值设置为true,它将从nuget 包在构建过程中输出到文件夹。
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<!--Add this line-->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
如果您的项目中有太多 nuget 包,而您只想要其中的一部分,请尝试使用PrivateAssets="All"防止 VS 将指定的包复制到输出文件夹。
<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>
Run Code Online (Sandbox Code Playgroud)
例如:使用上面的脚本将复制log4net,NewTonSoft.Json但不会复制WatsonTcp到输出文件夹。更多细节请参考github/dotnet/sdk#2235。
| 归档时间: |
|
| 查看次数: |
8664 次 |
| 最近记录: |