0

我有 .env 文件(大约有 300 个),我想在 VSTS 任务中访问 env 变量(我们不打算使用现有的变量组)。我找到了https://github.com/tonerdo/dotnet-env

我有 nuget 恢复到这个 Feed 并安装了 pkg,当我访问时从 CMD 行

DotNetEnv.Env.Load("./path/to/.env");

我明白了

2018-08-22T09:46:25.1533640Z ##[command]"C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "E:\agent\_work\_temp\6af04df4-4b54-4cd0-89e7-ccc483b488e8.cmd""
2018-08-22T09:46:25.2116417Z 'DotNetEnv.Env.Load' is not recognized as an internal or external command,
2018-08-22T09:46:25.2119634Z operable program or batch file.
2018-08-22T09:46:25.2166604Z 'Loaded' is not recognized as an internal or external command,
2018-08-22T09:46:25.2166869Z operable program or batch file.
2018-08-22T09:46:25.3735465Z ##[error]Cmd.exe exited with code '1'. `

我的 Neget 任务 -

2018-08-22T09:46:19.2173991Z [command]C:\Windows\system32\chcp.com 65001
2018-08-22T09:46:19.2235760Z Active code page: 65001
2018-08-22T09:46:19.3595127Z Detected NuGet version 4.1.0.2450 / 4.1.0
2018-08-22T09:46:19.3676596Z SYSTEMVSSCONNECTION exists true
2018-08-22T09:46:19.7814317Z Saving NuGet.config to a temporary config file.
2018-08-22T09:46:19.7893967Z [command]E:\agent\_work\_tool\NuGet\4.1.0\x64\nuget.exe sources Add -NonInteractive -Name https://www.nuget.org/packages/DotNetEnv/ -Source https://aiz-alm.pkgs.visualstudio.com/_packaging/https%3A%2F%2Fwww.nuget.org%2Fpackages%2FDotNetEnv%2F/nuget/v3/index.json -ConfigFile E:\agent\_work\r14\a\Nuget\tempNuGet_4147.config
2018-08-22T09:46:20.5248516Z Package Source with Name: https://www.nuget.org/packages/DotNetEnv/ added successfully.
2018-08-22T09:46:20.5295503Z [command]E:\agent\_work\_tool\NuGet\4.1.0\x64\nuget.exe sources Add -NonInteractive -Name NuGetOrg -Source https://api.nuget.org/v3/index.json -ConfigFile E:\agent\_work\r14\a\Nuget\tempNuGet_4147.config
2018-08-22T09:46:21.2957596Z Package Source with Name: NuGetOrg added successfully.
2018-08-22T09:46:21.2964479Z Saving NuGet.config to a temporary config file.
2018-08-22T09:46:21.3552331Z ##[section]Finishing: NuGet restor` 

在此处输入图像描述

请指教 。

谢谢,

4

2 回答 2

0

您应该将您的项目配置为使用 dotenv 然后向上搜索从程序集路径到根目录的目录,看看是否有 .env,如果有,然后加载它......很遗憾它不是默认行为对于 .net 的 dotenv,与其他平台一样。

此外,您可以使用 VSTS/Azure DevOps 中管道的库区域来指定环境变量,然后将它们绑定到有问题的管道,它们将为您的任务加载。

于 2019-03-14T00:21:23.277 回答
0

您找到的包是一个 .Net 库,应该像 C# 一样用于编码,它不能直接从 CMD 调用。

要在 VSTS Build 中使用 env 文件,您可以添加一个 Power-Shell 脚本任务并使用 powershell 加载 env 文件。例如:脚本 Smaple

于 2018-08-23T06:21:20.403 回答