問題描述
我正在嘗試使用 .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 引用復制到構建輸出?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!