Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using net451 libraries in an ASP.NET Core application (RC2)

I'm trying to upgrade my ASP.NET 5 RC1 projects to ASP.NET Core RC2 projects. I'm having some issues because I'm using libraries that do not yet support .NET Core so I have to run on the full framework. This has worked fine in RC1, but I'm not able to figure out the right way to achieve this in RC2.

I have one class library which can restore packages and build properly. And I have a test project referencing the class library. When I try to build the test project, I'm getting the following errors:

> dotnet build
Project TenantService (.NETFramework,Version=v4.5.1) was previously compiled. Skipping compilation.
Project TenantServiceTests (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing
Compiling TenantServiceTests for .NETCoreApp,Version=v1.0
C:\projects\TenantService\test\TenantServiceTests\project.json(25,23): error NU1001: The dependency mscorlib could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(9,31): error NU1001: The dependency mscorlib could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(25,23): error NU1001: The dependency mscorlib could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(9,31): error NU1001: The dependency mscorlib could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(26,21): error NU1001: The dependency System could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(9,31): error NU1001: The dependency System could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(26,21): error NU1001: The dependency System could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(9,31): error NU1001: The dependency System could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(27,26): error NU1001: The dependency System.Core could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(9,31): error NU1001: The dependency System.Core could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(27,26): error NU1001: The dependency System.Core could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(9,31): error NU1001: The dependency System.Core could not be resolved.
C:\projects\TenantService\test\TenantServiceTests\project.json(9,31): error NU1001: The dependency Microsoft.CSharp could not be resolved.

The project.json files for these two projects look like this:

src\TenantService\project.json

{
  "version": "1.0.0-*",

  "dependencies": {
    "NETStandard.Library": "1.5.0-rc2-24027",
    "Microsoft.Extensions.Options": "1.0.0-rc2-final",
    "Newtonsoft.Json": "8.0.4-beta1",
    "MongoDB.Driver": "2.2.4",
    "StackExchange.Redis": "1.1.603"
  },

  "frameworks": {
    "net451": {}
  }
}

test\TenantServiceTests\project.json

{
  "version": "1.0.0-*",
  "testrunner": "xunit",
  "description": "TenantServiceTests Class Library",
  "authors": [ "Henning" ],

  "dependencies": {
    "xunit": "2.1.0",
    "TenantService": "1.0.0-*",
    "dotnet-test-xunit": "1.0.0-rc2-build10015"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.0-rc2-3002702"
        }
      },
      "imports": [
        "net451"
      ]
    }
  }
}

How should I properly set this up in order to use net451 libraries in my app?

like image 741
henningst Avatar asked May 20 '16 11:05

henningst


1 Answers

The dependency mscorlib could not be resolved

I ran into this same problem yesterday. The issue is that the project.json for the test project is targeting the netcoreapp1.0. Instead you can target the net451 framework like the service you're testing against and that should "just work".

{
  "version": "1.0.0-*",
  "testrunner": "xunit",
  "description": "TenantServiceTests Class Library",
  "authors": [ "Henning" ],

  "dependencies": {
    "xunit": "2.1.0",
    "TenantService": "1.0.0-*",
    "dotnet-test-xunit": "1.0.0-rc2-build10015"
  },

  "frameworks": {
    "net451": { }
  }
}

For more details on this checkout the Migrating from ASP.NET 5 RC1 to ASP.NET Core. Another great resource is the markdown file out on the corefx repo that details .NET Platform Standard.

like image 142
David Pine Avatar answered Nov 07 '22 03:11

David Pine