2

I am attempting to use the new Class Library (Package) project in VS 2015.

I would like to target dnx451, so my package.json looks like this:

{
  "version": "1.0.0-beta-1",
  "description": "Foo",
  "authors": [ "Foo" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",

  "dependencies": {
    "Newtonsoft.Json": "8.0.1",
    "Microsoft.AspNet.Razor": "4.0.0-rc1-final",
    "Microsoft.Extensions.Configuration": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc1-final",
    "System.Net.Http": "4.0.1-beta-23516"
  },

  "frameworks": {
    "dnx451": { }
  }
}

Build is fine, and I get:

Recaptcha-dnxcore -> C:\Users\Epic\Documents\artifacts\bin\Foo\Release\Foo.1.0.0-beta-1.nupkg

Now I create a web project and edit its project.json file so that it targets only the dnx451 framework:

"frameworks": {
    "dnx451": { }
 },

When I add a reference to my Foo package, I get an error:

The dependency Foo 1.0.0-beta-1 in project WebApplication7 does not support framework DNX,Version=v4.5.1.

How can I create a Nuget package from a Class Library (Package) project that supports dnx451?


Per the comment below, here is the full project.json of the web app:

{
  "userSecretsId": "aspnet5-WebApplication7-0b4c05f0-6435-486b-9738-1b6aa3daee2c",
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "EntityFramework.Commands": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc1-final",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
    "Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final",
    "System.Net.Http": "4.0.1-beta-23516",
    "Foo": "1.0.0-beta-1"
  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel",
    "ef": "EntityFramework.Commands"
  },

  "frameworks": {
    "dnx451": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ],
  "scripts": {
    "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
  }
}
Mister Epic
  • 16,295
  • 13
  • 76
  • 147
  • How do you build the projects and can you please share the web app's project.json file? – Victor Hurdugaci Jan 26 '16 at 02:04
  • @VictorHurdugaci `project.json` added. Nothing exotic for the build - I specify that I want my class library to produce outputs on build, and then Right-Click -> Build – Mister Epic Jan 26 '16 at 02:09
  • I just rebuild your project.json in one solution. No build error here. With or without output to file. My personal guess: Foo is somewhere cached, and your build catches the wrong file. – Thomas Jan 28 '16 at 14:26

4 Answers4

1

I followed the same procedure as mentioned in your question

  1. I created both class library and web project in same solution, everything worked fine.

  2. Since your are more focused on making it NuGet package target to dnx451. I created another web application in separate solution, yes it throws errors because NuGet packages named are many "Foo". I guess due to this restoring of packages is given issue as its referring to Global NuGet feed.

  3. Then I tried referring "Foo" Nuget package locally using this link How to install a Nuget Package .nupkg file locally?

  4. Ensure that newly create local Package Source should be on TOP and Offical NuGet second place.

  5. After this, I restored web application in separate solution, it build fine and run properly also. Even I installed this NUGET in Console apps also

Hope this works out.

Community
  • 1
  • 1
Mithun Pattankar
  • 1,372
  • 1
  • 8
  • 12
  • This is probably what you need to do. Also, I believe the correct framework to target for class library projects is `net451`, not `dnx451`. Because class libraries do not have a dnx run entry point like web & console apps do. – danludwig Jan 28 '16 at 14:54
  • @danludwig I guess net451 and dnx451 are meant for giving names to framework target and its dependencies. Am I right? – Mithun Pattankar Jan 28 '16 at 15:06
  • Turns out I had a couple issues, the first as @danludwig pointed out I needed to target `net451` for a class library - my own fault for trying to do things manually! I also needed to increment my version number and rebuild before re-installing. – Mister Epic Jan 28 '16 at 22:32
  • tbh I am not really sure. I think dnx451 and net451 both target the same runtime framework, but that targeting dnx451 just designates a project as an application entry point (class libraries by definition are not application entry points). @MisterEpic, glad you got the answer you were looking for. – danludwig Jan 29 '16 at 14:30
0

The class library should also have it's own project.json and define the frameworks that it supports:

"frameworks": {
    "dnx451": { }
 }
Samuli Haverinen
  • 415
  • 5
  • 10
0

Don't add the version Number if you add a reference to a project, because it will search for the package on any Nugget feed.

Just add a reference to Foo, like this:

    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final",
    "System.Net.Http": "4.0.1-beta-23516",
    "Foo": ""
  },
Juergen Gutsch
  • 1,774
  • 2
  • 17
  • 28
  • I am trying to include this as a Nuget package, not as a project reference. I would like to distribute my work, but need to understand how I can target dnx451 – Mister Epic Jan 27 '16 at 13:16
  • Is it already distributed to NuGet.org? If not, you can't use a reference to NuGet. – Juergen Gutsch Jan 27 '16 at 13:42
  • I am pretty sure that your configuration is ok, except the reference to "Foo" :) If you reference it like I showed, it will still use the generated NuGet package but not from a public nugget feed, but from the output folder of "Foo". – Juergen Gutsch Jan 27 '16 at 13:51
  • Note you can set up a Nuget feed locally and reference a package that way. I do not want a project reference, I am looking to add a package reference. – Mister Epic Jan 28 '16 at 00:53
  • Did you already set up the local feed and did you already register it to DNVM? – Juergen Gutsch Jan 28 '16 at 13:06
0

Have a look at this answer.

You can only add a direct reference to your class library project only if both projects are in the same solution.

If your projects are not in the same solution you have to go to your class library project properties, open Build tab and check Produce outputs on build option

enter image description here

NuGet package will be created in {SolutionDir}\artifacts\bin{ProjectName}{Configuration} directory on each project build.

To use the library, publish NuGet package to nuget.org or any other NuGet feed and add it to your project using Visual Studio (References ~> Manage NuGet Packages...) or to dependencies property in project.json.

Community
  • 1
  • 1
Manos Pasgiannis
  • 1,693
  • 1
  • 18
  • 30