8

I would like to create a NuGet package of my ASP.NET vNext class library. How can I do it, step by step? I understand there is kpm build, but I couldn't find a guide regarding where to download kpm, etc.

Also, after getting a NuGet package (or DLL) of it, how can I add it from local machine to my vNext project?

whyleee
  • 4,019
  • 1
  • 31
  • 33
Adam Szabo
  • 11,302
  • 18
  • 64
  • 100

4 Answers4

5

Kpm is the package manager for the new KRuntime. Instructions on how to install the KRuntime command line utilities on your developer machine can be found on the aspnet Home repo. Once you have kvm and a version of the KRuntime set up you will have kpm available as well.

Now you can run kpm build on your class libraries project location. Output should be something like this:

kpm build src\ClassLibrary1\
ClassLibrary1 -> C:\Users\username\Documents\Visual Studio 14\Projects\WebApplication1\src\ClassLibrary1\bin\Debug\ClassLibrary1.1.0.0.nupkg
ClassLibrary1 -> C:\Users\username\Documents\Visual Studio 14\Projects\WebApplication1\src\ClassLibrary1\bin\Debug\ClassLibrary1.1.0.0.symbols.nupkg

Build succeeded.
    0 Warnings(s)
    0 Error(s)

Time elapsed 00:00:01.7556414

The easiest way to add a reference to a class project is to do it in your project.json, assuming you have it in the same solution. Here is an example project.json from a web application, which references a class library called ClassLibrary1.

{
    "webroot" : "wwwroot",
    "exclude": "wwwroot/**/*.*",
    "dependencies": {
        "Microsoft.AspNet.Server.IIS": "1.0.0-alpha4",
        "ClassLibrary1": ""
    },
    "frameworks" : {
        "aspnet50" : { },
        "aspnetcore50" : { }
    }
}

If you want to set up a NuGet feed you can read the official NuGet documentation to see how that is done. Copy the outputs of kpm build into your NuGet feed.

Note: VS14 CTP4 only works with alpha4 of the KRuntime. If you want to use VS14 for vNext without errors popping up you need to downgrade your KRuntime to version 1.0.0-alpha4.

AndersNS
  • 1,597
  • 16
  • 24
  • I've retracted my answer but leaving as comment in case anybody else comes here trying to figure this out for regular class libraries: I used [Nuget Package Explorer](https://npe.codeplex.com) to create the nuget packgage for the third party dll's that I needed to reference. After simple drag & drop of dll in lib folder and filling out basic metadata in explorer, I created the package and added the path to Nuget Package Manager (CTP4 version) lookup directories. After that I added the nuget package name directly in project.json and it picked up like it picks up any other online packages. – Maverik Oct 13 '14 at 12:20
  • I've tried this, but it breaks. My class library has a dependency on `"mongocsharpdriver": "1.9.2"`, it's in the `project.json` and it builds fine in VS. However it can't find this dependency when I try to build with `kpm`. It doesn't complain for Microsoft dependencies though. Any ideas? – Adam Szabo Oct 19 '14 at 12:22
  • Hard to say. The package location was moved between alpha3 and alpha4 so it might be that. Make sure your runtime is alpha4 at least. I tried using that package in a simple vnext project and it builds just fine. – AndersNS Oct 19 '14 at 16:29
  • My default runtime is `1.0.0-alpha4 CLR x86` – Adam Szabo Oct 19 '14 at 16:49
5

Creating NuGet package from class library

If you use Visual Studio 2015 RC and later: 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.

If you use command line:

  1. Make sure you installed DNVM and DNX (see ASP.NET Home repo for instructions).
  2. Run dnu pack in the project directory. NuGet package will be created in {ProjectDir}\bin\{Configuration} directory by default.

Using packaged class library

To use the class library in another project from the same solution, add it as a usual project reference in Visual Studio or to dependencies property in project.json:

"dependencies": {
  "ClassLibrary1": ""
}

To use the library in other solutions, 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
whyleee
  • 4,019
  • 1
  • 31
  • 33
0

Not enough rep to comment.

To update to whyleee's answer, according to the migration docs posted on 8/8/16, the tools that were part of the DNX toolset have been superseded by the dotnet CLI tool.

So, dnu pack becomes dotnet pack and creates the nuget and symbols package in the bin/[Configuration] directory by default. You pretty much replace dnu with dotnet for most of the commands.

To add a nuget package locally, see this answer.

Community
  • 1
  • 1
Ken G
  • 199
  • 1
  • 1
  • 10
0

As of VS2019, will need to update project properties / Package tab, and choose to "Generate NuGet package on build".

Property Tab Image

Tom Tate
  • 1
  • 1