3
votes

I have a project for Business Logic and DAL, call this project A. This library has .NET Standard 2.0 as the target framework. I'm referencing a NuGet Package, RavenDB.Client 3.5.4 which is using the library/dll in the netstandard1.3 folder of the NuGet package.

I have an ASP.NET Web API app that has a target framework of .NET Framework 4.7.1, call this project B (not using .Net Core 2 because there are some references to legacy code that does not work with .Net Core).

I have a ASP.NET Core app as well, call this project C with a target framework of .NET Core 2.0.

Both project B and C reference project A.

Project C can reference project A and the RaveDB.Client NuGet Package without an issue, because it uses the library/dll in the netstandard1.3 folder as well. When making calls to the BL or DAL in package A from C there are no issues.

Project B can reference project A, but the referencing RavenDB.Client NuGet Package references the package/dll in the net45 folder. I get this error:

The type 'IDocumentStore' is defined in an assembly that is not referenced.You must add a reference to assembly 'Raven.Client.Lightweight, Version=3.5.4.0, Culture=neutral, PublicKeyToken=null

Which at first is misleading because clearly the issues is with Target Framework. I have a reference to Raven.Client.Raven.Client.Lightweight Version 3.5.4.0. But I'm passing an object (IDcoumentStore) built from net45 library to netstandard1.3 library.

My question, because .NET Framework 4.7.1 can use .NET Standard library, how do I force a project in VS2017 targeting .NET Framework 4.7.1 to use a .NET Standard library in a NuGet package? I tried changing targetFramework="net471" to targetFramework="netstandard1.3" that does not work seems as if VS or NuGet reverts back.

My only solution, which is a pain on many levels, is to strip out the net45 library from the Nuget package and roll my own with only the .Netstandard library.

1
Contact the Raven package developers and let them give you a solution. Changing NuGet behaviors is beyond your control, and is not what you should attempt to do.Lex Li
Good suggestion, but would they be the only ones having this type of an issue. What if I come across another library with the same issue, it would seem a better solution would be able to choose which Target Framework to use.Guy Boicey
BTW, do you use packages.config? Do you try to use package reference instead?Lex Li
Two issues with that reading some documentation Package references in project files 1. Document states only works with .NET Core projects, .NET Standard projects, and UWP projects and 2. If it did work, there is no parameter to designate Target Framework. Which is the same issue with working with packages.configGuy Boicey
did you solved this issue? I have the same problemIamisti

1 Answers

-1
votes

It looks like in Raven 4.0 Client the NuGet package contains only .netstandard library. That will solve the issue and basically does what I did by recreating the Raven 3.x Client and stripping out the net45 folder and repackaging. Now all I need to do is update to 4.0 which is not an easy task.

This answers the questions for RavenDB just hope I don't run into other packages that mix Full Framework and .Netstandard library and I want my app to target a particular framework and not have it picked for me.

UPDATE

I think there was confusion on the problem/solution. I will try again. If you look in the RavenDB.Client 3.5.5 Package you will see the following. Any package that has a similar structure will have a similar issue.

\lib \net45 \netstandard1.3

I have a class library targeting .NET Standard 2.0 that will use the .NET Standard 1.3 RavenDB library in the \lib\netstandard1.3 folder. I also have an App project that targets .NET Framework 4.7.1. That project has a reference to the class library and RavenDB client library. That project will use the .NET 4.5 library in the \net45 folder. The problem is that when the App runs RavenDB logic from the class library I receive errors because the RavenDB library in the bin folder target .NET 4.5 library not the .NET Standard 1.3 library which my class library is looking for.

When I make a reference to a NuGet package I can't designate the target framework. The target framework is inferred based on the project's target framework. Even though a project that targets .NET Framework 4.7.1 could use the .NET Standard Library or the .NET Framework library, but I can't choose the target framework it is chosen for me.

Because I could not choose the target framework the only way was to force it by removing the \net45 folder from the NuGet package and repackage it. Then the .NET Framework 4.7.1 App would use the .NET Standard 1.3 RavenDB library. Or use RaveDB 4.0, which was more of a task because I had to upgrade the server and rewrite some code.

If you look at the RaveDB 4.0 package it only has .NET Standard libraries. Hence why it would work in a project targeting 4.7.1 that references a .NET 2.0 Standard class library.

\lib \netstandard1.3 \netstadnard2.0