Supports creating MSBuild solutions which are MSBuild projects that indicate what projects to include when building your solution tree. They are an evolution of the classic Visual Studio solution (.sln) files.
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
withMSBuild.Solution.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 properties, items, tasks and targets to customize your solution to your needs.
The final project should look like this:
<Project Sdk="MSBuild.Solution.Sdk">
<PropertyGroup>
<SolutionName>eShopSolution</SolutionName>
<RootNamespace>Contoso.eShop</RootNamespace>
</PropertyGroup>
<!-- Projects under the solution directory are automatically included -->
<ItemGroup>
<!-- Project Folders are also supported! -->
<ProjectFolder Include="Tools\Build\"/>
<ProjectFolder Include="Tools\Common\"/>
<ProjectFolder Include="Tools\Publish\"/>
</ItemGroup>
<!-- For projects outside of solution you can include it like so… -->
<ItemGroup Condition="Exists('$(RepoRoot)..\eShopTests\')">
<ProjectFile Include="$(RepoRoot)..\eShopTests\**\*.*proj"/>
<ProjectFolder Include="$(RepoRoot)..\eShopTests\ConsoleTests\"/>
</ItemGroup>
</Project>
You can put the SDK version in the global.json
file next to your solution:
{
"msbuild-sdks": {
"MSBuild.Solution.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="MSBuild.Solution.Sdk/1.0.0">
<PropertyGroup>
<SolutionName>eShopSolution</SolutionName>
<RootNamespace>Contoso.eShop</RootNamespace>
</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 solution and create NuGet packages: e.g., msbuild -t:Pack ...
.
- This SDK does not support Common Project System (CPS) protocol. As such, it may not open in Visual Studio and other IDEs that require it.
- But code editors such as Visual Studio Code and others will open the project without any issues as they (OmniSharp) don't require CPS.