1

There are a bit confusing information about the backward referencing possibility from .net core applications (e.g. ASP.Net Core) to the commonly used .net framework libraries. I got the following impression now:

  1. If you are using "netcoreapp1.0", then you cannot reference an ordinary library at all.
  2. If you are using e.g. "net451", then you can reference it, but you have to wrap it first in a nuget package with corresponding tag.

Does this sound correct?

P.S. I was thinking that perhaps in case 1 decompiling to IL and recompiling back as "netcoreapp1.0" or "netstandard1.6" or some other voodoo can help?

P.P.S. As mentioned in comments it's possible to reference ordinary class library project that can in turn reference the library, but that will mean you have to wrap everything that is in the library, so depends a lot if this can be used.

Ilya Chernomordik
  • 27,817
  • 27
  • 121
  • 207
  • It's not available *yet*, but there's promise of being able to do some external referencing in [.NET Standard 2](https://blogs.msdn.microsoft.com/dotnet/2016/09/26/introducing-net-standard/) (Search that page for `shim`) – Damien_The_Unbeliever Oct 03 '16 at 11:54
  • in the 2nd option, you can reference a project in the old format too. – Fabricio Koch Oct 03 '16 at 11:55

1 Answers1

4

For the moment this is not possible.

You have 3 options:

  1. attempt to convert your old project into a portable class library (PCL), which can then be referenced by your .net core app.
  2. wrap your project into a nuget package (you already mentioned that)
  3. Add the project as a class library (mentioned in the comments), but according to that SO answer and that GitHub thread it does not seem easy to make it work.

EDIT on 20-03-2017 : Just came across this post: It seems now possible to have your .NET Core app target .NET 4.6 by changing the .csproj, UNTESTED (yet)

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>

to

  <PropertyGroup>
    <TargetFramework>net46</TargetFramework>
  </PropertyGroup>

then dotnet restore followed by dotnet run

Community
  • 1
  • 1
Darxtar
  • 2,022
  • 22
  • 21
  • Can I convert any ordinary dll to a nuget package that can be referenced from asp.net core application? Will it also work with "netcoreapp1.0" or only with "netXXX"? – Ilya Chernomordik Oct 03 '16 at 12:11
  • According to this article https://blogs.msdn.microsoft.com/cesardelatorre/2016/06/28/running-net-core-apps-on-multiple-frameworks-and-what-the-target-framework-monikers-tfms-are-about If you want to consume traditional .NET libraries, you need to be using ASP.NET Core running on top of the traditional .NET Framework (CLR). If your ASP.NET Core app is running on the CoreCLR, then you cannot. For that scenario that you mention, “brown-field”, the recommended approach would be the first that I mentioned, so using ASP.NET Core running on top of the traditional CLR (.NET Framework CLR). – Darxtar Oct 03 '16 at 12:19
  • Another question is will I have to upload the package to nuget, or it can be just used locally without making it public? (Otherwise there is no point in this possibility for private code) – Ilya Chernomordik Oct 03 '16 at 12:21
  • You can use it locally, please look at this thread https://github.com/aspnet/Home/issues/1672 MV10 mentions how to do it, it's painful but it apparently works. "I have to put my files into a NuGet package locally, set up that folder as a NuGet source, browse to the package and load it up that way. " – Darxtar Oct 03 '16 at 12:24
  • Thanks a lot for you help, I'll wait a bit for other answers in case someone has other ideas how to make it work, otherwise I'll accept your answer. It's really a pity there is no good backward compatibility as of now. – Ilya Chernomordik Oct 03 '16 at 12:25
  • no problem, hopefully you can make it work! Good luck ;) – Darxtar Oct 03 '16 at 12:26
  • There is also a third way btw, but it's not too fancy (referencing via a class library project). Added it to the question. – Ilya Chernomordik Oct 03 '16 at 12:34
  • Yeah I came accross it here: https://github.com/aspnet/Tooling/issues/45 but that seems very wobbly to me. There is an SO question mentioning it here: http://stackoverflow.com/questions/38107573/how-to-add-project-reference-to-asp-net-core-1-0-mvc-project seems to be very limited though. – Darxtar Oct 03 '16 at 12:35
  • I tried and that actually worked rather fine with all the latest stuff. Seems MS has done something to support it properly. This does not allow you to reference the library directly though, only via an additional project, which might not be that bad if you use some sort of wrapping. But if you want to use library directly, still no easy way out... – Ilya Chernomordik Oct 03 '16 at 12:51
  • I had some issues with the 3rd option, but it was quite a while ago: I could add the reference, but the namespaces in my library were not recognized. Maybe they fixed that with update 3? I will check later. – Darxtar Oct 03 '16 at 12:56
  • I came across this post: https://jonhilton.net/2017/03/14/use-asp-net-core-1-1-with-net-4-without-visual-studio/ have you managed to get a fully working 'hybrid' project? – Darxtar Mar 20 '17 at 16:30
  • In the latest version of VS2017, I'm able to create a new asp.net core web project based on the .NET Framework (instead of core). This allows me to access older libraries. I using some as old as 2.0. – Michael Silver Aug 11 '17 at 17:43