I use .env files in my node.js code to handles secrets in my dev environment configuration. I add .env to my project's .gitignore, to prevent secrets be committed to the git repository.
I found node.js's .env approach quite simple and productive.
What the equivalent of .env files in C#?
With this question I am not looking for a library to do the same in C# like (https://github.com/tonerdo/dotnet-env)
I like to know the c# way of handling the same thing with an emphasis on not committing secrets in config files to git repositories.
This is not an Azure question, so Azure Key Vault Azure App Services are out of scope here.
Update #1
Please note that I am not asking to to handle secrets in my .net applications.
I have been using the options in the document below for many years:
https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-6.0&tabs=windows
Once I started to learn node.js and using .env
I wish I have the same in .net.
.env
files save me from keep tweaking environment variables while I develop node.js apps on my developer laptop. In production I set the env variables.
On my local developer laptop I like to keep my environment variables in a .env
text file. I trust my local laptop encrypted hard drive and there is no production passwords involved in my dev environment.
In essence I am trying to avoid the option below and the hassle of keep tweaking environment variables while I code.
Update #2
This scenario might highlight the advantage of .env
files:
When I develop node.js
apps, In VSCODE, I have the .env
file open in a separate tab to keep changing variables and run my node.js application in the vscode terminal. The scenario is to try different service principles, different database credentials, network credentials etc while I debug/trace my application. To do the same in c#
or .netcode
projects quickly, I have to have a bash script to set the environment variables, tweak it every time before and trace/debug my application.
While it is important to remember to add the set-secret-env-vars.sh
to the .gitignore
file, please consider the node.js
's standard .gitignore
file already includes the .env
because the process is standard and streamlined in node.js
applications.
Please note that I used to use the set-secret-env-vars.sh
approach while coding and debugging my node.js
apps. Then learned about .env
and found it more convenient. That is why I am trying to find a simialr approach for c#
app development workflow.
Update #3
To my understanding, most of the options/workarounds discussed here are specific to an IDE or tool.
launch.json
is feature of VSCODE. You need to launch your code using VSCODE if you want to benefit. With .env
approach, I can run node app1.js
or node app2.js
etc.
What happened if I need to develop using JetBrain's Rider? It is a well respected .net IDE.
My point is that .env
is not depending on any IDE and to my understanding it is very well adopted by many other platforms such as Python.