在VSTS任务中加载.ENV文件

问题描述 投票:0回答:2

我有.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'. `

我的任务 -

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` 

enter image description here

请指教 。

谢谢,

nuget azure-devops azure-pipelines-release-pipeline azure-pipelines-build-task azure-artifacts
2个回答
0
投票

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

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


0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.