17

Hi firstly i know vaguely similar questions have been asked before, but they are outdated now, I am using Visual Studio 2015 rtm and ASP.NET 5 beta 6.

I'm trying to add a reference to a normal (i.e. not vnext) class library project to my vnext web application. If I follow these steps:

  1. Create a new web app project

  2. Remove the "dnxcore50" framework from project.json

  3. Add a new project for a normal class library

  4. Manually move the class library project into the /src folder (otherwise I get error "The dependency MyClassLibrary1 >= 1.0.0-* could not be resolved.")

  5. Add a reference to this class library

Now it builds OK, but if I try and add "using MyClassLibrary1" it says MyClassLibrary1 doesn't exist in current context.

If I then change the class library to target .NET 4 Client profile (by default it was 4.6) it does work correctly, however .NET 4 full or 4.5 does not work. I need it to be 4.5 or higher as I need to reference various packages that require this. Ideally everything would just target 4.6.

This is my project.json file:

{
  "webroot": "wwwroot",
  "userSecretsId": "aspnet5-WebApplication2-6767111e-0eba-42a4-9d68-4b6c20767518",
  "version": "1.0.0-*",

  "dependencies": {
    "EntityFramework.SqlServer": "7.0.0-beta6",
    "EntityFramework.Commands": "7.0.0-beta6",
    "Microsoft.AspNet.Mvc": "6.0.0-beta6",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta6",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta6",
    "Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta6",
    "Microsoft.AspNet.Authentication.Google": "1.0.0-beta6",
    "Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta6",
    "Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta6",
    "Microsoft.AspNet.Diagnostics": "1.0.0-beta6",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta6",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta6",
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta6",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-beta6",
    "Microsoft.AspNet.StaticFiles": "1.0.0-beta6",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-beta6",
    "Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta6",
    "Microsoft.Framework.Configuration.Json": "1.0.0-beta6",
    "Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta6",
    "Microsoft.Framework.Logging": "1.0.0-beta6",
    "Microsoft.Framework.Logging.Console": "1.0.0-beta6",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta6"
  },

  "commands": {
    "web": "Microsoft.AspNet.Hosting --config hosting.ini",
    "ef": "EntityFramework.Commands"
  },

  "frameworks": {
    "dnx451": {
      "dependencies": {
        "MyClassLibrary1": "1.0.0-*"
      }

    }
  },

  "exclude": [
    "wwwroot",
    "node_modules",
    "bower_components"
  ],
  "publishExclude": [
    "node_modules",
    "bower_components",
    "**.xproj",
    "**.user",
    "**.vspscc"
  ],
  "scripts": {
    "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
  }
}

And my global.json file:

{
  "projects": [
    "src",
    "test",
    "wrap"
  ],
  "sdk": {
    "version": "1.0.0-beta6"
  }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Martin Richards
  • 905
  • 2
  • 9
  • 12
  • I can't even build after adding a class library project to my existing project;s solution. However if I start afresh, it works, what could be the reason. – Randeep Singh Feb 10 '16 at 10:47
  • raised as aspnet core issue: https://github.com/aspnet/Home/issues/1513 – OzBob Dec 22 '16 at 04:11

6 Answers6

23

This is how I did it using beta6 (UPDATE: It's still valid for the RC1 UPDATE 1).

  1. Remove frameworks => dnxcore from your project.json (you can't target it anyway using full .net class libraries)
  2. In your target project right click on References => Add Reference
  3. Navigate and select reference dll you want to add.

This will add a reference entry to your project.json file. Behind the scenes the dll is copied over to /lib directory in your solution and a "wrapper project" with only a project.json file is created in /wrap folder. The wrapper project is documented here (not well enough though): https://github.com/aspnet/Home/wiki/Project.json-file#bin-syntax-wrapping-a-dll

That's it! I've just tested this scenario. Hope this helps.

mbudnik
  • 2,087
  • 15
  • 34
  • 1
    Great, I didn't find that link, the docs are understandably a bit rough. cheers. – Martin Richards Aug 09 '15 at 20:17
  • 1
    Really grateful for your answer, mbudnik. First time someone stated that clearly (that I have found). First time I've been able to reference and utilize my own class library projects in a multi-project Solution from an ASP.NET 5 MVC 6 beta6 front-end project after trying many other methodologies from many other, even quite recent, answers here. I tell myself to keep off the bleeding edge and then each year I step right into it and my foot gets cut. – StackOverflowUser Aug 15 '15 at 06:46
  • 1
    In RC1 I still needed to edit project.json manually to change it to the bin syntax of `{ assembly, pdb }` (see the GitHub docs). Additionally, since my DLL references are projects in the same solution, I needed to add them as Project Dependencies and make sure the website is below them in the Project Build Order. – zemien Jan 22 '16 at 04:07
  • So we can no longer add project references? – ewahner Feb 10 '16 at 19:52
  • I checked in the wrap folder on root lvl and it magically get resolved by other team members now.. – rfcdejong Feb 16 '16 at 11:01
15

If anyone else is struggling with this particular error, the key is to add the reference in by "browsing" to the actual file when adding the reference, and not using the "project" tab.

This doesn't seem to store the path, but adds the reference to the project.json as per normal. Obviously a bug (beta7) at the time of writing this.

JamesDill
  • 1,857
  • 1
  • 18
  • 22
  • Just had this error and this fixed it, bit of a joke really. Adding from projects the reference doesn't seem to have a version against it. – Mark Homer Nov 12 '15 at 12:27
  • I'm having this issue with an ASP.NET 5 MVC front end project referencing packaged ASP.NET 5 class libraries. Any idea how to handle the issue with packaged projects? BTW, I'm using RC1. – Sam Dec 27 '15 at 18:46
2

Here is how I did it in ASPT.NET 5 RC 1 Update 1:

  1. Add the project reference
  2. Open project.json, inside "frameworks": node, delete "dnxcore50": { } line (JSON does not allow comment). When you save the json file, the DNX Core 5 reference should be removed immediately.

  3. Build the project. It should build successfully.

  4. Put "dnxcore50": { } back. It does not bring DNX 5 Core back.

Jeson Martajaya
  • 6,996
  • 7
  • 54
  • 56
1

To add normal .NET project in version greater then 4.5.1 just remove dnxcore and rename dnx451 to dnx461

Adam Wyżgoł
  • 567
  • 4
  • 6
  • 1
    Yes it builds. I tried adding a .NET 4.6.1 class library reference to the ASP.NET Core Web Site. When you run under IIS Express, the message "This site can’t be reached" is displayed in the browser. Startup class constructor doesn't get called. – Andez Apr 30 '16 at 17:42
  • Smae problem here. It builds but crash after the startup on IISExpress debug (F5). – Alan Araya May 10 '16 at 12:45
1

These answers really helped me figure this out. In my case cleaning things up in the solution's "wrap" folder resolved the build errors. I had renamed some class libraries and the old ones were still in there. Removing the old projects and updating the project.json files in the existing projects did the trick. Make sure the dependencies in the project.json files reverence the correct projects.

Here's an example:

  "dependencies": {
    "DomainRepository": "1.0.0-*",
    "Domain": "1.0.0-*",
    "DomainContract": "1.0.0-*"
  }
James
  • 1,440
  • 14
  • 12
0

This is a currently open bug. Here's the link so you can see when it closes: https://github.com/aspnet/Tooling/issues/245

empty
  • 5,194
  • 3
  • 32
  • 58