An MSBuild Extension package for automatically including various framework-specific (ASP.NET, UAP, WPF, Xamarin) and platform-specific (Android, Apple, Tizen, Windows, Web) default build items in .NET 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 newtemplates. - With your existing SDK-style project.
- from
-
Add
<Import Sdk="MSBuild.NET.DefaultItems" Project="Items.{props|targets}" />to the top and bottom of the file between the<Project>root elements. -
You have to tell MSBuild that the
Sdkshould resolve from NuGet by- Adding a
global.jsoncontaining the SDK name and version. - Appending a version info to the
Sdkattribute value.
- Adding a
-
Then you can enable the default items through a set of properties for each supported project types.
The final project should look like this:
<Project Sdk="Microsoft.NET.Sdk">
<Import Sdk="MSBuild.NET.DefaultItems" Project="Items.props"/>
<PropertyGroup>
<TargetFrameworks>net48;net5.0</TargetFrameworks>
<EnableDefaultXamlItems>true</EnableDefaultXamlItems>
</PropertyGroup>
<Import Sdk="MSBuild.NET.DefaultItems" Project="Items.targets"/>
</Project>You can put the SDK version in the global.json file next to your solution:
{
"msbuild-sdks": {
"MSBuild.NET.DefaultItems": "0.8.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="Microsoft.NET.Sdk">
<Import Sdk="MSBuild.NET.DefaultItems/0.8.0" Project="Items.props"/>
<PropertyGroup>
<TargetFrameworks>net48;net5.0</TargetFrameworks>
<EnableDefaultXamlItems>true</EnableDefaultXamlItems>
</PropertyGroup>
<Import Sdk="MSBuild.NET.DefaultItems/0.8.0" Project="Items.targets"/>
</Project>That's it! You do not need to specify the .NET or UWP or Tizen framework packages as they'll be automatically included.
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 ....
- This is an Extension/Support SDK that should be in conjunction with other .NET SDKs. So, when using it, be sure to disable their automatic Default items if present and enabled.