如何让 .NET Core 项目将 NuGet 引用复制到构建输出?

时间:2023-02-03
本文介绍了如何让 .NET Core 项目将 NuGet 引用复制到构建输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试使用 .NET Core 编写插件系统,我的要求之一是能够将插件 DLL 及其依赖项分发给用户进行安装.

I'm trying to write a plugin system with .NET Core, and one of my requirements are to be able to distribute the plugin DLL along with its dependencies to the user for install.

但是,我不知道如何将我的 NuGet 依赖项包含为构建工件并将它们输出到构建文件夹,而不必使用 dotnet publish 作为 hack.有什么方法可以在 .csproj 文件(项目文件)中指定吗?

However, I can't figure out how to include my NuGet dependencies as a build artifact and have them output to the build folder, without having to use dotnet publish as a hack. Is there some way I can specify this in the .csproj file (project file)?

推荐答案

您可以将其添加到您的 csproj 文件中的 <PropertyGroup> 以强制将 NuGet 程序集复制到构建输出:p>

You can add this to a <PropertyGroup> inside your csproj file to enforce copying NuGet assemblies to the build output:

<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

但是,请注意构建输出 (bin/Release/netcoreapp*/*) 不应该是可移植和可分发的,dotnet publish 的输出是.但是在您的情况下,将程序集复制到构建输出对于测试目的可能非常有用.但请注意,您也可以使用 DependencyContext api 来解析作为应用程序依赖关系图一部分的 DLL 及其位置,而不是枚举本地目录.

However, note that the build output (bin/Release/netcoreapp*/*) is not supposed to be portable and distributable, the output of dotnet publish is. But in your case, copying the assemblies to the build output is probably very useful for testing purposes. But note that you could also use the DependencyContext api to resolve the DLLs and their locations that are part of the application's dependency graph instead of enumerating a local directory.

这篇关于如何让 .NET Core 项目将 NuGet 引用复制到构建输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:C# 等价于 C++ 映射&lt;string,double&gt; 下一篇:代理背后的 NuGet

相关文章

最新文章