简体   繁体   English

具有自己的NuGet依赖项时如何从Full .Net引用标准库

[英]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 AppWindows 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.jsonruntimeconfig.jsonruntimeconfig.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.

相关问题 .NET Standard 库输出不包括 nuget 依赖项 - .NET Standard library output doesn't include nuget dependencies 发布 .net 标准库及其所有依赖项? - Publish .net standard library with all it's dependencies? 如何在VS 2017中创建具有最小依赖性的.NET Standard NuGet包? - How to create .NET Standard NuGet package with minimal dependencies in VS 2017? 如何从 Xamarin iOS 绑定项目引用 .NET 标准库? - How to reference a .NET standard library from a Xamarin iOS binding project? 从.net库引用.NET Standard 1.6库 - Reference a .NET Standard 1.6 library from a .net library 在 Xamarin Forms(.NET Standard 2)中的依赖项中添加缺少的引用选项 - Add Reference option missing from Dependencies in Xamarin Forms (.NET Standard 2) 在.NET Standard 1.4上参考CommonServiceLocator Nuget - Reference CommonServiceLocator Nuget on .NET Standard 1.4 NET标准类库的参考UWP库 - Reference UWP library from .net standard class library 如何从Visual Studio 2017中的.NET Framework 4.5控制台应用程序引用.NET标准库? - How Do You Reference a .NET Standard Library from a .NET Framework 4.5 Console Application in Visual Studio 2017? 通过 nuget 与手动参考在 .NET 标准中使用 .NET 框架程序集时的不同错误 - Different errors when using .NET framework assembly in .NET standard via nuget vs manual reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM