Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/KAW0/EnvVariablesGenerator
Generate code from .env files that can be changed after build
https://github.com/KAW0/EnvVariablesGenerator
Last synced: 3 months ago
JSON representation
Generate code from .env files that can be changed after build
- Host: GitHub
- URL: https://github.com/KAW0/EnvVariablesGenerator
- Owner: KAW0
- License: mit
- Created: 2024-02-17T15:43:43.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2024-03-09T17:13:10.000Z (8 months ago)
- Last Synced: 2024-04-26T10:20:17.306Z (6 months ago)
- Language: C#
- Size: 8.79 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- RSCG_Examples - EnvVariablesGenerator
- csharp-source-generators - EnvVariablesGenerator - ![stars](https://img.shields.io/github/stars/KAW0/EnvVariablesGenerator?style=flat-square&cacheSeconds=604800) ![last commit](https://img.shields.io/github/last-commit/KAW0/EnvVariablesGenerator?style=flat-square&cacheSeconds=86400) Generate code from `.env` files that can be changed after build. (Source Generators / Statically typed resources / configurations)
README
# EnvVariablesGenerator
`EnvVariablesGenerator` is a source generator that generates a special class called EnvVariables based on an *.env file.
While there are other libraries that provide similar functionality, they often hardcode variables from the *.env file, making them less flexible.However, in this library, the .env **file is copied to the built project**, allowing for changes to be made to the variables from there.
Additionally, you can opt to exclude this file from the built project and allow your application to load these variables from the actual environment instead.
## Instalation
To use add those lines in your .csproj file:
```xml
Always
```
Where `var.env` is name of your `*.env` file. Name is arbitrar except it must end with `.env`.
Also only one filename in project should end with `.env`
## Example var.env file
```
DB_HOST=localhost
DB_PORT=5432
```
Unfortunately, we cannot use a file named .env because MSBuild goes crazy when trying to add a file with just an extension as an additional file.
Aside from that, you can use whatever name you prefer, but only one file can be utilized.## Example usage
```cs
Console.WriteLine(EnvVariables.Host);
Console.WriteLine(EnvVariables.Port);
```
## License
This library is licensed under the MIT License.