-
Notifications
You must be signed in to change notification settings - Fork 0
/
Directory.Build.targets
247 lines (210 loc) · 10.5 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?xml version="1.0" encoding="utf-8"?>
<Project>
<Import Project="$(MSBuildThisFileDirectory)src\THNETII.RepositoryDefault.Dotnet.Build\build\THNETII.RepositoryDefault.Dotnet.Build.targets" />
<!-- <Import Project="$(MSBuildThisFileDirectory)src\THNETII.RepositoryDefault.Dotnet.Build.Git\build\THNETII.RepositoryDefault.Dotnet.Build.Git.targets" /> -->
<Import Project="$(MSBuildThisFileDirectory)src\THNETII.RepositoryDefault.Dotnet.Build.GitHub\build\THNETII.RepositoryDefault.Dotnet.Build.GitHub.targets" />
<Target Name="GetPackageIdWithVersion"
Outputs="@(PackageInformationItem)">
<ItemGroup>
<PackageInformationItem Include="$(PackageId)">
<Version>$(PackageVersion)</Version>
</PackageInformationItem>
</ItemGroup>
</Target>
<Target Name="StripTfmFromGeneratedNuspec"
Condition="'$(NuspecFile)'==''"
AfterTargets="Build"
DependsOnTargets="_CalculateInputsOutputsForPack"
Outputs="@(NuGetPackOutput->WithMetadataValue('Extension', '.nuspec'))">
<CallTarget Targets="GenerateNuspec" />
<ItemGroup>
<_GeneratedWithTfmNuspec Include="@(NuGetPackOutput->WithMetadataValue('Extension', '.nuspec'))" Condition="Exists('%(FullPath)')" />
<_IntermediateTfmAgnosticNuspec Include="@(_GeneratedWithTfmNuspec->'$(IntermediateOutputPath)%(Filename).int.nuspec')" />
</ItemGroup>
<PropertyGroup>
<_NuspecStripTargetFrameworkXsl>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd" >
<!--empty template suppresses match-->
<xsl:template match="/ns:package/ns:metadata/ns:dependencies/ns:group/@targetFramework" />
<!--identity template copies everything forward by default-->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
</_NuspecStripTargetFrameworkXsl>
</PropertyGroup>
<XslTransformation
XmlInputPaths="@(_GeneratedWithTfmNuspec)"
OutputPaths="@(_IntermediateTfmAgnosticNuspec)"
XslContent="$(_NuspecStripTargetFrameworkXsl)" />
<Move
SourceFiles="@(_IntermediateTfmAgnosticNuspec)"
DestinationFiles="@(_GeneratedWithTfmNuspec)">
<Output TaskParameter="MovedFiles" ItemName="_TfmAgnosticNuspec" />
</Move>
<ItemGroup>
<!-- Cleanup intermeditate items -->
<_IntermediateTfmAgnosticNuspec Remove="@(_IntermediateTfmAgnosticNuspec)" />
</ItemGroup>
</Target>
<Target Name="GetProjectReferencePackageInformation">
<MSBuild Projects="@(ProjectReference)"
Targets="GetPackageIdWithVersion"
SkipNonexistentTargets="true">
<Output TaskParameter="TargetOutputs" ItemName="_ProjectReferencePackageInformation" />
</MSBuild>
</Target>
<Target Name="AddProjectReferencePackageDependencyToNuspec"
Condition="'$(NuspecFile)'==''"
AfterTargets="StripTfmFromGeneratedNuspec"
DependsOnTargets="GetProjectReferencePackageInformation"
Inputs="@(_ProjectReferencePackageInformation)"
Outputs="@(_TfmAgnosticNuspec)">
<ItemGroup>
<_IntermediatePackageRefenceDepsNuspec Include="@(_TfmAgnosticNuspec->'$(IntermediateOutputPath)%(Filename).int.nuspec')" />
</ItemGroup>
<PropertyGroup>
<_ProjectReferenceAdditionalNuspecDependencies>
@(_ProjectReferencePackageInformation->'<ns:dependency id="%(Identity)" version="%(Version)" include="all" />', '')
</_ProjectReferenceAdditionalNuspecDependencies>
<_NuspecXmlNamspaceDeclarations>
<Namespace Prefix="ns" Uri="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd" />
</_NuspecXmlNamspaceDeclarations>
</PropertyGroup>
<XmlPeek XmlInputPath="@(_TfmAgnosticNuspec->'%(FullPath)')"
Namespaces="$(_NuspecXmlNamspaceDeclarations)"
Query="/ns:package/ns:metadata/ns:dependencies/ns:group/ns:dependency">
<Output TaskParameter="Result" ItemName="_NuspecExistingDependencyDeclarationXmlElement" />
</XmlPeek>
<PropertyGroup>
<_ProjectReferenceAddAdditionalNuspecDependenciesXsl Condition="'@(_NuspecExistingDependencyDeclarationXmlElement)' != ''">
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd" >
<!-- Identity transform -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/ns:package/ns:metadata/ns:dependencies/ns:group/ns:dependency[last()]">
<xsl:copy-of select="." />
$(_ProjectReferenceAdditionalNuspecDependencies)
</xsl:template>
</xsl:stylesheet>
</_ProjectReferenceAddAdditionalNuspecDependenciesXsl>
<_ProjectReferenceAddAdditionalNuspecDependenciesXsl Condition="'@(_NuspecExistingDependencyDeclarationXmlElement)' == ''">
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd" >
<!-- Identity transform -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/ns:package/ns:metadata/ns:dependencies/ns:group">
<ns:group>
$(_ProjectReferenceAdditionalNuspecDependencies)
</ns:group>
</xsl:template>
</xsl:stylesheet>
</_ProjectReferenceAddAdditionalNuspecDependenciesXsl>
</PropertyGroup>
<XslTransformation
XmlInputPaths="@(_TfmAgnosticNuspec)"
OutputPaths="@(_IntermediatePackageRefenceDepsNuspec)"
XslContent="$(_ProjectReferenceAddAdditionalNuspecDependenciesXsl)" />
<Move
SourceFiles="@(_IntermediatePackageRefenceDepsNuspec)"
DestinationFiles="@(_TfmAgnosticNuspec)" />
<ItemGroup>
<!-- Cleanup intermeditate items -->
<_IntermediatePackageRefenceDepsNuspec Remove="@(_IntermediatePackageRefenceDepsNuspec)" />
</ItemGroup>
</Target>
<Target Name="AddProjectBuildFilesToNuspec"
Condition="'$(NuspecFile)'==''"
AfterTargets="StripTfmFromGeneratedNuspec"
Outputs="@(_TfmAgnosticNuspec)">
<PropertyGroup>
<_ProjectBuildFilesAdditionalNuspecFileReferences>
<ns:file src="$(MSBuildProjectDirectory)\build\*.*" target="build" xmlns:ns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd" />
<ns:file src="$(MSBuildProjectDirectory)\buildMultiTargeting\*.*" target="buildMultiTargeting" xmlns:ns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd" />
<ns:file src="$(MSBuildProjectDirectory)\buildMultiTargeting\*.*" target="buildTransitive" xmlns:ns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd" />
</_ProjectBuildFilesAdditionalNuspecFileReferences>
<_NuspecXmlNamspaceDeclarations>
<Namespace Prefix="ns" Uri="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd" />
</_NuspecXmlNamspaceDeclarations>
</PropertyGroup>
<XmlPeek XmlInputPath="@(_TfmAgnosticNuspec->'%(FullPath)')"
Namespaces="$(_NuspecXmlNamspaceDeclarations)"
Query="/ns:package/ns:files/ns:file">
<Output TaskParameter="Result" ItemName="_NuspecExistingFileDeclarationXmlElement" />
</XmlPeek>
<ItemGroup>
<_IntermediateFileReferencesAddProjectBuildFilesNuspec Include="@(_TfmAgnosticNuspec->'$(IntermediateOutputPath)%(Filename).int.nuspec')" />
</ItemGroup>
<PropertyGroup>
<_FileReferencesAddProjectBuildFilesXsl Condition="'@(_NuspecExistingFileDeclarationXmlElement)' != ''">
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd" >
<!-- Identity transform -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/ns:package/ns:files/ns:file[last()]">
<xsl:copy-of select="." />
$(_ProjectBuildFilesAdditionalNuspecFileReferences)
</xsl:template>
</xsl:stylesheet>
</_FileReferencesAddProjectBuildFilesXsl>
<_FileReferencesAddProjectBuildFilesXsl Condition="'@(_NuspecExistingFileDeclarationXmlElement)' == ''">
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd" >
<!-- Identity transform -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/ns:package/node()[last()]">
<xsl:copy-of select="." />
<ns:files>
$(_ProjectBuildFilesAdditionalNuspecFileReferences)
</ns:files>
</xsl:template>
</xsl:stylesheet>
</_FileReferencesAddProjectBuildFilesXsl>
</PropertyGroup>
<XslTransformation
XmlInputPaths="@(_TfmAgnosticNuspec)"
OutputPaths="@(_IntermediateFileReferencesAddProjectBuildFilesNuspec)"
XslContent="$(_FileReferencesAddProjectBuildFilesXsl)" />
<Move
SourceFiles="@(_IntermediateFileReferencesAddProjectBuildFilesNuspec)"
DestinationFiles="@(_TfmAgnosticNuspec)" />
<ItemGroup>
<!-- Cleanup intermeditate items -->
<_IntermediateFileReferencesAddProjectBuildFilesNuspec Remove="@(_IntermediateFileReferencesAddProjectBuildFilesNuspec)" />
</ItemGroup>
</Target>
<Target Name="PackUsingFixedNuspec"
Condition="'$(NuspecFile)'==''"
DependsOnTargets="_CalculateInputsOutputsForPack;StripTfmFromGeneratedNuspec;AddProjectReferencePackageDependencyToNuspec;AddProjectBuildFilesToNuspec"
AfterTargets="Build"
Inputs="@(_TfmAgnosticNuspec)"
Outputs="@(NuGetPackOutput->WithMetadataValue('Extension', '.nupkg'))">
<MSBuild Projects="$(MSBuildProjectFullPath)"
Targets="Pack"
Properties="NuspecFile=%(_TfmAgnosticNuspec.FullPath);" />
</Target>
</Project>