0
votes

Silly question perhaps but how do I add a reference from a class library to a web application?

  1. I have the ASP Net 5 RC1 update installed and ready to go.
  2. Created a new website using the AspNet 5 Templateenter image description here

  3. Created a new class library enter image description here

  4. The project.json file looks like this in the class library project

Problem I get is, I have tried adding a reference to the web project via the dependencies section and I get the error

"The dependency Middleware 1.0.0 in project Middleware.Tests does not support framework .NETFramework,Version=v4.5.1. Middleware.Test"

It is glaringly obvious from the message why this is failing however, I am struggling to understand how do I add this reference?

I have tried adding different framework versions like net50 but still no luck.

{
  "version": "1.0.0-*",
  "description": "Middleware.Tests Class Library",
  "authors": [ "Foo Man" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",

  "frameworks": {
    "net451": {
      "dependencies": {
        "Middleware": ""
      }
    }
  }
}

Edit as requested the web project.json file:

{
  "commands": {    
    "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000",
  },
  "compilationOptions": {
    "emitEntryPoint": true
  },
  "dependencies": {
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.Http.Abstractions": "1.0.0-rc1-final",
    "Microsoft.AspNet.Hosting": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-rc1-final",
    "Microsoft.AspNet.Owin": "1.0.0-rc1-final"
  },
  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "frameworks": {
    "dnx451": {
      "dependencies": {
      }
    }
  },
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ],
  "version": "1.0.0-*"
}
1
try changing net451 to dnx451 - Joe Audette
would need to also see the web project.json to help more - Joe Audette
@JoeAudette sorted it! Post as the answer please and I can close it down. - Dr Schizo

1 Answers

1
votes

Unit Test class libraries are considered as "applications", the same as web apps and console apps, and applications should use the "dnx" monikers.

net451 would be correct for normal class libraries, but for unit test projects you should change it to dnx451

Note that this info is relevant only for RC1, in the next release there will be changes to the target monikers that make it easier to target multiple frameworks.