How to create and use ASP.NET vNext class library NuGet package?

…衆ロ難τιáo~ 提交于 2020-01-11 04:48:06

问题


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?


回答1:


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.




回答2:


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:

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.




回答3:


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.



来源:https://stackoverflow.com/questions/26308654/how-to-create-and-use-asp-net-vnext-class-library-nuget-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!