Global Builds
Instead of adding and maintaining build projects in all your repositories, you can also build them by convention using a global build. Global builds are based on the concept of .NET global tools and additionally include all the necessary tools referenced through NuGet packages. That means that for building one of your repositories, you only need to install and execute your pre-packaged build.
Packaging
As a first step, you need to extend the build project file with the necessary information for global tool packaging. Particularly, that includes the PackAsTool
and ToolCommandName
property:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<PackAsTool>true</PackAsTool>
<ToolCommandName>my-build</ToolCommandName>
</PropertyGroup>
</Project>
Afterwards, the project can be packaged and deployed as usual:
dotnet pack --version <version>
dotnet nuget push MyBuild.<version>.nupkg --source <source> --api-key <token>
Currently, single-file deployments are not supported. That means that the operating system must have the .NET SDK installed. Feel free to track the related GitHub issue for any updates.
Installation
Once the global build is packaged and deployed, you can install it either locally to a repository or globally on your development machine:
- Local Tool
- Global Tool
dotnet new tool-manifest
dotnet tool install MyBuild
dotnet tool install -g MyBuild
When you want to guarantee reproducibility, local tools are the better fit since the version is pinned individually for every repository. Global tools, on the other hand, provide more convenience in that you're always building with the same version. This is especially helpful when your conventions, like folder structure and namings, are already well evolved.
Execution
After installation, you can invoke the build through the command that you've specified in ToolCommandName
. As per the example from above:
- Local Tool
- Global Tool
dotnet my-build [args]
my-build [args]