如何获得.NET Core项目以将NuGet引用复制到生成输出? [英] How do I get .NET Core projects to copy NuGet references to the build output?

查看:368
本文介绍了如何获得.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程序集复制到生成的输出中:

You can add this to a <PropertyGroup> inside your csproj file to enforce copying NuGet assemblies to the built 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引用复制到生成输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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