forked from dotnet/aspire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirectory.Build.targets
120 lines (97 loc) · 5.6 KB
/
Directory.Build.targets
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />
<!--
Logic for including the ConfigurationSchema.json file and corresponding
PackageId.targets file which brings the ConfigurationSchema.json file into the Json Schema.
-->
<PropertyGroup>
<ConfigurationSchemaPath>$(MSBuildProjectDirectory)\ConfigurationSchema.json</ConfigurationSchemaPath>
<ConfigurationSchemaExists Condition="Exists('$(ConfigurationSchemaPath)')">true</ConfigurationSchemaExists>
</PropertyGroup>
<ItemGroup Condition="'$(ConfigurationSchemaExists)' == 'true'">
<None Include="$(ConfigurationSchemaPath)"
Pack="True"
PackagePath="ConfigurationSchema.json" />
</ItemGroup>
<PropertyGroup Condition="'$(ConfigurationSchemaExists)' == 'true'">
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);AddPackageTargetsInPackage</TargetsForTfmSpecificContentInPackage>
</PropertyGroup>
<Target Name="AddPackageTargetsInPackage">
<ItemGroup>
<TfmSpecificPackageFile Include="$(MSBuildThisFileDirectory)Common\Package.targets"
PackagePath="buildTransitive\$(TargetFramework)\$(PackageId).targets" />
</ItemGroup>
</Target>
<!--
Logic for generating and comparing the ConfigurationSchema.json file
-->
<PropertyGroup>
<TargetsTriggeredByCompilation Condition="'$(DesignTimeBuild)' != 'true'">$(TargetsTriggeredByCompilation);GenerateConfigurationSchema</TargetsTriggeredByCompilation>
<ConfigurationSchemaGeneratorProjectPath>$(RepoRoot)src\Tools\ConfigurationSchemaGenerator\ConfigurationSchemaGenerator.csproj</ConfigurationSchemaGeneratorProjectPath>
<ConfigurationSchemaGeneratorRspPath>$(IntermediateOutputPath)$(AsemblyName).configschema.rsp</ConfigurationSchemaGeneratorRspPath>
<GeneratedConfigurationSchemaOutputPath>$(IntermediateOutputPath)ConfigurationSchema.json</GeneratedConfigurationSchemaOutputPath>
</PropertyGroup>
<ItemGroup>
<!-- ensure the config generator is built -->
<ProjectReference Include="$(ConfigurationSchemaGeneratorProjectPath)"
Private="false"
ReferenceOutputAssembly="false" />
</ItemGroup>
<Target Name="GenerateConfigurationSchema"
DependsOnTargets="CoreGenerateConfigurationSchema;
CopyNewConfigurationSchema;
CompareConfigurationSchema" />
<Target Name="WriteConfigurationSchemaGeneratorRspFile">
<PropertyGroup>
<ConfigSchemaInput>"@(IntermediateAssembly)"</ConfigSchemaInput>
<ConfigSchemaReferences>"@(ReferencePathWithRefAssemblies, '" "')"</ConfigSchemaReferences>
<ConfigSchemaOutput>"$(GeneratedConfigurationSchemaOutputPath)"</ConfigSchemaOutput>
</PropertyGroup>
<ItemGroup>
<ConfigSchemaGenArg Include="--input $(ConfigSchemaInput)" />
<ConfigSchemaGenArg Include="--reference $(ConfigSchemaReferences)" />
<ConfigSchemaGenArg Include="--output $(ConfigSchemaOutput)" />
</ItemGroup>
<WriteLinesToFile File="$(ConfigurationSchemaGeneratorRspPath)"
Lines="@(ConfigSchemaGenArg)"
Overwrite="true"
WriteOnlyWhenDifferent="true" />
</Target>
<Target Name="CalculateConfigurationSchemaGeneratorPath">
<MSBuild Projects="$(ConfigurationSchemaGeneratorProjectPath)"
Targets="GetTargetPath">
<Output TaskParameter="TargetOutputs" PropertyName="ConfigurationSchemaGeneratorPath" />
</MSBuild>
</Target>
<Target Name="CoreGenerateConfigurationSchema"
DependsOnTargets="WriteConfigurationSchemaGeneratorRspFile;
CalculateConfigurationSchemaGeneratorPath"
Inputs="$(ConfigurationSchemaGeneratorPath);
@(IntermediateAssembly);
@(ReferencePathWithRefAssemblies)"
Outputs="$(GeneratedConfigurationSchemaOutputPath)">
<PropertyGroup>
<GeneratorCommandLine>"$(DotNetTool)" exec $(ConfigurationSchemaGeneratorPath)</GeneratorCommandLine>
<GeneratorCommandLine>$(GeneratorCommandLine) @$(ConfigurationSchemaGeneratorRspPath)</GeneratorCommandLine>
</PropertyGroup>
<Exec Command="$(GeneratorCommandLine)" />
<ItemGroup>
<FileWrites Include="$(GeneratedConfigurationSchemaOutputPath)" Condition="Exists('$(GeneratedConfigurationSchemaOutputPath)')"/>
</ItemGroup>
</Target>
<Target Name="CopyNewConfigurationSchema"
Condition="('$(ConfigurationSchemaExists)' != 'true' OR '$(UpdateConfigurationSchema)' == 'true')
AND Exists('$(GeneratedConfigurationSchemaOutputPath)')">
<Copy SourceFiles="$(GeneratedConfigurationSchemaOutputPath)"
DestinationFiles="$(ConfigurationSchemaPath)" />
</Target>
<Target Name="CompareConfigurationSchema"
Condition="Exists('$(ConfigurationSchemaPath)') AND Exists('$(GeneratedConfigurationSchemaOutputPath)')">
<PropertyGroup>
<CurrentConfigurationSchemaFileContent>$([System.IO.File]::ReadAllText('$(ConfigurationSchemaPath)'))</CurrentConfigurationSchemaFileContent>
<GeneratedConfigurationSchemaFileContent>$([System.IO.File]::ReadAllText('$(GeneratedConfigurationSchemaOutputPath)'))</GeneratedConfigurationSchemaFileContent>
</PropertyGroup>
<Error Condition="'$(CurrentConfigurationSchemaFileContent)' != '$(GeneratedConfigurationSchemaFileContent)'"
Text="ConfigurationSchema.json is out of date for $(MSBuildProjectFile). Run 'dotnet build --no-incremental /p:UpdateConfigurationSchema=true' to update it." />
</Target>
</Project>