32

I have two class library project with the following setting:

  • ClassLibrary1 --> Target framework-->.NET Core 2.1
  • ClassLibrary2 --> Target framework-->.NET Framework 4.7.2

Now I referenced the ClassLibrary1 project in ClassLibrary2 project. It was done successfully. But on rebuilding the project I am getting an error:

Severity Code Description Project File Line Suppression State Error Project '..\ClassLibrary1\ClassLibrary1.csproj' targets 'netcoreapp2.1'. It cannot be referenced by a project that targets '.NETFramework,Version=v4.7.2'. ClassLibrary2

Can anyone help me to know the reason for this error?

Rui Jarimba
  • 11,166
  • 11
  • 56
  • 86
santosh kumar patro
  • 7,231
  • 22
  • 71
  • 143
  • 4
    Can you use `netstandard2.0` as a TargetFramework? – Roman Marusyk Oct 31 '18 at 12:43
  • 5
    Use *.NET Standard 2.0* if you want to create a library project that can be referenced by both runtimes – Panagiotis Kanavos Oct 31 '18 at 12:44
  • Possible duplicate of [How to target netcoreapp2.0 and net461 in the same project](https://stackoverflow.com/questions/46531784/how-to-target-netcoreapp2-0-and-net461-in-the-same-project) – Roman Marusyk Oct 31 '18 at 12:49
  • I have following error with .Net Standard 2.0: Project ... is not compatible with netstandard2.0 (.NETStandard,Version=v2.0). Project ... supports: netcoreapp2.1 (.NETCoreApp,Version=v2.1) – Eralper May 07 '19 at 15:22

2 Answers2

57

You are not able to reference:

  • .NET Core libraries from .NET Framework
  • .NET Framework libraries from .NET Core

If you want to share code between those two libraries you have to use .NET Standard libraries.

.NET Standard is a kind of interface, a versioned list of APIs that you can call, .NET Framework and .NET Core implements this standard

Please see for reference: .NET Standard

Szymon Tomczyk
  • 1,219
  • 11
  • 16
2

I changed my targeting class library to netstandard2.0 and it passed the builds.

gouravm
  • 301
  • 1
  • 12