glopes
glopes

Reputation: 4390

How do you create a NuGet package from a .NET Core MSBuild project in Visual Studio 2017 RC?

Now that we have an official migration from project.json back to .csproj, how do you actually generate a NuGet package output?

I don't know if it's just me but I find it hard to understand the official documentation pages. The only mention is about calling msbuild from the command line, but it's not really working for me, and besides I was more hoping that you could just specify this step directly in the .csproj file itself.

A complete example of how to do this using .csproj files would be greatly appreciated.

Update: Finally got the MSBuild to output the package by running it from the command line. The trick was fill in a PropertyGroup with all the package metadata as described in the doc pages. However, I still would much prefer to run pack as part of the normal build process.

Update: Found a much better resource for understanding the new .csproj format in the .NET Blog page.

Upvotes: 3

Views: 946

Answers (1)

Weiwei
Weiwei

Reputation: 3776

I'm packing a .NET Core NuGet package with MSBuild in Visual Studio 2017 RC using following steps:

  1. Install Visual Studio 2017 with .NET Core and Docker (Preview) component.
  2. Create a following package information through New -> Project -> C# -> .NET Core -> Console App (.NET Core).
  3. Right-Click the .NET Core project to choose Edit ProjectName.csproj option to open the .csproj file in Visual Studio 2017.
  4. Save a file under the PropertyGroup node with the following package information:

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>netcoreapp1.0</TargetFramework>
        <PackageId>TestNetCorePackage</PackageId>
        <PackageVersion>1.0.0</PackageVersion>
        <Authors>Weiwei</Authors>
        <Description>Test .NET Core package</Description>            <PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
        <PackageReleaseNotes>First release</PackageReleaseNotes>
        <Copyright>Copyright 2016 (c) Contoso Corporation. All rights reserved.</Copyright>
        <PackageTags>Net Core</PackageTags>
    </PropertyGroup>
    
  5. Open Developer Command Prompt for VS 2017 RC and type cd *your project file path* command to navigate to your project file path.

  6. Type msbuild ProjectName.csproj /t:pack, which is the command to pack your .NET Core package. It will generate in bin\debug folder in your project path.

Upvotes: 2

Related Questions