0

I have .env files(which has round 300) which I wanted to access env variables in VSTS tasks, (we not planning to use existing variable groups) . I found https://github.com/tonerdo/dotnet-env.

I have nuget restore to this Feed and installed pkg, and from CMD line when I access

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

I get

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

my Neget Task -

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

Please advice .

Thanks,

Community
  • 1
  • 1

2 Answers2

0

The package you find is a .Net Library which should be used in coding like C#, it cannot be called from CMD directly.

To use the env file in VSTS Build, you can add a Power-Shell script task and use powershell to load the env files. For example: Script Smaple

Eddie Chen - MSFT
  • 29,708
  • 2
  • 46
  • 60
0

You should configure your project to use dotenv then search upwards through the directories from the assembly path to the root and see if there is a .env, if there is, then load it... it's a shame it isn't the default behavior for dotenv for .net, like other platforms.

Also, you can use the Libraries area of your Pipelines in VSTS/Azure DevOps to specify environment variables, then bind them to the pipeline in question and they will be loaded for your tasks.

Tracker1
  • 19,103
  • 12
  • 80
  • 106