-
Notifications
You must be signed in to change notification settings - Fork 163
/
Directory.Build.targets
131 lines (108 loc) · 6.53 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
121
122
123
124
125
126
127
128
129
130
131
<Project>
<!--
Steeltoe: This file was copied from the .NET Aspire Configuration Schema generator
at https://github.com/dotnet/aspire/tree/cb7cc4d78f8dd2b4df1053a229493cdbf88f50df/src/Tools/ConfigurationSchemaGenerator.
-->
<!--
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)src\Tools\src\package.targets"
PackagePath="buildTransitive\$(TargetFramework)\$(PackageId).targets" />
</ItemGroup>
</Target>
<!--
Logic for generating and comparing the ConfigurationSchema.json file
-->
<PropertyGroup Condition="'$(IsPackable)' == 'true'">
<TargetsTriggeredByCompilation Condition="'$(DesignTimeBuild)' != 'true'">$(TargetsTriggeredByCompilation);GenerateConfigurationSchema</TargetsTriggeredByCompilation>
<ConfigurationSchemaGeneratorProjectPath>$(MSBuildThisFileDirectory)src\Tools\src\ConfigurationSchemaGenerator\ConfigurationSchemaGenerator.csproj</ConfigurationSchemaGeneratorProjectPath>
<ConfigurationSchemaGeneratorRspPath>$(IntermediateOutputPath)$(AsemblyName).configschema.rsp</ConfigurationSchemaGeneratorRspPath>
<GeneratedConfigurationSchemaOutputPath>$(IntermediateOutputPath)ConfigurationSchema.json</GeneratedConfigurationSchemaOutputPath>
</PropertyGroup>
<ItemGroup Condition="'$(IsPackable)' == 'true'">
<!-- ensure the config generator is built -->
<ProjectReference Include="$(ConfigurationSchemaGeneratorProjectPath)"
Private="false"
ReferenceOutputAssembly="false" />
</ItemGroup>
<Target Name="GenerateConfigurationSchema"
DependsOnTargets="CoreGenerateConfigurationSchema;
CopyNewConfigurationSchema;
CompareConfigurationSchema" />
<!--
Steeltoe: Using ReferencePath instead of ReferencePathWithRefAssemblies in <ConfigSchemaReferences>,
because the ref subdirectory doesn't contain the assembly.xml file, which breaks inheritdoc usage in doc-comments.
-->
<Target Name="WriteConfigurationSchemaGeneratorRspFile">
<PropertyGroup>
<ConfigSchemaInput>"@(IntermediateAssembly)"</ConfigSchemaInput>
<ConfigSchemaReferences>"@(ReferencePath, '" "')"</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"
RemoveProperties="TargetFramework">
<Output TaskParameter="TargetOutputs" PropertyName="ConfigurationSchemaGeneratorPath" />
</MSBuild>
</Target>
<Target Name="CoreGenerateConfigurationSchema"
DependsOnTargets="WriteConfigurationSchemaGeneratorRspFile;
CalculateConfigurationSchemaGeneratorPath"
Inputs="$(ConfigurationSchemaGeneratorPath);
@(IntermediateAssembly);
@(ReferencePathWithRefAssemblies)"
Outputs="$(GeneratedConfigurationSchemaOutputPath)">
<PropertyGroup>
<GeneratorCommandLine>dotnet exec "$(ConfigurationSchemaGeneratorPath)"</GeneratorCommandLine>
<GeneratorCommandLine>$(GeneratorCommandLine) @"$(ConfigurationSchemaGeneratorRspPath)"</GeneratorCommandLine>
</PropertyGroup>
<Message Importance="High" Text="Running ConfigurationSchemaGenerator for project: $(MSBuildProjectName)" />
<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>
<Warning Condition="'$(CurrentConfigurationSchemaFileContent)' != '$(GeneratedConfigurationSchemaFileContent)' And '$(Configuration)' == 'Debug'"
Text="ConfigurationSchema.json in project $(MSBuildProjectName) is out of date. Run 'dotnet build --no-incremental /p:UpdateConfigurationSchema=true' to update it." />
<Error Condition="'$(CurrentConfigurationSchemaFileContent)' != '$(GeneratedConfigurationSchemaFileContent)' And '$(Configuration)' != 'Debug'"
Text="ConfigurationSchema.json in project $(MSBuildProjectName) is out of date. Run 'dotnet build --no-incremental /p:UpdateConfigurationSchema=true' to update it." />
</Target>
</Project>