Skip to content

Commit

Permalink
Added a subsection on how to copy the .env file to the output directory
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDave1999 committed May 30, 2022
1 parent 1c0c314 commit 81cc216
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The advantage of using this library is that you do not need to set the environme
* [Load .env file based on environment](#load-env-file-based-on-environment)
* [Parsing .env files](#parsing-env-files)
* [Using DotEnv in ASP.NET Core](#using-dotenv-in-aspnet-core)
- [Copying .env file to the output directory](#copying-env-file-to-the-output-directory)
- [File Format](#file-format)
* [Comments](#comments)
* [Interpolating variables](#interpolating-variables)
Expand Down Expand Up @@ -83,6 +84,9 @@ dotnet add package DotEnv.Core
```

## Overview

The first thing you need to do is create a `.env` file in the root directory of your project.

### Load .env file

You must import the namespace types at the beginning of your class file:
Expand Down Expand Up @@ -228,6 +232,18 @@ builder.Configuration.AddEnvironmentVariables();

For more information, see the [articles](https://mrdave1999.github.io/dotenv.core/articles/getting_started.html).

## Copying .env file to the output directory

If you want to copy the .env file to the output directory, you have to add the following to your .csproj file:
```xml
<ItemGroup>
<Content Include=".env">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
```
**NOTE:** Your .env file must be in the same directory as the .csproj file.

## File Format

- Empty lines or lines with white-spaces will be ignored.
Expand Down
16 changes: 15 additions & 1 deletion docs/articles/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ dotnet add package DotEnv.Core

## Usage

The first thing you need to do is create a `.env` file in the root directory of your project.

### Loading .env file

You must import the namespace types at the beginning of your class file:
Expand Down Expand Up @@ -195,4 +197,16 @@ else
}
```

**Note:** If you don't know what each class does, don't forget to check the [API documentation](xref:DotEnv.Core).
**Note:** If you don't know what each class does, don't forget to check the [API documentation](xref:DotEnv.Core).

## Copying .env file to the output directory

If you want to copy the .env file to the output directory, you have to add the following to your .csproj file:
```xml
<ItemGroup>
<Content Include=".env">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
```
**NOTE:** Your .env file must be in the same directory as the .csproj file.

0 comments on commit 81cc216

Please sign in to comment.