2

Trying to play a bit with asp.net vNext.

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

I've packed it into nuget package, and then by using local feed add it to vNext project. Also used kpm restore to actually download the package.

It looks like package added successfully, but no code from MyCode.dll available, it's simply not used by intelliSence and build throw Type or namespace chould not be found

I could move code from MyCode.dll to asp.net 5 class library, but I need to reuse existing dll that also is used by other projects, like old versions of asp.net etc.

1
  • This scenario isn't well-supported in ASP.NET 5 just yet. Here's the official bug tracking the work and the proposed designs: github.com/aspnet/XRE/issues/955 Commented Jan 24, 2015 at 19:50

3 Answers 3

3

My work around was to add a local nuget server and correctly spec, pack and push the assembly to the nuget server by doing that you can target multiples version of .NET like aspnetcore5, aspnet5 and net45. When creating the specification file of the assembly don't forget to include their corresponding dependencies for each version.

To create a local server please see instruction here

Please see example 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

Sign up to request clarification or add additional context in comments.

Comments

3

If you are using the latest VS 2015 CTP, the easiest way is to add your existing .NET 4.5 project to your ASP.NET 5.0 solution and use the "Add Refernece" dialog to reference 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 while running the full ASP.NET 5.0 runtime so be sure project settings aren't set to target the ASP.NET 5.0 Core runtime. If you want your library to be cross-platform and target the Core runtime you'll need to rebuild it as an ASP.NET 5.0 Library.

enter image description here

2 Comments

Thanks for you answer, but that works only if you have csproj. what if you have only dll?
A nuget server will help, they are easy to setup please see anserw above
0

When I added "older libraries" to the new ASP.NET, I get the Internal Server 500. With some errors in the IISExpress. Specifically with System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

After research and some internal Debugging with DNX we finally found the source of failure.

The assembly with display name 'System.Web.Mvc' failed to load in the 'Anonymous' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileNotFoundException: Could not load 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 file specified.

As "my older" libraries was using and older MVC. I updated my libraries after to submit the following command:

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

With the following conclusion:

If you libraries that you are trying to use in ASP.NET vNext depends or use an version MVC 5.2.3 or older, You are unable to use inside the new framework.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.