-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathPackaging.targets
484 lines (416 loc) · 26.1 KB
/
Packaging.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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
<Project InitialTargets="EnsureCreateContentFolderRunsBeforeNuspecDependsOn">
<!-- Dummy 'Pack' target for 'vcxproj' -->
<Target Name="Pack" Condition="'$(MSBuildProjectExtension)'=='.vcxproj'" />
<PropertyGroup>
<!-- Projects can override the name of the 'lib' folder to something else - for e.g., 'tools'-->
<LibFolder Condition="'$(LibFolder)'==''">lib</LibFolder>
<!--
Architecture-specific assemblies go under runtimes\<rid>\native\
https://docs.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks
-->
</PropertyGroup>
<PropertyGroup>
<PackageName Condition="'$(CreateArchNeutralPackage)'!='true' And '$(PackageName)'!=''">$(PackageRuntimeIdentifierPrefix).$(PackageName)</PackageName>
<NormalizedPackageName>$(PackageName.Replace('$(PackageRuntimeIdentifierPrefix).',''))</NormalizedPackageName>
<NuspecPackageId>$(PackageName)</NuspecPackageId>
<DevelopmentDependency Condition="'$(MsBuildSdkPackage)'=='true'">true</DevelopmentDependency>
<PackageType Condition="'$(MsBuildSdkPackage)'=='true'">MSBuildSdk</PackageType>
</PropertyGroup>
<!--
Target: PreparePackageAssets
Copies packages assets for a project to artifacts\packaging\$(Configuration)\$(PackageName)\
and prepares it for packaging then Target=Pack is executed
Important properties and items:
$(PackageName): Name of the package
This target will only run for projects that specify $(PackageName)
@(PackagingContent): Additional content specified by projects
Place under content\ in the package by default
Placement in package can be altered by specifying a SubFolder attribute
<PackagingContent Include="foo.xml" SubFolder="xmls" /> would result in
foo.xml being packaged under content\xmls
'root' is a special prefix-value for the attribute SubFolder, and it will result
in the placement of the file in the root of the package.
- <PackagingContent Include="THIRD-PARTY-NOTICES.TXT" SubFolder="root"/>
will result in "THIRD-PARTY-NOTICES.TXT" to be placed at the root
of the package.
<PackagingContent Include"sdk\*.props" Subfolder="root\sdk" /> will result in
relevant *.props files to be placed under the 'sdk' sub-folder in the package.
@(PackagingAssemblyContent) -
A way to specify which files under $(OutDir) should be packaged.
If this list is set, then we will only carry assemblies specified in this set
an no others.
$(ExcludeRefAssemblies) - true/false to include/exclude ref assemblies from packaging.
default is true.
$(ExcludePdbs) - true/false to include/exclude PDB's from packaging
default is true
$(PreparePackageAssetsDependsOn):
List of targets that PreparePackageAssets would depend on
This is an extensibility point
Packaging projects ($(IsPackagingProject) == true) also have $(PackageName) - do not attempt
to prepare DLL, EXE, PDB etc. assets for those projects. Only prepare content (PackageAsset)
assets for packaging projects
-->
<Target Name="PreparePackageAssets"
AfterTargets="Build"
DependsOnTargets="$(PreparePackageAssetsDependsOn);IdentifyPackageAssets;CopyPackageAssets"
Condition="'$(PackageName)'!=''" />
<Target Name="CopyPackageAssets"
Inputs="@(PackageAsset)"
Outputs="@(PackageAsset->'%(RelativePath)\%(Filename)%(Extension)')"
Condition="'$(PackageName)'!=''">
<MakeDir Condition="!Exists('%(PackageAsset.RelativePath')" Directories="@(PackageAsset->'%(RelativePath)')" />
<Copy Condition="(@(PackageAsset->Count()) > 0)"
SourceFiles="@(PackageAsset)"
DestinationFolder="%(PackageAsset.RelativePath)"
SkipUnchangedFiles="true"/>
</Target>
<Target Name="IdentifyPackageAssets"
Returns="@(PackageAsset)"
Condition="'$(PackageName)'!=''">
<PropertyGroup>
<DestinationSubFolder Condition="'$(DestinationSubFolder)'=='' and '$(TargetFramework)'!='' and !('$(MSBuildProjectExtension)'=='.vcxproj' and '$(UseDestinationLibFolder)' == '')">$(LibFolder)\$(TargetFramework)\</DestinationSubFolder>
</PropertyGroup>
<PropertyGroup Condition="'$(MSBuildProjectExtension)'=='.vcxproj' and '$(DestinationSubFolder)'==''">
<DestinationSubFolder Condition="'$(Platform)'=='AnyCPU' or '$(Platform)'=='x86' or '$(Platform)'=='Win32'">runtimes\win-x86\native\</DestinationSubFolder>
<DestinationSubFolder Condition="'$(Platform)'=='x64'">runtimes\win-x64\native\</DestinationSubFolder>
<DestinationSubFolder Condition="'$(Platform)'=='arm64'">runtimes\win-arm64\native\</DestinationSubFolder>
</PropertyGroup>
<!--
Instead of showing an error when $(TargetFramework) or $(RuntimeIdentifier) cannot be identified
we simply do no further work
Include all the DLL's, EXE's and PDB's under $(DestinationSubFolder), i.e., either under lib\$(TargetFramework) or runtimes\$(RuntimeIdentifier)\native
Include all reference assemblies under ref\
Include all content files under content\
@(PackageAsset) evaluation should be done after $(PreparePackageAssetsDependsOn) targets have completed running. To ensure
delayed evaluation, use CreateItem tasks.
The CreateItem tasks below is equivalent to this:
<ItemGroup Condition="'$(DestinationSubFolder)'!='' and '$(IsPackagingProject)'!='true'">
<PackageAsset Include="$(OutDir)*.dll" RelativePath="$(ArtifactsPackagingDir)$(PackageName)\$(DestinationSubFolder)"/>
<PackageAsset Include="$(OutDir)*.exe" RelativePath="$(ArtifactsPackagingDir)$(PackageName)\$(DestinationSubFolder)"/>
<PackageAsset Include="$(OutDir)*.pdb" RelativePath="$(ArtifactsPackagingDir)$(PackageName)\$(DestinationSubFolder)"/>
<PackageAsset Include="$(ReferenceAssemblyDir)*.dll" RelativePath="$(ArtifactsPackagingDir)\$(DestinationSubFolder)"/>
<PackageAsset Include="$(ReferenceAssemblyDir)*.xml" RelativePath="$(ArtifactsPackagingDir)\$(DestinationSubFolder)"/>
</ItemGroup>
-->
<CreateItem Include="$(OutDir)*.dll"
Exclude="@(FileNamesExcludedFromPackaging -> '$(OutDir)%(Filename)%(Extension)' )"
AdditionalMetadata="RelativePath=$(ArtifactsPackagingDir)$(NormalizedPackageName)\$(DestinationSubFolder)"
Condition="'$(DestinationSubFolder)'!='' and '$(IsPackagingProject)'!='true' and '@(PackagingAssemblyContent)'==''">
<Output ItemName="PackageAsset" TaskParameter="Include"/>
</CreateItem>
<!--
Normally, .lib files are not included in packaging - projects have to opt in by setting
<PropertyGroup>
<IncludeLibFilesInPackaging>true<IncludeLibFilesInPackaging>
</PropertyGroup>
-->
<CreateItem Include="$(OutDir)*.lib"
Exclude="@(FileNamesExcludedFromPackaging -> '$(OutDir)%(Filename)%(Extension)' )"
AdditionalMetadata="RelativePath=$(ArtifactsPackagingDir)$(NormalizedPackageName)\$(DestinationSubFolder)"
Condition="'$(DestinationSubFolder)'!='' and '$(IsPackagingProject)'!='true' and '@(PackagingAssemblyContent)'=='' and '$(IncludeLibFilesInPackaging)' == 'true'">
<Output ItemName="PackageAsset" TaskParameter="Include"/>
</CreateItem>
<CreateItem Include="$(OutDir)*.exe"
Exclude="@(FileNamesExcludedFromPackaging -> '$(OutDir)%(Filename)%(Extension)' )"
AdditionalMetadata="RelativePath=$(ArtifactsPackagingDir)$(NormalizedPackageName)\$(DestinationSubFolder)"
Condition="'$(DestinationSubFolder)'!='' and '$(IsPackagingProject)'!='true' and '@(PackagingAssemblyContent)'==''">
<Output ItemName="PackageAsset" TaskParameter="Include"/>
</CreateItem>
<CreateItem Include="$(OutDir)*.pdb"
Exclude="@(FileNamesExcludedFromPackaging -> '$(OutDir)%(Filename)%(Extension)' )"
AdditionalMetadata="RelativePath=$(ArtifactsPackagingDir)$(NormalizedPackageName)\$(DestinationSubFolder)"
Condition="'$(DestinationSubFolder)'!='' and '$(IsPackagingProject)'!='true' and '$(ExcludePdbs)'!='true' and '@(PackagingAssemblyContent)'==''">
<Output ItemName="PackageAsset" TaskParameter="Include"/>
</CreateItem>
<!--
Static C++ libraries do not copy their PDB's to $(OutDir) -get it directly from $(IntermediateOutputPath)
Also, normally projects generating .lib files are not included in packaging. Such projects must opt in like this:
<PropertyGroup>
<IncludeLibFilesInPackaging>true<IncludeLibFilesInPackaging>
</PropertyGroup>
-->
<CreateItem Include="$(IntermediateOutputPath)*.pdb"
AdditionalMetadata="RelativePath=$(ArtifactsPackagingDir)$(NormalizedPackageName)\$(DestinationSubFolder)"
Condition="'$(ConfigurationType)'=='StaticLibrary' and '$(Language)'=='C++' and
'$(DestinationSubFolder)'!='' and '$(IsPackagingProject)'!='true' and '$(ExcludePdbs)'!='true' and '@(PackagingAssemblyContent)'=='' and '$(IncludeLibFilesInPackaging)' == 'true'">
<Output ItemName="PackageAsset" TaskParameter="Include"/>
</CreateItem>
<CreateItem Include="$(ReferenceAssemblyDir)*.dll"
AdditionalMetadata="RelativePath=$(ArtifactsPackagingDir)$(NormalizedPackageName)\ref\$(TargetFramework)"
Condition="'$(DestinationSubFolder)'!='' and '$(IsPackagingProject)'!='true' and '$(ExcludeRefAssemblies)'!='true'">
<Output ItemName="PackageAsset" TaskParameter="Include"/>
</CreateItem>
<!-- Intellisense XML's bundled alongwith ref-pack content -->
<CreateItem Include="$(ReferenceAssemblyDir)*.xml"
AdditionalMetadata="RelativePath=$(ArtifactsPackagingDir)$(NormalizedPackageName)\ref\$(TargetFramework)"
Condition="'$(DestinationSubFolder)'!='' and '$(IsPackagingProject)'!='true' and '$(ExcludeRefAssemblies)'!='true'">
<Output ItemName="PackageAsset" TaskParameter="Include"/>
</CreateItem>
<CreateItem Include="$(OutDir)%(PackagingAssemblyContent.Identity)"
AdditionalMetadata="RelativePath=$(ArtifactsPackagingDir)$(NormalizedPackageName)\$(DestinationSubFolder)"
Condition="'$(DestinationSubFolder)'!='' and '$(IsPackagingProject)'!='true' and '@(PackagingAssemblyContent)'!=''">
<Output ItemName="PackageAsset" TaskParameter="Include"/>
</CreateItem>
<!--
$(XlfLanguages) is defined by XliffTasks.
The conversion of .resx files to .xlf files, and the building of resource assemblies (.resources.dll) and
culture-specific satellite assemblies (<culture>\*.resources.dll) are done immediately after Build, as part of
CreateSatelliteAssemblies.
Include satellite assemblies into the package if $(XlfLanguages) is defined. They are included under a relative path
that is the same as their respective culture identifier (for e.g., 'fr', 'zh-Hans' etc.)
-->
<ItemGroup Condition="'$(XlfLanguages)'!=''">
<PackageAssetCultures Remove="$(PackageAssetCultures)" />
<PackageAssetCultures Include="$(XlfLanguages)" />
<PackageAsset Include="$(OutDir)%(PackageAssetCultures.Identity)\*.dll"
RelativePath="$(ArtifactsPackagingDir)$(NormalizedPackageName)\$(DestinationSubFolder)\%(PackageAssetCultures.Identity)" />
</ItemGroup>
<ItemGroup Condition="'$(DestinationSubFolder)'!=''">
<!-- %(PackagingContent.SubFolder) not StartsWith 'root' -->
<PackageAsset Condition="'%(PackagingContent.SubFolder)'!='' And !$([System.String]::Copy("%(PackagingContent.SubFolder)").StartsWith("root"))"
Include="%(PackagingContent.Identity)"
RelativePath="$(ArtifactsPackagingDir)$(NormalizedPackageName)\content\%(PackagingContent.SubFolder)"/>
<PackageAsset Condition="'%(PackagingContent.SubFolder)'==''"
Include="%(PackagingContent.Identity)"
RelativePath="$(ArtifactsPackagingDir)$(NormalizedPackageName)\content"/>
<!--
%(PackagingContent.SubFolder) StartsWith 'root'
Package content under sub-folder %(PackagingContent.SubFolder).TrimLeft('root')
Keep track of such sub-folders that exist immediately under root in a special ItemGroup - PackagingRootFolderSubFolders
PackagingRootFolderSubFolders will be used later in CreateContentFolder
Implementation Note:
SubFolder string looks like this: "root\subfolder1\subfolder2"
%(SubFolder).SubString(4) ~= "\subfolder1\subfolder2"
%(SubFolder).SubString(5) ~= "subfolder1\subfolder2"
When concatenating next to $(ArtifactsPackagingDir)$(PackageName),
- use %(SubFolder).SubString(4)
- do not insert a directory separator character (\) between them
- this has the benefit of working seamlessly when %(SubFolder) == "root"
When SubFolder name must be extracted,
- use %(SubFolder).SubString(5)
- In GenerateNuspec target, we have special-case logic to deal with files directly under the root folder,
so we only need to keep track of sub-folder names.
-->
<PackageAsset Condition="$([System.String]::Copy("%(PackagingContent.SubFolder)").StartsWith("root"))"
Include="%(PackagingContent.Identity)"
RelativePath="$(ArtifactsPackagingDir)$(NormalizedPackageName)$([System.String]::Copy('%(PackagingContent.SubFolder)').SubString(4))"/>
<PackagingRootFolderSubFolders Condition="$([System.String]::Copy("%(PackagingContent.SubFolder)").StartsWith("root\"))"
Include="$([System.String]::Copy('%(PackagingContent.SubFolder)').SubString(5))">
<PackageName>$(NormalizedPackageName)</PackageName>
</PackagingRootFolderSubFolders>
</ItemGroup>
</Target>
<!-- Target: CreateContentFolder -->
<!-- Dynamically populates @(Content) for packaging -->
<!--
This target is only run for projects which specify $(IsPackable) = true
By convention, NO WPF projects will specify $(IsPackable) = true
WPF projects will opt into PreparePackageAssets target by specifying $(PackageName)
Special packaging-only projects will be used to orchestrate the actual packaging
Also, if an "ArchNeutral" package sets $(IncludeAssembliesInArchNeutralPackage)=true,
then it will include 'lib\**\*' files in it anyway.
This can be combined with $(PlatformIndependentPackage)=true (which controls the generation
of runtime.json file) to generate an AnyCPU Sdk package containing ref + lib assemblies alongwith
all the props and targets.
The following properties are of interest to this target
$(PackageName): The name of the package
$(PackageVersion): The package version
$(Authors): Authors
$(PackageDescription): Description
$(TargetCulture): culture/language of the build. If not specified (or '*'), then $(NeutralLanguage) will be used instead
$(RepositoryUrl): Repo Url
$(PackageRequireLicenseAcceptance): true/false indicating whether license file acceptance is required
$(MsBuildSdkPackage): true/false indicating whether the nupkg is an MSBuild SDK package. When set to true, the nuspec produces
additional content indicating that the package is an Sdk.
We expect to find $(DefaultPackageLicenseFile) (typically defined as 'LICENSE.TXT' in nupkg\Directory.Build.props) at the
root of the packaging content folder . If a $(DefaultPackageLicenseFile) file is not found, we will fallback to
$(PackageLicenseExpression) license (typically defined as 'MIT')
When building a nupkg for a bait-and-switch package ($(CreateArchNeutralPackage)==true), the following changes are
made:
Package name : A RID is not prefixed onto the package name
Files - : Only ref\ and root-level content files are included
Microsoft.DotNet.Arcade.Sdk\tools\WorkArounds.targets - InitializeStandardNuspecProperties populates $(_CommonMetadataElements)
with the following metadata information:
id
description
version
authors
requireLicenseAcceptance
license type=
projectUrl
copyright
developmentDependency
serviceable
repository type= url= commit=
In effect, it provides us with all the relevant package metadata we need. We can simply reuse that
information here within <metadata>
-->
<Target Condition="'$(PackageName)'!='' and '$(IsPackable)'=='true'"
Name="CreateContentFolder">
<!-- Use $(TargetCulture) or fallback to $(NeutralLanguage) -->
<PropertyGroup>
<BuildCulture Condition="'$(TargetCulture)'!='' and '$(TargetCulture)'!='*'">$(TargetCulture)</BuildCulture>
<BuildCulture Condition="'$(BuildCulture)'==''">$(NeutralLanguage)</BuildCulture>
</PropertyGroup>
<!-- Used to test whether there are any files immediately under $(ArtifactsPackagingDir)$(PackageName) -->
<!-- ('@(RootFolderContents)'=='') would be False when there are files available to be packed -->
<ItemGroup>
<RootFolderContents Remove="@(RootFolderContents)" />
<RootFolderContents Include="$(ArtifactsPackagingDir)$(NormalizedPackageName)\*.*"/>
</ItemGroup>
<PropertyGroup>
<DestinationRuntimeSubFolder Condition="'$(Platform)'=='AnyCPU' or '$(Platform)'=='x86' or '$(Platform)'=='Win32'">runtimes\win-x86\native\</DestinationRuntimeSubFolder>
<DestinationRuntimeSubFolder Condition="'$(Platform)'=='x64'">runtimes\win-x64\native\</DestinationRuntimeSubFolder>
<DestinationRuntimeSubFolder Condition="'$(Platform)'=='arm64'">runtimes\win-arm64\native\</DestinationRuntimeSubFolder>
</PropertyGroup>
<ItemGroup>
<Content Include="$(ArtifactsPackagingDir)$(NormalizedPackageName)\$(LibFolder)\**\*.dll"
Condition="('$(CreateArchNeutralPackage)'!='true' Or '$(IncludeAssembliesInArchNeutralPackage)'== 'true') and Exists('$(ArtifactsPackagingDir)$(NormalizedPackageName)\$(LibFolder)\')" >
<Pack>true</Pack>
<PackagePath>$(LibFolder)</PackagePath>
</Content>
<Content Include="$(ArtifactsPackagingDir)$(NormalizedPackageName)\$(LibFolder)\**\*.exe"
Condition="('$(CreateArchNeutralPackage)'!='true' Or '$(IncludeAssembliesInArchNeutralPackage)'== 'true') and Exists('$(ArtifactsPackagingDir)$(NormalizedPackageName)\$(LibFolder)\')" >
<Pack>true</Pack>
<PackagePath>$(LibFolder)</PackagePath>
</Content>
<Content Include="$(ArtifactsPackagingDir)$(NormalizedPackageName)\$(LibFolder)\**\*.pdb"
Condition="('$(CreateArchNeutralPackage)'!='true' Or '$(IncludeAssembliesInArchNeutralPackage)'== 'true') and Exists('$(ArtifactsPackagingDir)$(NormalizedPackageName)\$(LibFolder)\')" >
<Pack>true</Pack>
<PackagePath>$(LibFolder)</PackagePath>
</Content>
<Content Include="$(ArtifactsPackagingDir)$(NormalizedPackageName)\$(DestinationRuntimeSubFolder)\*.dll"
Condition="('$(CreateArchNeutralPackage)'!='true' Or '$(IncludeAssembliesInArchNeutralPackage)'== 'true') and Exists('$(ArtifactsPackagingDir)$(NormalizedPackageName)\$(DestinationRuntimeSubFolder)\')" >
<Pack>true</Pack>
<PackagePath>$(DestinationRuntimeSubFolder)</PackagePath>
</Content>
<Content Include="$(ArtifactsPackagingDir)$(NormalizedPackageName)\$(DestinationRuntimeSubFolder)\*.lib"
Condition="('$(CreateArchNeutralPackage)'!='true' Or '$(IncludeAssembliesInArchNeutralPackage)'== 'true') and Exists('$(ArtifactsPackagingDir)$(NormalizedPackageName)\$(DestinationRuntimeSubFolder)\')" >
<Pack>true</Pack>
<PackagePath>$(DestinationRuntimeSubFolder)</PackagePath>
</Content>
<Content Include="$(ArtifactsPackagingDir)$(NormalizedPackageName)\$(DestinationRuntimeSubFolder)\*.exe"
Condition="('$(CreateArchNeutralPackage)'!='true' Or '$(IncludeAssembliesInArchNeutralPackage)'== 'true') and Exists('$(ArtifactsPackagingDir)$(NormalizedPackageName)\$(DestinationRuntimeSubFolder)\')" >
<Pack>true</Pack>
<PackagePath>$(DestinationRuntimeSubFolder)</PackagePath>
</Content>
<Content Include="$(ArtifactsPackagingDir)$(NormalizedPackageName)\$(DestinationRuntimeSubFolder)\*.pdb"
Condition="('$(CreateArchNeutralPackage)'!='true' Or '$(IncludeAssembliesInArchNeutralPackage)'== 'true') and Exists('$(ArtifactsPackagingDir)$(NormalizedPackageName)\$(DestinationRuntimeSubFolder)\')" >
<Pack>true</Pack>
<PackagePath>$(DestinationRuntimeSubFolder)</PackagePath>
</Content>
<Content Include="$(ArtifactsPackagingDir)$(NormalizedPackageName)\ref\**\*.dll"
Condition="Exists('$(ArtifactsPackagingDir)$(NormalizedPackageName)\ref\')">
<Pack>true</Pack>
<PackagePath>ref</PackagePath>
</Content>
<Content Include="$(ArtifactsPackagingDir)$(NormalizedPackageName)\ref\**\*.xml"
Condition="Exists('$(ArtifactsPackagingDir)$(NormalizedPackageName)\ref\')">
<Pack>true</Pack>
<PackagePath>ref</PackagePath>
</Content>
<Content Include="$(ArtifactsPackagingDir)$(NormalizedPackageName)\content\**\*.*"
Condition="('$(CreateArchNeutralPackage)'!='true' Or '$(IncludeAssembliesInArchNeutralPackage)'== 'true') and Exists('$(ArtifactsPackagingDir)$(NormalizedPackageName)\content\')" >
<Pack>true</Pack>
<PackagePath>content</PackagePath>
</Content>
<Content Include="$(ArtifactsPackagingDir)$(NormalizedPackageName)\*.*"
Exclude="$(ArtifactsPackagingDir)$(NormalizedPackageName)\runtime.json"
Condition="'$(CreateArchNeutralPackage)'!='true' and '@(RootFolderContents)'!=''" >
<Pack>true</Pack>
<PackagePath></PackagePath>
</Content>
<Content Include="$(ArtifactsPackagingDir)$(NormalizedPackageName)\*.*"
Condition="'$(CreateArchNeutralPackage)'=='true' and '@(RootFolderContents)'!=''" >
<Pack>true</Pack>
<PackagePath>.</PackagePath>
</Content>
<Content Include="$(ArtifactsPackagingDir)$(NormalizedPackageName)\%(PackagingRootFolderSubFolders.Identity)\*.*"
Condition="'@(PackagingRootFolderSubFolders)'!=''">
<Pack>true</Pack>
<PackagePath>%(PackagingRootFolderSubFolders.Identity)</PackagePath>
</Content>
</ItemGroup>
</Target>
<!--
We can't reliably insert CreatecontentFolder
at the head of GenerateNuspecDependsOn during
static imports of props/targets, so we do it
dynamically from within a target
-->
<Target Name="EnsureCreateContentFolderRunsBeforeNuspecDependsOn">
<PropertyGroup>
<GenerateNuspecDependsOn>
CreateContentFolder;
$(GenerateNuspecDependsOn)
</GenerateNuspecDependsOn>
</PropertyGroup>
</Target>
<!-- Create version.txt containing latest commit ID -->
<Target Name="GenerateVersionFileWithRepositoryCommit"
Condition="'$(IsPackable)'=='true' and '$(CreateArchNeutralPackage)'=='true' and !Exists('$(ArtifactsPackagingDir)$(NormalizedPackageName)\version.txt')"
BeforeTargets="CreateContentFolder"
Outputs="$(ArtifactsPackagingDir)$(NormalizedPackageName)\version.txt">
<!--
Workaround
Ensure that SourceRevisionId is obtained if it has not already been read in
Reuse tasks from Microsoft.Build.Tasks.Git.targets
-->
<Microsoft.Build.Tasks.Git.LocateRepository Path="$(MSBuildProjectDirectory)" Condition="'$(SourceRevisionId)' == ''" >
<Output TaskParameter="RevisionId" PropertyName="SourceRevisionId" />
</Microsoft.Build.Tasks.Git.LocateRepository>
<ItemGroup>
<RepoCommitVersionFileLines Remove="@(RepoCommitVersionFileLines)" />
<RepoCommitVersionFileLines Include="$(SourceRevisionId)" />
</ItemGroup>
<PropertyGroup>
<RepoCommitVersionFileDir>$(ArtifactsPackagingDir)$(NormalizedPackageName)\</RepoCommitVersionFileDir>
<RepoCommitVersionFile>$(RepoCommitVersionFileDir)version.txt</RepoCommitVersionFile>
</PropertyGroup>
<MakeDir Condition="!Exists('$(RepoCommitVersionFileDir)')" Directories="$(RepoCommitVersionFileDir)" />
<WriteLinesToFile Lines="@(RepoCommitVersionFileLines)" File="$(RepoCommitVersionFile)"/>
</Target>
<!-- Generate runtime.json for embedding in the arch-neutral package that uses the Bait & Switch technique -->
<Target Name="GenerateRuntimeJson"
Condition="'$(IsPackable)'=='true' and '$(CreateArchNeutralPackage)'=='true' and '$(PlatformIndependentPackage)'!='true'"
BeforeTargets="CreateContentFolder"
Outputs="$(ArtifactsPackagingDir)$(NormalizedPackageName)\runtime.json">
<ItemGroup>
<RuntimeJsonLine Remove="@(RuntimeJsonLine)" />
<RuntimeJsonLine Include="Json">
<Text>
<![CDATA[{
"runtimes": {
"win-x64": {
"$(NormalizedPackageName)": {
"runtime.win-x64.$(PackageName)": "$(PackageVersion)"
}
},
"win-x86": {
"$(NormalizedPackageName)": {
"runtime.win-x86.$(PackageName)": "$(PackageVersion)"
}
},
"win-arm64": {
"$(NormalizedPackageName)": {
"runtime.win-arm64.$(PackageName)": "$(PackageVersion)"
}
}
}
}
]]></Text>
</RuntimeJsonLine>
</ItemGroup>
<ItemGroup>
<RuntimeJson Remove="@(RuntimeJson)" />
<RuntimeJson Include="@(RuntimeJsonLine->'%(Text)')" />
</ItemGroup>
<PropertyGroup>
<RuntimeJsonFileDir>$(ArtifactsPackagingDir)$(NormalizedPackageName)\</RuntimeJsonFileDir>
<RuntimeJsonFile>$(RuntimeJsonFileDir)runtime.json</RuntimeJsonFile>
</PropertyGroup>
<MakeDir Condition="!Exists('$(ArtifactsPackagingDir)')" Directories="$(ArtifactsPackagingDir)" />
<Delete Condition="Exists('$(RuntimeJsonFile)')" Files="$(RuntimeJsonFile)" />
<WriteLinesToFile Lines="@(RuntimeJson)" File="$(RuntimeJsonFile)"/>
</Target>
</Project>