-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathNuGetizer.Inference.targets
348 lines (314 loc) · 18.3 KB
/
NuGetizer.Inference.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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<!--
***********************************************************************************************
NuGetizer.Inference.targets
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.
Copyright (c) .NET Foundation. All rights reserved.
***********************************************************************************************
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="NuGetizer.Tasks.InferImplicitPackageReference" AssemblyFile="NuGetizer.Tasks.dll" />
<PropertyGroup>
<!-- The PackFolder of primary output (build, symbols, doc and satellite assemblies) set if PackBuildOutput = true -->
<PackFolder Condition="'$(PackFolder)' == ''">lib</PackFolder>
<!-- Whether to include @(Content) items with CopyToOutputDirectory != '' in the package -->
<PackContent Condition="'$(PackContent)' == ''">true</PackContent>
<!-- Whether to include @(BuiltProjectOutputGroupOutput), @(DocumentationProjectOutputGroupOutput) and @(SatelliteDllsProjectOutputGroupOutput) items in the package -->
<PackBuildOutput Condition="'$(PackBuildOutput)' == '' and '$(IsPackagingProject)' != 'true'">true</PackBuildOutput>
<!-- Whether to include @(DebugSymbolsProjectOutputGroupOutput) items in the package -->
<PackSymbols Condition="'$(PackSymbols)' == '' and '$(PackBuildOutput)' == 'true'">true</PackSymbols>
<!-- Whether to include framework references (%(ReferencePath.ResolvedFrom)' == '{TargetFrameworkDirectory}') in the package -->
<!-- Only default to true if the project isn't a nuget packaging project itself and its primary output is lib. -->
<PackFrameworkReferences Condition="'$(PackFrameworkReferences)' == '' and '$(IsPackagingProject)' != 'true' and '$(PackFolder)' == 'lib'">true</PackFrameworkReferences>
<_OutputFullPath Condition="$([System.IO.Path]::IsPathRooted($(OutputPath)))">$(OutputPath)</_OutputFullPath>
<_OutputFullPath Condition="'$(_OutputFullPath)' == ''">$(MSBuildProjectDirectory.TrimEnd('\'))\$(OutputPath)</_OutputFullPath>
</PropertyGroup>
<ItemDefinitionGroup Label="Inference Defaults">
<Compile>
<!-- For Compile, the CodeLanguage should default to the project's default source extension -->
<CodeLanguage>$(DefaultLanguageSourceExtension.TrimStart('.'))</CodeLanguage>
<DefaultPackFolder>content</DefaultPackFolder>
<Pack Condition="'$(PackCompile)' == 'true'">true</Pack>
<BuildAction>Compile</BuildAction>
</Compile>
<Content>
<DefaultPackFolder>content</DefaultPackFolder>
<Pack Condition="'$(PackContent)' == true">true</Pack>
<BuildAction>Content</BuildAction>
</Content>
<EmbeddedResource>
<DefaultPackFolder>content</DefaultPackFolder>
<Pack Condition="'$(PackEmbeddedResource)' == true">true</Pack>
<BuildAction>EmbeddedResource</BuildAction>
</EmbeddedResource>
<None>
<DefaultPackFolder>none</DefaultPackFolder>
<Pack Condition="'$(PackNone)' == true">true</Pack>
<BuildAction>None</BuildAction>
</None>
<ApplicationDefinition>
<DefaultPackFolder>content</DefaultPackFolder>
<Pack Condition="'$(PackApplicationDefinition)' == true">true</Pack>
<BuildAction>ApplicationDefinition</BuildAction>
</ApplicationDefinition>
<Page>
<DefaultPackFolder>content</DefaultPackFolder>
<Pack Condition="'$(PackPage)' == true">true</Pack>
<BuildAction>Page</BuildAction>
</Page>
<Resource>
<DefaultPackFolder>content</DefaultPackFolder>
<Pack Condition="'$(PackResource)' == true">true</Pack>
<BuildAction>Resource</BuildAction>
</Resource>
<SplashScreen>
<DefaultPackFolder>content</DefaultPackFolder>
<Pack Condition="'$(PackSplashScreen)' == true">true</Pack>
<BuildAction>SplashScreen</BuildAction>
</SplashScreen>
<DesignData>
<DefaultPackFolder>content</DefaultPackFolder>
<Pack Condition="'$(PackDesignData)' == true">true</Pack>
<BuildAction>DesignData</BuildAction>
</DesignData>
<DesignDataWithDesignTimeCreatableTypes>
<DefaultPackFolder>content</DefaultPackFolder>
<Pack Condition="'$(PackDesignDataWithDesignTimeCreatableTypes)' == true">true</Pack>
<BuildAction>DesignDataWithDesignTimeCreatableTypes</BuildAction>
</DesignDataWithDesignTimeCreatableTypes>
<CodeAnalysisDictionary>
<DefaultPackFolder>content</DefaultPackFolder>
<Pack Condition="'$(PackCodeAnalysisDictionary)' == true">true</Pack>
<BuildAction>CodeAnalysisDictionary</BuildAction>
</CodeAnalysisDictionary>
<AndroidAsset>
<DefaultPackFolder>content</DefaultPackFolder>
<Pack Condition="'$(PackAndroidAsset)' == true">true</Pack>
<BuildAction>AndroidAsset</BuildAction>
</AndroidAsset>
<AndroidResource>
<DefaultPackFolder>content</DefaultPackFolder>
<Pack Condition="'$(PackAndroidResource)' == true">true</Pack>
<BuildAction>AndroidResource</BuildAction>
</AndroidResource>
<BundleResource>
<DefaultPackFolder>content</DefaultPackFolder>
<Pack Condition="'$(PackBundleResource)' == true">true</Pack>
<BuildAction>BundleResource</BuildAction>
</BundleResource>
<InferenceCandidate>
<DefaultPackFolder />
<Pack />
<PackagePath />
<PackFolder />
<ShouldPack />
</InferenceCandidate>
</ItemDefinitionGroup>
<!-- Extend some built-in items with metadata we use in our inference targets -->
<ItemDefinitionGroup>
<PackageReference>
<Pack />
</PackageReference>
<ReferencePath>
<Facade>false</Facade>
<FrameworkFile>false</FrameworkFile>
<NuGetPackageId />
<Pack />
</ReferencePath>
<_ReferenceRelatedPaths>
<Facade>false</Facade>
<FrameworkFile>false</FrameworkFile>
<NuGetPackageId />
<Pack />
</_ReferenceRelatedPaths>
</ItemDefinitionGroup>
<PropertyGroup>
<GetPackageContentsDependsOn>
$(GetPackageContentsDependsOn);
_SetBuildOutputFrameworkSpecific;
_SetDefaultPackageReferencePack;
InferPackageContents
</GetPackageContentsDependsOn>
</PropertyGroup>
<Target Name="_SetBuildOutputFrameworkSpecific" Condition="'$(BuildOutputFrameworkSpecific)' == ''" Returns="$(BuildOutputFrameworkSpecific)">
<!-- Determine whether primary output is framework specific -->
<ItemGroup>
<_BuildOutputFrameworkSpecific Include="@(PackFolderKind -> '%(FrameworkSpecific)')" Condition="'%(Identity)' == '$(PackFolder)'" />
</ItemGroup>
<PropertyGroup>
<BuildOutputFrameworkSpecific>@(_BuildOutputFrameworkSpecific)</BuildOutputFrameworkSpecific>
</PropertyGroup>
</Target>
<Target Name="_SetDefaultPackageReferencePack" Condition="'$(PackFolder)' == 'build'"
BeforeTargets="InferPrimaryOutputDependencies;InferPackageContents">
<ItemGroup>
<PackageReference Update="@(PackageReference)"
Condition="$([MSBuild]::ValueOrDefault('%(Identity)', '').StartsWith('Microsoft.Build')) and '%(Pack)' != 'true'"
Pack="false" />
</ItemGroup>
</Target>
<ItemGroup>
<PackInference Include="Compile;Content;EmbeddedResource;None;ApplicationDefinition;Page;
Resource;SplashScreen;DesignData;DesignDataWithDesignTimeCreatableTypes;
CodeAnalysisDictionary;AndroidAsset;AndroidResource;BundleResource" />
</ItemGroup>
<Target Name="InferPackageContents" DependsOnTargets="$(InferPackageContentsDependsOn)" Returns="@(PackageFile)">
<ItemGroup>
<InferenceCandidate Include="@(%(PackInference.Identity))" />
<InferenceCandidate>
<ShouldPack Condition="('%(Pack)' == 'true' or '%(PackagePath)' != '' or '%(PackFolder)' != '') and '%(Pack)' != 'false'">true</ShouldPack>
</InferenceCandidate>
</ItemGroup>
<AssignTargetPath Files="@(InferenceCandidate)" RootFolder="$(MSBuildProjectDirectory)"
Condition="'%(ShouldPack)' == 'true'">
<Output TaskParameter="AssignedFiles" ItemName="_InferenceCandidateWithTargetPath" />
</AssignTargetPath>
<ItemGroup Label="PackInference">
<_InferenceCandidateWithTargetPath Condition="'%(PackFolder)' == ''">
<!-- Items that are copied to the output directory adopt the kind of the build output -->
<PackFolder Condition="'%(_InferenceCandidateWithTargetPath.CopyToOutputDirectory)' != '' or
'%(_InferenceCandidateWithTargetPath.CopyToOutputDirectory)' != 'Never'">$(PackFolder)</PackFolder>
<!-- Otherwise they cake on whichever is the default for their item type, as defined by their PackInference item -->
<PackFolder Condition="'%(_InferenceCandidateWithTargetPath.CopyToOutputDirectory)' == '' or
'%(_InferenceCandidateWithTargetPath.CopyToOutputDirectory)' == 'Never'">%(_InferenceCandidateWithTargetPath.DefaultPackFolder)</PackFolder>
</_InferenceCandidateWithTargetPath>
<!-- Items that are copied to the output directory are included from the target path -->
<_InferredPackageFile Include="@(_InferenceCandidateWithTargetPath -> '$(_OutputFullPath)\%(TargetPath)')"
Condition="'%(_InferenceCandidateWithTargetPath.CopyToOutputDirectory)' != '' and
'%(_InferenceCandidateWithTargetPath.CopyToOutputDirectory)' != 'Never'" />
<!-- Otherwise, they are included from the source location -->
<_InferredPackageFile Include="@(_InferenceCandidateWithTargetPath->'%(FullPath)')"
Condition="'%(_InferenceCandidateWithTargetPath.CopyToOutputDirectory)' == '' or
'%(_InferenceCandidateWithTargetPath.CopyToOutputDirectory)' == 'Never'" />
</ItemGroup>
<ItemGroup Label="BuildOutput Inference" Condition="'$(PackBuildOutput)' == 'true'">
<!-- Unfortunately, even with https://github.com/Microsoft/msbuild/pull/1115, when multi-targeting
.NETFramework, the desktop WinFX.targets are imported which don't have the fix, so we need to
do it "the old way" for this particular output group -->
<_SatelliteDllsProjectOutputGroupOutput Include="@(SatelliteDllsProjectOutputGroupOutput)"
FinalOutputPath="'%(FullPath)')" />
<_InferredProjectOutput Include="@(BuiltProjectOutputGroupOutput -> '%(FinalOutputPath)');
@(BuiltProjectOutputGroupKeyOutput -> '%(FinalOutputPath)');
@(DocumentationProjectOutputGroupOutput -> '%(FinalOutputPath)');
@(_SatelliteDllsProjectOutputGroupOutput -> '%(FinalOutputPath)')">
<PackFolder>$(PackFolder)</PackFolder>
<FrameworkSpecific>$(BuildOutputFrameworkSpecific)</FrameworkSpecific>
</_InferredProjectOutput>
<_InferredProjectOutput Include="@(DebugSymbolsProjectOutputGroupOutput -> '%(FinalOutputPath)')"
Condition="'$(PackSymbols)' != 'false'">
<PackFolder>$(PackFolder)</PackFolder>
<FrameworkSpecific>$(BuildOutputFrameworkSpecific)</FrameworkSpecific>
</_InferredProjectOutput>
<_InferredPackageFile Include="@(_InferredProjectOutput -> Distinct())" />
</ItemGroup>
<ItemGroup Label="References Inference">
<_InferredPackageFile Include="@(PackageReference)"
Condition="'%(PackageReference.Identity)' != 'NuGetizer' and
'%(PackageReference.Identity)' != 'NETStandard.Library' and
'%(PackageReference.PrivateAssets)' != 'all' and
'%(PackageReference.Pack)' != 'false'">
<PackFolder>Dependency</PackFolder>
</_InferredPackageFile>
<!-- We can't use %(FrameworkFile)==true because it's not defined for raw file references and
it also includes mscorlib which we don't need
TBD: maybe include ResolvedFrom=ImplicitlyExpandDesignTimeFacades too? -->
<_InferredPackageFile Include="@(ReferencePath->'%(OriginalItemSpec)')"
Condition="'$(PackFrameworkReferences)' == 'true' and
'%(ReferencePath.ResolvedFrom)' == '{TargetFrameworkDirectory}' and
'%(ReferencePath.Pack)' != 'false'">
<PackFolder>FrameworkReference</PackFolder>
</_InferredPackageFile>
</ItemGroup>
<ItemGroup>
<!--
PackageId metadata on all PackageFile items means we can tell appart which ones came from which dependencies
NOTE: if PackageId is empty, we won't generate a manifest and it means the files need to be packed with the
current project.
-->
<PackageFile Include="@(_InferredPackageFile)">
<Source>Implicit</Source>
<PackageId Condition="'$(IsPackable)' == 'true'">$(PackageId)</PackageId>
<Platform>$(Platform)</Platform>
<TargetFrameworkMoniker Condition="'$(IsPackagingProject)' != 'true'">$(TargetFrameworkMoniker)</TargetFrameworkMoniker>
</PackageFile>
</ItemGroup>
</Target>
<Target Name="_CollectPrimaryOutputDependencies" DependsOnTargets="BuildOnlySettings;ResolveReferences" Returns="@(ImplicitPackageReference)">
<ItemGroup>
<_PrimaryOutputRelatedFile Include="@(ReferencePath);@(_ReferenceRelatedPaths)"
Condition="'%(NuGetPackageId)' != 'NETStandard.Library' and
'%(Facade)' != 'true' and
'%(FrameworkFile)' != 'true' and
'%(Pack)' != 'false'"/>
<_PrivateAssetsPackageReference Include="@(PackageReference -> WithMetadataValue('PrivateAssets', 'all'))"
Condition="'%(PackageReference.IsImplicitlyDefined)' != 'true' and '%(PackageReference.Pack)' != 'false'"/>
</ItemGroup>
<InferImplicitPackageReference Condition="'@(_PrivateAssetsPackageReference)' != '' and '@(PackageDependencies)' != ''"
PackageReferences="@(_PrivateAssetsPackageReference)"
PackageDependencies="@(PackageDependencies)">
<Output TaskParameter="ImplicitPackageReferences" ItemName="ImplicitPackageReference" />
</InferImplicitPackageReference>
</Target>
<Target Name="_ResolvePackageDependencies" Condition="'$(UsingMicrosoftNETSdk)' == 'true'" DependsOnTargets="RunResolvePackageDependencies" />
<Target Name="InferPrimaryOutputDependencies"
Inputs="@(_PrimaryOutputRelatedFile)"
Outputs="%(_PrimaryOutputRelatedFile.NuGetPackageId)"
Returns="@(_InferredPackageFile)"
DependsOnTargets="_ResolvePackageDependencies;_CollectPrimaryOutputDependencies">
<ItemGroup>
<_NuGetPackageId Include="@(_PrimaryOutputRelatedFile -> '%(NuGetPackageId)')" Condition="'%(NuGetPackageId)' != 'NETStandard.Library'" />
</ItemGroup>
<PropertyGroup>
<_NuGetPackageId>@(_NuGetPackageId -> Distinct())</_NuGetPackageId>
</PropertyGroup>
<ItemGroup>
<_PrimaryPackageReference Include="@(PackageReference);@(ImplicitPackageReference)" Condition="'$(_NuGetPackageId)' != '' and '%(Identity)' == '$(_NuGetPackageId)'" />
</ItemGroup>
<PropertyGroup>
<_PrivateAssets>@(_PrimaryPackageReference -> '%(PrivateAssets)')</_PrivateAssets>
<_ShouldPack>@(_PrimaryPackageReference -> '%(Pack)')</_ShouldPack>
<_ShouldIncludeAssetsRegex>$(_NuGetPackageId)\\.+\\$(_PrivateAssets)\\.*</_ShouldIncludeAssetsRegex>
</PropertyGroup>
<ItemGroup Condition="'$(_ShouldPack)' != 'false' and '$(_PrivateAssets)' == 'all'">
<_InferredPackageFile Include="@(_PrimaryOutputRelatedFile)" Condition="'%(_PrimaryOutputRelatedFile.FrameworkFile)' != 'true'">
<PackFolder>$(PackFolder)</PackFolder>
<FrameworkSpecific>$(BuildOutputFrameworkSpecific)</FrameworkSpecific>
</_InferredPackageFile>
</ItemGroup>
<ItemGroup Condition="'$(_ShouldPack)' != 'false' and '$(_PrivateAssets)' != 'all' and '$(_PrivateAssets)' != 'none' and '$(_PrivateAssets)' != ''">
<!-- In this case, we only add files that have a matching path to the private assets value.
i.e. for Mono.Options, PrivateAssets=lib, we'll include the file if its full path contains
'Mono.Options\*\lib\*', meaning the file is a lib. -->
<_InferredPackageFile Include="@(_PrimaryOutputRelatedFile)"
Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('%(_PrimaryOutputRelatedFile.FullPath)', '$(_ShouldIncludeAssetsRegex)', 'RegexOptions.IgnoreCase')) == 'true'">
<PackFolder>$(PackFolder)</PackFolder>
<FrameworkSpecific>$(BuildOutputFrameworkSpecific)</FrameworkSpecific>
</_InferredPackageFile>
</ItemGroup>
</Target>
<Target Name="_SetInferPackageContentsDependsOn" AfterTargets="_SetPropertiesFromCapabilities">
<PropertyGroup>
<!-- NOTE: this avoids taking dependencies on targets that are only available when the project supports the concept of references -->
<_SupportsReferences Condition="
$(_AllProjectCapabilities.Contains('AssemblyReferences')) or
$(_AllProjectCapabilities.Contains('COMReferences')) or
$(_AllProjectCapabilities.Contains('ProjectReferences')) or
$(_AllProjectCapabilities.Contains('PackageReferences')) or
$(_AllProjectCapabilities.Contains('WinRTReferences')) or
$(_AllProjectCapabilities.Contains('SDKReferences'))">true</_SupportsReferences>
<InferPackageContentsDependsOn Condition="'$(_SupportsReferences)' == 'true'">
ResolveReferences;
InferPrimaryOutputDependencies
</InferPackageContentsDependsOn>
<InferPackageContentsDependsOn>
$(InferPackageContentsDependsOn);
GetPackageTargetPath
</InferPackageContentsDependsOn>
<InferPackageContentsDependsOn Condition="$(_AllProjectCapabilities.Contains('AllTargetOutputGroups'))">
$(InferPackageContentsDependsOn);
AllProjectOutputGroups
</InferPackageContentsDependsOn>
</PropertyGroup>
</Target>
</Project>