![]() |
Nuke.Cola
|
Build plugins for Nuke is a way to implicitly share build tasks which the main build tool can pick up automatically from anywhere within the project. For components which are independent of each-other but they don't individually make a complete project, like a composition of those are expressing the resulting piece of software, it might not make sense for them to have independent full fledged Nuke context for each of them. For these scenarios Nuke.Cola provides a way to discover C# scripts or C# projects following a specific convention anywhere inside the subfolders of the project (recursively). These plugins can be then just distributed and re-used along these components.
This is originally developed for Unreal plugins where the main project's Nuke scripts or the pre-built independently distributed build-tools shouldn't explicitly know about the plugin composition of the project they need to work on in runtime. Unreal, or other non-dotnet project models might not have the capacity or cultural acceptance to rely on a Nuget infrastructure to distribute build scripts of these independent software components, which then could be referenced by the main project. Even if that would be plausable it would still take uncomfortable extra boilerplate for each of these software components. In case of a pre-built build tool based on a Nuke build script, this is the only way I know of to have dynamically composable software component specific build scripts considered.
Build plugins are discovered before the main entry point of Nuke, if the developer uses
public for this to work.The following kinds of plugins discovered this way:
*.nuke.csx standalone C# script files.*.Nuke.csproj named C# projects.[ImplicitBuildInterface] tagged interfaces in the main build.Scripts are better when there's a single file with few targets which don't need to interact with the main build class, projects are better for more elaborate scenarios and [ImplicitBuildInterface] can be used when <Compile Include="../**/*.nuke.cs" /> is specified for the build project.
In all cases build interfaces inheriting INukeBuild are picked up and their targets and parameters are added to the final Nuke build class. Read more about Nuke build interfaces (or "Build Components" as they call it). Targets of Plugins have complete freedom to interact with the entire build graph, especially when the build graph is expressed first in a Nuget package library (like Nuke.Unreal already gives Unreal plugins a lot to work with).
This is simply an interface defined in your main build project. It may not seem very useful until one factors in the following addition to your build csproj:
This means that without any further configuration one can put .nuke.cs files anywhere in their project and write scripts in the context of their placement. This is the easiest to configure method requiring the least bboilerplate but obviously it doesn't work on pre-built nuke build-tools.
if one creates a csproj based build plugin which sole purpose is to include source files that way. In that case the prebuilt build tool can discover .nuke.cs files provided when compiling the csproj plugin.
Example:
Example:
You can put a *.nuke.csx file anywhere and it will be picked up as a Build Plugin. Nuke.Cola will also configure VSCode for C# scripts auto-completion support as common courtasy. In order for VSCode to pick up nuget references use .NET: Restart Language Server via the command palette (or Omnisharp: Restart OmniSharp in case that fallback is used). Debugging plugins require you to modify .vscode/launch.json and run the desired targets/parameters as startup. Mutliple scripts with the same name in different folders can co-exist as long as they define unique interface names.
You can put a *.Nuke.csproj named project anywhere and the build script using Nuke.Cola will pick it up. Simplest way to do it is via dotnet command line:
then add Nuke.Cola Nuget package (and your own project's specific shared build components):
and then you can proceed as with any other dotnet class library.
Building plugins can take a long time, and if nuke is run repeatedly this can get worse pretty quickly. For this reason if REUSE_COMPILED environment variable is set to 1 or --ReuseCompiled is present in command line arguments, plugins are only re-built / re-discovered the first time they're needed. Consecutive runs assume that nothing is changed.
This is useful for CI runs or when nuke is run frequently locally.
As an extra Nuke.Cola provides build.ps1 / build.sh entry points which also respect these indicators, so they can skip directly to executing the build without going through all the checks and preparations.