How to use existing code in asp.net vNext

Trying a little play with asp.net vNext.

Let's say I have a MyCode.dll assembly with some code that I have, and I want to use vNext in my project. How can I reference an existing .net 4.5 assembly?

I packed it into a nuget package, and then using the local channel add it to the vNext project. Also kpm restore to actually download the package.

It seems that the package was added successfully, but the code from MyCode.dll is not available, it just is not used by intelliSence and build throw Type or namespace chould not be found

I could move the code from MyCode.dll to the asp.net 5 class library, but I need to reuse the existing dll, which is also used by other projects, such as older versions of asp.net, etc.

+2
source share
3 answers

My job was to add a local nuget server and correctly specify, package, and push the assembly to the nuget server, so that you can target the multiplicative version of .NET, such as aspnetcore5, aspnet5 and net45. When creating an assembly specification file, remember to include their respective dependencies for each version.

To create a local server, see the instructions here

See sample specification.

 <dependencies> <group targetFramework="net45"> <dependency id="Newtonsoft.Json" version="6.0.6" /> </group> <group targetFramework="aspnet50"> <dependency id="Newtonsoft.Json" version="6.0.6" /> <dependency id="System" version="4.0.0.0" /> <dependency id="System.Core" version="4.0.0.0" /> <dependency id="Microsoft.CSharp" version="4.0.0.0" /> <dependency id="mscorlib" version="4.0.0.0" /> </group> <group targetFramework="aspnetcore50"> <dependency id="Newtonsoft.Json" version="6.0.6" /> <dependency id="System.Runtime" version="4.0.20-beta-22231" /> <dependency id="System.Collections" version="4.0.10-beta-22516" /> </group> </dependencies> 

Sample package

+3
source

If you are using the latest VS 2015 CTP , the easiest way is to add an existing .NET 4.5 project to your ASP.NET 5.0 and use the Add Refernece dialog to link to your 4.5 library. This will make your project.json file look something like this:

 "frameworks": { "aspnet50": { "dependencies": { "MyClassLib": "1.0.0-*" } }, "aspnetcore50": { } }, 

You can only use 4.5 libraries when running the full version of the ASP.NET 5.0 runtime, so make sure that project settings are not configured to target the ASP.NET 5.0 Core runtime. If you want your library to be cross-platform and designed for the Core runtime, you need to rebuild it as an ASP.NET 5.0 library.

enter image description here

+3
source

When I added the "old libraries" to the new ASP.NET, I get Internal Server 500. With some errors in IISExpress. In particular, with System.Reflection.ReflectionTypeLoadException: it is not possible to load one or more of the requested types. Get the LoaderExceptions property for more information.

After researching and some internal debugging with DNX, we finally found the source of the failure.

The node with the display name "System.Web.Mvc" did not load in the "Anonymous" context of the AppDomain binding with identifier 1. The reason for the failure was: System.IO.FileNotFoundException: Failed to load the file or assembly System.Web.Mvc, Version = 5.2. 3.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35 'or one of its dependencies. The system cannot find the specified file.

As the "old" libraries used and older than MVC. I updated my libraries after sending the following command:

Installation Package Microsoft.AspNet.WebApi.Core -version 5.2.3

With the following conclusion:

If the libraries you are trying to use in ASP.NET vNext are dependent on MVC version 5.2.3 or later, you cannot use it in the new structure.

0
source

Source: https://habr.com/ru/post/1212502/


All Articles