[英]How to reference Standard library from Full .Net when it have it's own NuGet dependencies
I have some back-end logic in .NET Standard library (let's call it Service
) and have to have two types of entry point: .Net Core Console App and a Windows Service as entry points to that logic. 我在.NET Standard库中有一些后端逻辑(我们称其为Service
),并且必须具有两种类型的入口点: .Net Core Console App和Windows Service作为该逻辑的入口点。 My Service
library have it's own dependencies and one of those dependencies ( DAL
) makes use of NuGet, specifically MongoDB.Driver. 我的Service
库具有它自己的依赖关系,并且其中一个依赖关系( DAL
)使用了NuGet,尤其是MongoDB.Driver。 When I compile it, in bin/debug
Service don't have any mongo related libraries. 当我编译它时, bin/debug
Service中没有任何与mongo相关的库。 But Net Core Console App
do have deps.json
, runtimeconfig.json
, runtimeconfig.dev.json
files and as far as I understand this is why everything runs perfectly with Core Console. 但是Net Core Console App
确实具有deps.json
, runtimeconfig.json
, runtimeconfig.dev.json
文件,据我所知,这就是为什么一切都可以在Core Console上完美运行的原因。
But it don't work with Windows Service (Net 4.6.1) that referencing Standard
. 但是,它不适用于引用Standard
Windows Service(Net 4.6.1)。 There is also no Mongo in bin/Debug
and as a result when I run it (it is configured as a console application too) I get bin/Debug
也没有Mongo,因此,当我运行它时(它也被配置为控制台应用程序),我得到了
FileNotFoundException: Could not load file or assembly 'MongoDB.Driver, Version=2.5.0.0
and this is reasonable message... but how this supposed to work then? 这是合理的信息...但是这应该如何工作? Usually NuGet dependencies in Full .Net are copied with the target project (and also copied to those who references this project). 通常,Full .Net中的NuGet依赖项会与目标项目一起复制(并且还会复制到引用该项目的人员)。 This is not the case with Standard Libraries. 标准库不是这种情况。 I just afraid to reinvent the wheel here, may be there are good existing solution? 我只是害怕在这里重新发明轮子,也许有好的现有解决方案?
I had a similar issue; 我有一个类似的问题; add the following to the .csproj of your full .NET project. 将以下内容添加到整个.NET项目的.csproj中。 It is explained on GitHub 在GitHub上有解释
<PropertyGroup>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
Looks like this works too but should be done in csproj of .Net Standard. 看起来也可以,但是应该在.Net Standard的csproj中完成。
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
I'm not sure which approach is better, waiting for comments. 我不确定哪种方法更好,请等待评论。
It also looks like the Full.Net project just falls back to Packages.config because this is set by default in VS Setting. 看起来Full.Net项目只是退回到Packages.config,因为它是在VS Setting中默认设置的。 I've switched this to PackageReference and removead all changes in proj files - it now works just as is. 我已将其切换为PackageReference并删除了proj文件中的所有更改-现在它可以按原样工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.