.NET Framework (4.8) 的 Cake runner 不获取环境变量

Cake runner for .NET Framework (4.8) doesn't pick up environment variables

我正在使用 Cake runner for .NET Framework 构建 .NET Framework 4.8 控制台应用程序。我得到 build.ps1 使用:

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

该文件中没有我自己的更改。我的 build.cake 看起来像这样:

var configuration = "Release";
var buildPath = $"CakeEnvDemo/bin/{configuration}";
var buildDir = Directory(buildPath);

var solution = "CakeEnvDemo.sln";

Task("Clean")
    .Does(() => 
    {
        Information("Running Clean ...");
        CleanDirectory(buildDir);
    });

Task("NuGetRestore")
    .IsDependentOn("Clean")
    .Does(() => 
    {
        Information("Running NuGetRestore ...");
        NuGetRestore(solution);
    });


Task("Build")
    .IsDependentOn("NuGetRestore")
    .Does(() => 
    {
        MSBuild(solution, settings => settings.SetConfiguration(configuration));
    });

Task("AfterBuild")
    .IsDependentOn("Build")
    .Does(() => 
    {
        Information("Running After Build ...");

        var cakeEnv = EnvironmentVariable("cake_env", "default value");
        
        Information($"Got value of cake_env from environment: {cakeEnv}");

    });


RunTarget("AfterBuild");

看看“AfterBuild”任务。基本上,我想在构建完成后读取一个环境变量并对其进行处理。但是,无论我做什么,蛋糕似乎都无法拾取它,而是始终使用我提供的默认值。

根据文档 here,我假设是这样的:

$cake_env="actual env var value"
.\build.ps1

应该可以,但从来没有。我总是得到默认值:

========================================
AfterBuild
========================================
Running After Build ...
Got value of cake_env from environment: default value

我不想使用参数,所以请不要推荐 ScriptArgs。我要环境变量。

这个:

$cake_env="actual env var value"

正在设置本地 PowerShell 变量,而不是环境变量。

您应该可以使用:

$env:cake_env="actual env var value"