An MSBuild SDK package that provides Project System support for NuGet package authoring. Having a separate Project System makes it possible to author complex NuGet packages, otherwise not possible with Pack targets. One such need is to create a completely customized package with a custom layout that is different from the standard layout. One can also pack existing libraries (via other projects and packages) into the package or add them to package dependencies.
It's basically an SDK wrapper around NuGet.Build.Packaging aka NuGetizer-3000 project, with targets optimized for SDK-style projects.
Visual Studio v15.6+ includes support for SDK's resolved from NuGet. That makes using the custom SDKs much easier.
See Using MSBuild project SDKs guide on Microsoft Docs for more information on how project SDKs work and how project SDKs are resolved.
-
Create a new project
- from
dotnet new
templates. - With your existing SDK-style project.
- from
-
Replace
Microsoft.NET.Sdk
withNuGet.Packaging.Sdk
in the project's top-levelSdk
attribute. -
You have to tell MSBuild that the
Sdk
should resolve from NuGet by- Adding a
global.json
containing the SDK name and version. - Appending a version info to the
Sdk
attribute value.
- Adding a
-
Remove the
TargetFramework(s)
and other .NET specific properties from the project file. Older versions of VS IDE might requireTargetFramework(s)
property to open the project in IDE successfully. -
Then you can add package specific properties and items (though some are included by default) and use the project for building a NuGet package.
The final project should look like this:
<Project Sdk="NuGet.Packaging.Sdk">
<PropertyGroup>
<PackageId>Vendor.Awesome.Package</PackageId>
<!-- Other Package-specific properties -->
</PropertyGroup>
<!-- Some files in the project and files outside of project cone should be included manually -->
<ItemGroup>
<PackageFile Include="$(RepoRoot)ReadMe.md" TargetPath="\">
<PackageFile Include="SomeBuildCustom.props" TargetPath="\build\$(PackageId).props">
<PackageFile Include="SomeBuildCustom.targets" TargetPath="\build\$(PackageId).targets">
</ItemGroup>
</Project>
You can put the SDK version in the global.json
file next to your solution:
{
"msbuild-sdks": {
"NuGet.Packaging.Sdk": "1.0.0"
}
}
Then, all of your project files, from that directory forward, uses the version from the global.json
file.
This would be a preferred solution for all the projects in your solution.
Then again, you might want to override the version for just one project OR if you have only one project in your solution (without adding global.json
), you can do so like this:
<Project Sdk="NuGet.Packaging.Sdk/1.0.0">
<PropertyGroup>
<PackageId>Vendor.Awesome.Package</PackageId>
<!-- Other Package-specific properties -->
</PropertyGroup>
<!-- Other properties, items and targets -->
</Project>
That's it! You do not need to specify any default properties or items as they'll be automatically defined.
After that, you can use the Restore
, Build
, Pack
targets to restore packages, build the project and create NuGet packages: e.g., msbuild -t:Pack ...
.
- As the project support in the SDK is based on an experimental NuGet project, it requires the NuGet Packaging Visual Studio extension to load
.nuproj
project types. - Since the extension hasn't been updated in a while, newer VS IDE can't install the extension and thus can't open the project. So, either use internally published VS IDE extension or just use VS Code with OmniSharp extension.