.net core classlibrary call .net framework class library

I could not find the answer to my doubts, and I hope someone can clarify.

I created a dummy solution with

  • 1 class library (.net framework)
  • 1. core core library

Tried to refer anyway, but I can’t, they are incompatible, thin makes sense.

Now my question

I have a utility class library (.net framework) with extensions, helpers, etc ... which is used by winforms-wpf-asp.net mvc 4.5 applications now with the .net core event, it seems to me that I'm more I can not use this library if I do not port it to the .net kernel, which then I can not use with my other applications.

What is the right approach?

Am I missing the obvious?

+4
source share
2 answers

The common code between the regular .NET library and the base project did not work for me by simply using the Shared project, because I could not reference it from the Core project.

However, with a little trick, I could get it to work.

Let me explain this structure / file:

[ProjectName] // Root of Core project project.json [ProjectName].xproj Shared // Root of Shared project [ProjectName].Shared.projitems [ProjectName].Shared.shproj // -- Source files here -- Net // Root of .NET project [ProjectName].csproj Properties AssemblyInfo.cs // For both Core and .NET project // NO source files here 

So, you will need 3 projects, of course: the main project, the regular .NET project and the general project.
The Shared project has all the source files.
The .NET project refers to the Shared project, so it also has these files.
The main project sees all the files of the Shared project, so it also has the same files.

What is it. You can now have common source code files for the .NET and Core project.

A few notes:

  • Never put .shroj and .csproj in the same folder. For me, this completely turned off intellisense in VS (2015). This information was worth a lot of pain for me ...
  • You can use #if -s to fine tune generic code
  • You can also use NuGet 2 in a .NET project with the specified folder structure.
    • Please note that if you place (NuGet 2) packages.config in the same folder where (NuGet 3) project.json , the latter will completely overwrite earlier.
+2
source

You can try to use a project with a shared library. It thus compiles to the application / link library platform. This gives you the opportunity to create class libraries designed for different platforms, without the need to duplicate any code, but this may require some #if ...

https://blogs.msdn.microsoft.com/dotnet/2014/04/21/sharing-code-across-platforms/

0
source

Source: https://habr.com/ru/post/1265290/


All Articles