Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing a .NET 4.6 project from ASP.NET 5 causes build error

Tags:

asp.net-core

In my ASP.NET 5 RC1 project (targeting only dnx46) I'm trying to add a reference to a (classic) Class Library project targeting .net 4.6.

I get this error at build time: ...\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1819,5): warning MSB3274: The primary reference "...\ClassLibrary1.dll" could not be resolved because it was built against the ".NETFramework,Version=v4.6" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.5.1".

Why is this happening? My ASP.NET 5 project isn't targeting 4.5.1. According to the project.json file it's only targeting dnx46. I can't find any mention of .net 4.5.1 anywhere.

Here's the project.json for my WebApplication project:

{
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final"
  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel"
  },

  "frameworks": {
    "dnx46": {
      "dependencies": {
        "ClassLibrary1": "1.0.0-*"
      }
    },
  },

  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ]
}

And here's the project.json that the "wrapping" process creates for my ClassLibrary project:

{
  "version": "1.0.0-*",
  "frameworks": {
    "net46": {
      "wrappedProject": "../../ClassLibrary1/ClassLibrary1.csproj",
      "bin": {
        "assembly": "../../ClassLibrary1/obj/{configuration}/ClassLibrary1.dll",
        "pdb": "../../ClassLibrary1/obj/{configuration}/ClassLibrary1.pdb"
      }
    }
  }
}
like image 445
BowserKingKoopa Avatar asked Nov 22 '15 18:11

BowserKingKoopa


People also ask

Can you reference a .NET core library from .NET framework?

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

Does .NET 5 implement .NET standard?

NET 5 improves code sharing and replaces . NET Standard except for cases where developers need to extend the reach of their code sharing to support older frameworks such as . NET Framework or share code between specific existing frameworks.


2 Answers

The warning is still there if built using VS 2015 Update 1, but web app works well and can call a method from .net4.6 assembly.

like image 119
Sergei Zinovyev Avatar answered Sep 28 '22 06:09

Sergei Zinovyev


try to upgrade your utilities and Runtime version if you have't upgraded it yet.

  • dnvm upgrade

then from the shell point to your working\project folder clean the cache and restore the project packages

  • dnu clear-http-cache
  • dnu restore

then try build it

  • dnu build
like image 33
Hasan Assi Avatar answered Sep 28 '22 06:09

Hasan Assi