Search code examples
wcfentity-framework-6asp.net-corekendo-asp.net-mvcdotnet-cli

How to make ASP.NET Core RC2 app build on net46 framework with older third party dependencies


I have a shiny new Asp.Net Core MVC App that references some older net45 libraries.

Works fine with Asp.Net Core RC1 on full net45 framework. Migrating from Asp.NET Core rc1 to rc2 I have hit an obstacle that I don't know how to fix.

The App is a ASP.NET Core App that using EF6, Autofac, Kendo.MVC and it needs to run on the full .Net 4.6 framework as there are references libraries that use WCF.

In migrating from rc1 to rc2 I first update the NuGet.config feed to point to https://www.myget.org/F/aspnetcirelease/api/v3/index.json then I make the following changes to the project.json

  • Remove "version" from the top most node
  • Add the following attribute to the complationOptions object: "debugType": "portable"
  • dependencies: change AspNet to AspNetCore
  • dependencies: change all rc1-final, to *
  • Check that MVC and MVC Tag Helpers have been renamed from 6.0 to 1.0
  • Remove all dependencies to Application Insights
  • Remove all dependencies for Microsoft.AspNet.Tooling.Razor
  • Add a dependency to "Microsoft.NETCore.App": { "type": "platform", "version": "1.0.0-*" }
  • Add a new content object: "content": [ "wwwroot", "Views", "web.config", "appsettings.json" ]
    • Update all using statements to reference AspNetCore.* instead of AspNet.*

I then replace the frameworks object with:

"frameworks": {
  "netcoreapp1.0": {
    "imports": [
      "net45"
    ]
  }
}

I do a dotnet restore and everything resolves exceptfor 1 package:

error: Package Kendo.Mvc 2016.1.412 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package Kendo.Mvc 2016.1.412 supports:
error:   - dnx451 (DNX,Version=v4.5.1)
error:   - dnxcore50 (DNXCore,Version=v5.0)
error: One or more packages are incompatible with .NETCoreApp,Version=v1.0.
info : Committing restore...


Errors in project.json
    Package Kendo.Mvc 2016.1.412 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package Kendo.Mvc 2016.1.412 supports:
      - dnx451 (DNX,Version=v4.5.1)
      - dnxcore50 (DNXCore,Version=v5.0)
    One or more packages are incompatible with .NETCoreApp,Version=v1.0.

So, Kendo.MVC needs to reference net45 or net451 instead of dnx451, but since this comes from a NuGet feed, I can't change this.

Do you know if there is a quick fix I can make instead of waiting for the next release of Kendo.MVC?


Solution

  • Your approach is close. Well done. There are a few changes/additions to make. The following works with dotnet restore then dotnet run. The full code listing is on GitHub.

    frameworks

    Your frameworks fail because .NET Core (netcoreapp) is not compatible with .NET Framework (net), so you cannot import net45. Your errors say that Kendo.Mvc is compatible with dnx451 and dnxcore50; import one of those instead. Then add a portable import for some packages on which Kendo.Mvc depends (if you don't, you will see build errors that tell you to do this.)

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

    Now your app will restore and build. It won't run yet, though.

    dependencies

    Change your dependency on Microsoft.NETCore.App not to have the "type" : "platform". Otherwise your app will not run on its own, because NuGet will suppress the package's assets.

    "dependencies" : 
    {
        // others omitted for clarity
        "Microsoft.NETCore.App": "1.0.0-*",
        "Kendo.Mvc": "*"
    }
    

    runtimes

    Add a runtimes section; we now specify this in project.json instead of relying on dnvm.

    "runtimes": {
      "win8-x64": {}
    }