How to Target netcoreapp and net461 from ASPNET Core

The default templates for ASP.NET Core RC2 apps only target “netcoreapp1.0”. If you wish to have one app target multiple frameworks, you can do so by first adding the new framework to the list in project.json (e.g. “net461” for .NET Framework 4.6.1). However, once you do this you’ll get an error that Microsoft.NETCore.App is broken and perhaps an error like this one:

error NU1002: The dependency System.Runtime.Loader 4.0.0-rc2-24027 does not support framework .NETFramework,Version=v4.6.1.

The solution is to move the “Microsoft.NETCore.App” dependency out of “dependencies” and into a new “dependencies” section under the “netcoreapp1.0” key in “frameworks”. Here is a full, working project.json for an ASP.NET Core RC2 app that targets both netcoreapp1.0 and NET461:

 

  • Did you try to publish such app (ASP.NET Core rc2 with target framework .NET 4.6) to Azure?
    In my case it error 500 while works well if I publish the same app for target framework .NETCoreApp

    • ardalis

      I haven’t yet. I’m not sure Azure web apps support RC2, yet. I’m sure you could get it working in a VM, but I don’t know beyond that.

  • RealThing

    Steve, I have noticed that with the frameworks dependencies the way you have above that my web app when deployed on IIS includes both a web-application.dll and web-application.exe which are coming from the netcoreapp1.0 and net461 bin folders. Also, my web app won’t run anymore since including the dependency for .NET 4.6.1. Have you tried running your app on IIS?

    • ardalis

      Not yet, no. And in any case, RTM is coming in under 3 weeks and is likely to change some of this, so I’m probably going to just hold out for that.

  • scottdock

    Steve – I am dealing with this same issue right now, with RTM. Everything works fine in Visual Studio, but my msbuild process via AppVeyor is failing – saying my custom assemblies “does not support framework .NETFramework,Version=v4.6.1.” But they do in fact reference that framework. Have you run into this again with RTM? Any suggestions?

    • ardalis

      Sorry, I haven’t seen it again. Are you sure your production environment is totally clean? Did it ever include RC bits?