-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDirectory.Build.targets
More file actions
53 lines (49 loc) · 2.23 KB
/
Copy pathDirectory.Build.targets
File metadata and controls
53 lines (49 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<Project>
<!--
Auto-generate missing .env files from committed .env.template defaults.
Runs before build so CopyToOutputDirectory can pick them up.
Templates are NOT gitignored (*.env patterns don't match *.env.template).
-->
<Target Name="_EnsureEnvironmentFiles" BeforeTargets="BeforeBuild"
Condition="Exists('Environment')">
<ItemGroup>
<_EnvTemplate Include="Environment\*.env.template" />
<_MissingEnvFile Include="@(_EnvTemplate)" Condition="!Exists('%(RootDir)%(Directory)%(Filename)')" />
</ItemGroup>
<Copy SourceFiles="@(_MissingEnvFile)"
DestinationFiles="@(_MissingEnvFile->'%(RootDir)%(Directory)%(Filename)')"
Condition="'@(_MissingEnvFile)' != ''" />
<Message Importance="high"
Text="Created missing %(Filename) from template"
Condition="'@(_MissingEnvFile)' != ''" />
</Target>
<!--
Dynamically register .env files as Content items AFTER _EnsureEnvironmentFiles
has generated them from templates. Runs before AssignTargetPaths (current project's
content pipeline) and GetCopyToOutputDirectoryItems (what referencing projects call),
so the files propagate transitively through ProjectReference.
CopyToOutputDirectory="Always" ensures source edits always reach the output.
-->
<Target Name="_RegisterEnvironmentContent"
BeforeTargets="AssignTargetPaths;GetCopyToOutputDirectoryItems"
DependsOnTargets="_EnsureEnvironmentFiles"
Condition="Exists('Environment')">
<ItemGroup>
<Content Include="Environment\*.env;Environment\*.env.template"
CopyToOutputDirectory="Always" />
</ItemGroup>
</Target>
<!--
Delete copied .env files from the output directory during Clean.
-->
<Target Name="_CleanEnvironmentFiles" AfterTargets="Clean"
Condition="Exists('Environment')">
<ItemGroup>
<_OutputEnvFile Include="$(OutputPath)Environment\*.env" Exclude="$(OutputPath)Environment\*.template" />
</ItemGroup>
<Delete Files="@(_OutputEnvFile)" Condition="'@(_OutputEnvFile)' != ''" />
<Message Importance="high"
Text="Deleted .env files from output directory"
Condition="'@(_OutputEnvFile)' != ''" />
</Target>
</Project>