Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference a Full Framework Library Project from ASP.NET Core MVC Web Application (RC2)?

I'm currently using ASP.NET Core MVC RC2 which is suppose to support referencing a full framework library Project from a Core MVC Web Application Project. But I can't seem to make it work.

I have an existing full framework library project that I'd like to use with a new Core MVC Web application project. But when I try to add a reference to the library's project I get an error that says the target framework for it is incompatible with the target framework for the web application.

To try to simplify the problem I created a new Core MVC web application and a new Windows Code Library and tried to add a reference from the web application project to the library's project and got the same error message. I've searched on stack overflow and I did find this question that seemed highly relevent:How to make ASP.NET Core RC2 app build on net46 framework with older third party dependencies but I was unable to use the information there to solve my issue.

Here are the steps to reproduce the issue:
I created a solution with a ".NET Core" "ASP.NET Core Web Application" project based on the "Web Application" template in Visual Studio 2015.

[pic 1

[pic 2

I then added a new "Windows" "Class Library" project to the solution.

enter image description here

So at this point the solution looks like this:

pic 4

Now, when I try to use visual studio to add reference from the Core MVC Web Application to the Full Framework library I get an error that says that "ExampleLib has a target frameworks that are incompatible with the targets in current project ExampleWebApplicaiton.":

enter image description here

This error seems fairly self explanatory and seems to want me to change the framework that the web application is targeting so that it's the same as the library, which makes perfect sense. The problem is that I can't find documentation on how to do that and intellisense isn't being particularly helpful.

I suspect I need to change one of the following pieces of the project.json file for the web application:

"dependencies": {
    "Microsoft.NETCore.App": {
     "version": "1.0.0-rc2-3002702",
     "type": "platform"
   },

or

 "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "dnxcore50",
        "portable-net45+win8"
      ]
    }
  },

How do I specify .NETFramework Version 4.6 for the Core MVC Web Application instead of .NETCoreApp?

like image 599
RonC Avatar asked May 23 '16 18:05

RonC


People also ask

Can you reference .NET framework from .NET core?

The answer is no, we cannot use . NET Framework Base Class Library in . NET Core because of compatibility issues. Basically, the libraries which target .

How do I add a reference to .NET core library?

Add Class Library Reference To use a class library in your application, you must add a reference to the library to access its functionality. Right click on the project name of your console app in Solution Explorer and select Add ->Reference option.

Can we use NET Framework class library in .NET core?

All aspects of . NET Core are open-source including class libraries, runtime, compilers, languages as well as application frameworks. . NET Core also supports C#, Visual Basic, and F#.


1 Answers

There is a template that allows you to target the full .NET framework - sorry, can't post an image yet, but you can go to: Templates -> Visual C# -> Web -> ASP.NET Core Web Application (.NET Framework)

Note that you can specify the version of the .NET Framework from the dropdown above (as per usual).

This will change your project.json to:

"frameworks": {
"net461": { }
}

(depending on the framework version that you've selected). You will now be able to add a reference to your class library.

"frameworks": {
    "net461": {
    "dependencies": {
    "ClassLibrary1": {
        "target": "project"
        }
     }
   }
}
like image 89
JC1001 Avatar answered Sep 27 '22 15:09

JC1001