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. My Service
library have it's own dependencies and one of those dependencies ( DAL
) makes use of NuGet, specifically MongoDB.Driver. When I compile it, in bin/debug
Service don't have any mongo related libraries. 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.
But it don't work with Windows Service (Net 4.6.1) that referencing Standard
. 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
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). 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. It is explained on 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.
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
I'm not sure which approach is better, waiting for comments.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.