用户登录
用户注册

分享至

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

  • 作者: 急躁的年轻人
  • 来源: 51数据库
  • 2023-02-13

问题描述

我正在尝试使用 .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.

软件
前端设计
程序设计
Java相关