Support projects that do not compile to an assembly. This is usually the base SDK for other SDKs in this repository.
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.Project.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 custom properties, items, tasks and targets and use the project for various purposes other than building a .NET assembly.
The final project should look like this:
<Project Sdk="MSBuild.Project.Sdk" DefaultTargets="Greet">
<PropertyGroup>
<Greeting>Hello, World!</Greeting>
</PropertyGroup>
<Target Name="Greet">
<Message Importance="High" Text="$(Greeting)"/>
</Target>
</Project>
You can put the SDK version in the global.json
file next to your solution:
{
"msbuild-sdks": {
"MSBuild.Project.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.Project.Sdk/1.0.0" DefaultTargets="Greet">
<PropertyGroup>
<Greeting>Hello, World!</Greeting>
</PropertyGroup>
<Target Name="Greet">
<Message Importance="High" Text="$(Greeting)"/>
</Target>
</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 Greet
target to display the greeting message (in my example) OR roll your own targets to do things that you want: e.g., msbuild -t:DoWork ...
.
- 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.