From Cake to Nuke - Files in use and Visual Studio Active Build configurations

Today I ran into some issues when trying to run a nuke build, where the message was along the lines of "could not copy _build.exe to bin\Debug_build.exe".

Tracking down the cause of this issue, the following comment by Nuke's creator, Matthias Koch proved to be the most useful:

"If your build project is built when building the solution, you have a misconfigured solution" - Matthias Koch @matkoch Dec 28 2018 00:15

So it turns out what happens is that when you open a solution configured with a nuke build project, Visual Studio may automatically add active build configurations to the solution file. In my case, the following modifications were made by Visual Studio to my solution file:

{A7952760-6A32-48D8-8A72-24FE069E0275}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A7952760-6A32-48D8-8A72-24FE069E0275}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7952760-6A32-48D8-8A72-24FE069E0275}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{A7952760-6A32-48D8-8A72-24FE069E0275}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{A7952760-6A32-48D8-8A72-24FE069E0275}.Debug|x86.ActiveCfg = Debug|Any CPU
{A7952760-6A32-48D8-8A72-24FE069E0275}.Debug|x86.Build.0 = Debug|Any CPU
{A7952760-6A32-48D8-8A72-24FE069E0275}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A7952760-6A32-48D8-8A72-24FE069E0275}.Release|Any CPU.Build.0 = Release|Any CPU
{A7952760-6A32-48D8-8A72-24FE069E0275}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{A7952760-6A32-48D8-8A72-24FE069E0275}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{A7952760-6A32-48D8-8A72-24FE069E0275}.Release|x86.ActiveCfg = Release|Any CPU
{A7952760-6A32-48D8-8A72-24FE069E0275}.Release|x86.Build.0 = Release|Any CPU

Now that this change has been made, if you try to run a nuke build, it will raise a warning that there is an active build configuration in the solution file:

Repeating warnings and errors:
Solution D:\Checkouts\lana_superduperclean\Lana.sln has an active build configuration for D:\Checkouts\lana_superduperclean\build\_build.csproj.

This issue is basically that having the build project be built as part of a solution build causes a rebuild of the build project, ... which ultimately cannot succeed when running a nuke build as the nuke process itself is being run from the Debug / Release folder of the build project. What we need to do is to tell Visual Studio to not build the "Build" project for any Configuration (Debug / Release) or project type (Any CPU, x64, x86 etc). This can be done via the gui by right clicking the solution, and choosing "Configuration Manager..." from where you are able to toggle off the 'Build' checkbox for each possible permutation.

Or a quicker way to achieve this is to remove all lines that Visual Studio added to the solution that contain ".Build.0", in my case this meant removing the following lines:

{A7952760-6A32-48D8-8A72-24FE069E0275}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7952760-6A32-48D8-8A72-24FE069E0275}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{A7952760-6A32-48D8-8A72-24FE069E0275}.Debug|x86.Build.0 = Debug|Any CPU
{A7952760-6A32-48D8-8A72-24FE069E0275}.Release|Any CPU.Build.0 = Release|Any CPU
{A7952760-6A32-48D8-8A72-24FE069E0275}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{A7952760-6A32-48D8-8A72-24FE069E0275}.Release|x86.Build.0 = Release|Any CPU

After doing so, the warning is removed from Nuke when you run a build and you should no longer recieve the "could not copy _build.exe to bin\Debug_build.exe" errors.

Hope this helps,