Link to the .NET 4.6.2 Class Library from the .NET Core Application

I am using VS Update 3 (14.0.25425.01). Here is what I did:

  • Creating an ASP.Net Core Web Application (.Net Core)
  • Create .Net 4.6.2 Class Library
  • Add net462 to framework, netcoreapp1.0 , import into project.json
  • Right-click on the ASP.Net Core application, click Add Link, select Projects, select the Class Library created in step 2.

I do not get errors during recovery, and the link is added to the ASP.Net Core application. However, I cannot access it. I cannot add using import declaration or access to objects. I ran a lot of things, but nothing works, and the messages are very fragmented by versions.

enter image description here

Here is the Program.cs program in the ASP.Net Core application. enter image description here

enter image description here

Update I did what Nate suggested. I thought I already tried this ... but of course I can now access my libraries 4.6.2. However, now I get compilation errors.

enter image description here

+6
source share
2 answers

This works in Visual Studio 2015 Update 3, but your project.json not quite right.

Instead of adding net462 to the imports section imports it should be in the frameworks section:

 "frameworks": { "net461": { }, "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { "type": "platform", "version": "1.0.0" } } } } 

Note that the Microsoft.NETCore.App dependency should also be migrated to the netcoreapp1.0 section. This is because this dependency is only required when compiled as a .NET Core application.

The link to your .NET 4.6.2 library will simply be part of your dependencies section:

 "dependencies": { (...) "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", "MyLibrary": { "target": "project" } } 

By structuring it in this way, I was able to easily cope and use classes in my .NET 4.6.2 library.


For reference, here is the whole working project.json I used:

 { "dependencies": { "Microsoft.AspNetCore.Mvc": "1.0.0", "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0", "Microsoft.Extensions.Configuration.CommandLine": "1.0.0", "Microsoft.Extensions.Logging": "1.0.0", "Microsoft.Extensions.Logging.Console": "1.0.0", "Microsoft.Extensions.Logging.Debug": "1.0.0", "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", "MyLibrary": { "target": "project" } }, "frameworks": { "net461": { }, "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { "type": "platform", "version": "1.0.0" } } } }, "version": "1.0.0-*" } 
+4
source
Answer to

@NateBarbettini fulfilled my initial question. But I could not start ASP.NET Core Web Application version 1 with my .Net 4.6.1 project, because it could not find the assembly .NetCore.App v1 for my .Net 4.6.1 project. So I added project.json to my .Net 4.6.1 project with the following project.json.

 { "version": "1.0.0-*", "dependencies": { "NETStandard.Library": "1.6.0" }, "frameworks": { "netstandard1.6": { "imports": "dnxcore50" }, "net461": {} } } 

Then, in the main ASP.Net web application, modify project.json by adding the dependency to .NetCore.App. Thus, he will pick up both versions, 4.6.1 and .NetCore v1.

 ... "frameworks": { "net461": { "dependencies": { "ClassLibrary1": { "target": "project" } } }, "netcoreapp1.0": { "imports": [ "dotnet5.6", "portable-net45+win8", "net461" ], "dependencies": { "Microsoft.NETCore.App": { "version": "1.0.0", "type": "platform" }, "ClassLibrary1": { "target": "project" } } } } 

So far so good, I can develop in .Net 4.6.1, and it will run under .NetCore.App v1. However, I think there will be problems when I have other dependencies in my .Net 4.6.1 projects.

+1
source

All Articles