Search code examples
continuous-integrationteamcitycakebuild

CAKE throws error claiming argument was not set, even though it was


I am using Cake 0.21.1.0.

For my project, as a build step on TeamCity, I execute build.ps1, which in turn invokes build.cake. I pass in the following arguments to my build.ps1 script, in accordance with the CAKE documentation:

-ScriptArgs '-MSBuildLogger="JetBrains.BuildServer.MSBuildLoggers.MSBuildLogger,%teamcity.dotnet.msbuild.extensions4.0%"'

In build.cake, I added the following line:

var msBuildLogger = Argument<string>("MSBuildLogger");

However, the following error was thrown:

[15:37:22]Error: Argument 'MSBuildLogger' was not set.
[15:37:22]Process exited with code 1

What did I do wrong?


Solution

  • Try the following build.cake file:

    var logger = Argument<string>("MSBuildLogger");
    
    Task("Default")
      .Does(() =>
    {
      Information(logger);
    });
    
    RunTarget("Default");
    

    Also, fetch the most recent bootstrapper file from the resources repository using:

    Invoke-WebRequest https://cakebuild.net/download/bootstrapper/windows -OutFile build.ps1
    

    Then run the following:

    .\build.ps1 -ScriptArgs '-MSBuildLogger="JetBrains.BuildServer.MSBuildLoggers.MSBuildLogger,%teamcity.dotnet.msbuild.extensions4.0%"'
    

    Confirm that you are getting the correct output when running the script locally. i.e. take TeamCity out of the equation.