You can reference all the build infrastructure required for a development technology stack such as the .NET SDK simply by referencing a set of properties and targets collectively known as a project SDK by its specific ID. The ID references a particular set of .props files that contain property definitions, and .targets files that contain target definitions. You reference a project SDK by using the Sdk attribute on the top-level project node.
There are many SDKs distributed by Microsoft. The project SDK referenced in the previous example has the moniker Microsoft.NET.Sdk. The project SDKs associated with .NET Core and .NET 5 and later are listed at .NET Project SDK overview.
Reference a project SDK
There are three ways to reference a project SDK:
Use the Sdk attribute on the <Project/> element
XML
<ProjectSdk="My.Custom.Sdk">
...
</Project>
An implicit import is added to the top and bottom of the project as discussed previously.
To specify a specific version of the SDK, append it to the Sdk attribute:
When you explicitly include the imports in your project, you have full control over the order.
When using the <Import/> element, you can specify an optional Version attribute as well. For example, you can specify <Import Project="Sdk.props" Sdk="My.Custom.Sdk" Version="1.2.3" />.
Warning
If you change your project to use <Import/> elements, make sure you add both .props and .targets imports, and that you remove the SDK from the <Project/> element and <Sdk/> elements. Failure to do so will result in doubled imports and an MSB4011 warning.
How project SDKs are resolved
When evaluating the import, MSBuild dynamically resolves the path to the project SDK based on the name and version you specified. MSBuild also has a list of registered SDK resolvers, which are plug-ins that locate project SDKs on your machine. These plug-ins include:
A NuGet-based resolver that queries your configured package feeds for NuGet packages that match the ID and version of the SDK you specified.
This resolver is only active if you specified an optional version. It can be used for any custom project SDK.
A .NET SDK resolver that resolves MSBuild SDKs that are installed with the .NET SDK.
This resolver locates project SDKs such as Microsoft.NET.Sdk and Microsoft.NET.Sdk.Web that are part of the product.
A default resolver that resolves SDKs that were installed with MSBuild.
The NuGet-based SDK resolver supports specifying a version in the global.json file, which allows you to control the project SDK version in one place rather than in each individual project:
Only one version of each project SDK can be used during a build. If you reference two different versions of the same project SDK, MSBuild emits a warning. It is recommended to not specify a version in your projects if a version is specified in the global.json file.
Create a .NET project and learn to add packages and manage package dependencies in your project. Use the .NET Core CLI and NuGet registry to add libraries and tools to your C# applications through Visual Studio Code.