Skip to content

Commit

Permalink
Created .props file to copy .env files to the publish directory (#138)
Browse files Browse the repository at this point in the history
* Added `DotEnv.Core.Props` package to the example project
  • Loading branch information
MrDave1999 authored Jun 30, 2023
1 parent 3bd9806 commit dec1114
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 1 deletion.
6 changes: 5 additions & 1 deletion example/DotEnv.Core.Example.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -11,4 +11,8 @@
<ProjectReference Include="..\src\DotEnv.Core.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="DotEnv.Core.Props" Version="1.0.1" />
</ItemGroup>

</Project>
29 changes: 29 additions & 0 deletions props/DotEnv.Core.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>DotEnv.Core.Props</id>
<version>1.0.1</version>
<authors>David Román Amariles</authors>
<owners>David Román Amariles</owners>
<projectUrl>https://github.com/MrDave1999/dotenv.core</projectUrl>
<license type="expression">MIT</license>
<readme>README.md</readme>
<icon>dotenv-icon-nuget.png</icon>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>
dotenv.core.props is a file that represents a set of properties that will tell MSBuild to copy the .env files
from the project folder to the publish directory.
</description>
<releaseNotes>
- fix: Added .props extension to the build/DotEnv.Core.Props file.
</releaseNotes>
<copyright>Copyright ©2023 David Román Amariles</copyright>
<tags>properties props dotenv env environment variables</tags>
</metadata>

<files>
<file src="README.md" target="" />
<file src="..\dotenv-icon-nuget.png" target="" />
<file src="build\**" target="build" />
</files>
</package>
26 changes: 26 additions & 0 deletions props/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
**DotEnv.Core.Props** is a file that represents a set of properties that will tell MSBuild to copy the .env files from the project folder to the publish directory.

This .props file **excludes** the following sample .env files:
- `.env.example`
- `example.env`
- `.env.sample`
- `sample.env`
- `.env.template`
- `template.env`

## Installation

Run the following command from the terminal:
```
dotnet add package DotEnv.Core.Props
```

## How to use it?

The .props file does not need to be used directly, simply run the `dotnet publish` command and MSBuild will copy the .env files to the publish directory.

Remember that .env files must follow either of these two conventions:
- `.env.{name}` (e.g., .env.config).
- `{name}.env` (e.g., config.env).

Following these conventions is necessary for MSBuild to know which file to copy to the publish directory.
31 changes: 31 additions & 0 deletions props/build/DotEnv.Core.Props.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project>

<PropertyGroup>
<!--
Redefine the DefaultItemExcludes property to exclude the folders as ./bin, ./obj and .env files of samples.
This also excludes sample .env files that are located in subdirectories of the project folder.
-->
<DefaultItemExcludes>
$(DefaultItemExcludes);
**\.env.example;
**\example.env;
**\.env.sample;
**\sample.env;
**\.env.template;
**\template.env
</DefaultItemExcludes>
</PropertyGroup>

<ItemGroup>
<!--
Copy all the .env files to the publish directory (except for sample files). It will also copy .env files that are in subdirectories.
The publish directory contains the assemblies ready for deployment to a hosting system (for example, a server, PC, laptop) for execution.
-->
<Content
Include="**\*.env*"
CopyToPublishDirectory="PreserveNewest"
Exclude="$(DefaultItemExcludes)"
/>
</ItemGroup>

</Project>

0 comments on commit dec1114

Please sign in to comment.