-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathDirectory.Build.targets
890 lines (749 loc) · 49.1 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
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
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets, $(MSBuildThisFileDirectory)..))" />
<PropertyGroup Condition="'$(UseInnerClone)' == 'true'">
<BuildArgs>$(BuildArgs) /p:UseInnerClone=true</BuildArgs>
<BuildArgs>$(BuildArgs) /p:CopySrcInsteadOfClone=true</BuildArgs>
<BuildArgs>$(BuildArgs) /p:CopyWipIntoInnerSourceBuildRepo=true</BuildArgs>
</PropertyGroup>
<PropertyGroup>
<!-- Force use of dotnet msbuild (ignoring global.json contents) unless ForceDotNetMSBuildEngine is explicitly set in the repo project. -->
<BuildArgs Condition="'$(BuildOS)' == 'windows' and '$(ForceDotNetMSBuildEngine)' != 'false'">$(BuildArgs) $(FlagParameterPrefix)msbuildEngine dotnet</BuildArgs>
<!-- Add the overrides for the shipping and non-shipping packages here to allow repo projects to identify a project as reference-only -->
<RepoArtifactsShippingPackagesDir Condition="'$(ReferenceOnlyRepoArtifacts)' != 'true'">$([MSBuild]::NormalizeDirectory('$(ArtifactsShippingPackagesDir)', '$(RepositoryName)'))</RepoArtifactsShippingPackagesDir>
<RepoArtifactsShippingPackagesDir Condition="'$(ReferenceOnlyRepoArtifacts)' == 'true'">$(ReferencePackagesDir)</RepoArtifactsShippingPackagesDir>
<RepoArtifactsNonShippingPackagesDir Condition="'$(ReferenceOnlyRepoArtifacts)' != 'true'">$([MSBuild]::NormalizeDirectory('$(ArtifactsNonShippingPackagesDir)', '$(RepositoryName)'))</RepoArtifactsNonShippingPackagesDir>
<RepoArtifactsNonShippingPackagesDir Condition="'$(ReferenceOnlyRepoArtifacts)' == 'true'">$(ReferencePackagesDir)</RepoArtifactsNonShippingPackagesDir>
<!-- Pass location for packages -->
<BuildArgs>$(BuildArgs) /p:SourceBuiltShippingPackagesDir=$(RepoArtifactsShippingPackagesDir)</BuildArgs>
<!-- Trim the trailing slash as it breaks argument parsing on Windows if this is the last argument. -->
<BuildArgs>$(BuildArgs) /p:SourceBuiltNonShippingPackagesDir=$(RepoArtifactsNonShippingPackagesDir.TrimEnd('\'))</BuildArgs>
<!-- Pass RID and Portable/non-portable information -->
<_platformIndex>$(NETCoreSdkRuntimeIdentifier.LastIndexOf('-'))</_platformIndex>
<RuntimeOS>$(NETCoreSdkRuntimeIdentifier.Substring(0, $(_platformIndex)))</RuntimeOS>
<_platformIndex>$(NETCoreSdkPortableRuntimeIdentifier.LastIndexOf('-'))</_platformIndex>
<BaseOS>$(NETCoreSdkPortableRuntimeIdentifier.Substring(0, $(_platformIndex)))-$(TargetArchitecture)</BaseOS>
<BuildArgs>$(BuildArgs) /p:PortableBuild=$(PortableBuild)</BuildArgs>
<BuildArgs Condition="'$(ShortStack)' != 'true' and '$(TargetOS)' != 'linux-musl'">$(BuildArgs) /p:RuntimeOS=$(RuntimeOS)</BuildArgs>
<BuildArgs Condition="'$(ShortStack)' != 'true' and '$(TargetOS)' != 'linux-musl'">$(BuildArgs) /p:BaseOS=$(BaseOS)</BuildArgs>
</PropertyGroup>
<PropertyGroup>
<BuildCommand Condition="'$(BuildCommand)' == '' and '$(IsUtilityProject)' != 'true'">$(BuildScript) $(BuildActions) $(BuildArgs)</BuildCommand>
<!-- MinimalConsoleLogOutput determines if the repository build should be logged to a separate file or directly to the console.
Enable it by default as with prallel repository builds the log becomes non-readable. -->
<RepoConsoleLogFile>$(ArtifactsLogRepoDir)$(RepositoryName).log</RepoConsoleLogFile>
<MinimalConsoleLogOutput Condition="'$(MinimalConsoleLogOutput)' == ''">$(BuildInParallel)</MinimalConsoleLogOutput>
<PackageReportDataFile>$(PackageReportDir)prebuilt-usage.xml</PackageReportDataFile>
<ProjectAssetsJsonArchiveFile>$(PackageReportDir)all-project-assets-json-files.zip</ProjectAssetsJsonArchiveFile>
<ProdConManifestFile>$(PackageReportDir)prodcon-build.xml</ProdConManifestFile>
</PropertyGroup>
<UsingTask TaskName="Microsoft.DotNet.UnifiedBuild.Tasks.ReplaceTextInFile" AssemblyFile="$(MicrosoftDotNetUnifiedBuildTasksAssembly)" TaskFactory="TaskHostFactory" />
<Target Name="AddNoWarns"
Condition=" EXISTS('$(ProjectDirectory)Directory.Build.props') OR EXISTS('$(ProjectDirectory)src/Directory.Build.props') "
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(RepoCompletedSemaphorePath)AddNoWarns.complete" >
<!-- Don't warn on warnings that can be generated in source-build
but not necessarily in repo builds.
NU1603 - See https://github.com/dotnet/source-build/issues/2766.
NU5104 - During preview builds, some packages have pre-release versions.
Some repos with stable versions may need to uptake these packages
with pre-release versions because of PVP when building with
source-build. -->
<PropertyGroup>
<OldText><![CDATA[</Project>]]></OldText>
<NewText>
<![CDATA[ <PropertyGroup>
<NoWarn>%24(NoWarn);NU1903;$(RepoNoWarns)</NoWarn>
</PropertyGroup>
</Project>]]>
</NewText>
<DirectoryBuildPropsFile Condition=" EXISTS('$(ProjectDirectory)Directory.Build.props') ">$(ProjectDirectory)Directory.Build.props</DirectoryBuildPropsFile>
<DirectoryBuildPropsFile Condition=" '$(DirectoryBuildPropsFile)' == '' AND EXISTS('$(ProjectDirectory)src/Directory.Build.props') ">$(ProjectDirectory)src/Directory.Build.props</DirectoryBuildPropsFile>
</PropertyGroup>
<ReplaceTextInFile InputFile="$(DirectoryBuildPropsFile)"
OldText="$(OldText)"
NewText="$(NewText)" />
</Target>
<!-- Returns the repository references of this project and all the projects this project references, recursively -->
<Target Name="GetTransitiveRepositoryReferences" Returns="@(TransitiveRepositoryReference)">
<ItemGroup>
<_TransitiveRepositoryReference Include="@(RepositoryReference)" />
</ItemGroup>
<MSBuild Projects="@(RepositoryReference->'%(Identity).proj')"
Targets="GetTransitiveRepositoryReferences"
BuildInParallel="true">
<Output TaskParameter="TargetOutputs" ItemName="_DependencyTransitiveRepositoryReference" />
</MSBuild>
<!-- When items are transferred between projects, they get metadata indicating their source (e.g. MSBuildSourceProjectFile).
This is problematic because it causes introduces distinctness on the items. For example, an arcade RepositoryReference
that comes from both msbuild and source-build-externals will be treated as two separate items. But we only want one arcade
reference. To prevent this from happening, we need to remove the extra metadata so the two references can be seen as duplicates. -->
<ItemGroup>
<_TransitiveRepositoryReference Include="@(_DependencyTransitiveRepositoryReference)"
RemoveMetadata="MSBuildSourceProjectFile;MSBuildSourceTargetName;OriginalItemSpec;DotNetBuildPass" />
<TransitiveRepositoryReference Include="@(_TransitiveRepositoryReference)" KeepDuplicates="false" />
</ItemGroup>
</Target>
<!-- Wraps the transitive repo references with additional metadata -->
<Target Name="GetRepositoryReferenceInfo"
DependsOnTargets="GetTransitiveRepositoryReferences">
<!-- SBRP is explicitly excluded since it is output to its own special directory, $(ReferencePackagesDir). -->
<ItemGroup Condition="'@(TransitiveRepositoryReference)' != ''">
<RepositoryReferenceInfo Include="@(TransitiveRepositoryReference)"
Exclude="source-build-reference-packages">
<ShippingSourceName>$(SourceBuiltSourceNamePrefix)%(Identity)</ShippingSourceName>
<NonShippingSourceName>$(SourceBuiltSourceNamePrefix)transport-%(Identity)</NonShippingSourceName>
<ShippingPackagesPath>$(ArtifactsShippingPackagesDir)/%(Identity)/</ShippingPackagesPath>
<NonShippingPackagesPath>$(ArtifactsNonShippingPackagesDir)/%(Identity)/</NonShippingPackagesPath>
</RepositoryReferenceInfo>
</ItemGroup>
<ItemGroup Condition="'@(RepositoryReferenceInfo)' != ''">
<DependentRepoSourceName Include="@(RepositoryReferenceInfo->'%(ShippingSourceName)')" />
<DependentRepoSourceName Include="@(RepositoryReferenceInfo->'%(NonShippingSourceName)')" />
</ItemGroup>
</Target>
<Target Name="CopyNuGetConfig"
Condition="'$(NuGetConfigFile)' != ''"
Inputs="$(MSBuildProjectFullPath);$(OriginalNuGetConfigFile)"
Outputs="$(NuGetConfigFile)">
<MakeDir Directories="$([System.IO.Path]::GetDirectoryName('$(NuGetConfigFile)'))" />
<Copy
SourceFiles="$(OriginalNuGetConfigFile)"
DestinationFiles="$(NuGetConfigFile)">
<Output TaskParameter="CopiedFiles" ItemName="FileWrites" />
</Copy>
</Target>
<UsingTask TaskName="Microsoft.DotNet.UnifiedBuild.Tasks.AddSourceToNuGetConfig" AssemblyFile="$(MicrosoftDotNetUnifiedBuildTasksAssembly)" TaskFactory="TaskHostFactory" />
<UsingTask TaskName="Microsoft.DotNet.UnifiedBuild.Tasks.RemoveInternetSourcesFromNuGetConfig" AssemblyFile="$(MicrosoftDotNetUnifiedBuildTasksAssembly)" TaskFactory="TaskHostFactory" />
<UsingTask TaskName="Microsoft.DotNet.UnifiedBuild.Tasks.UpdateNuGetConfigPackageSourcesMappings" AssemblyFile="$(MicrosoftDotNetUnifiedBuildTasksAssembly)" TaskFactory="TaskHostFactory" />
<Target Name="UpdateNuGetConfig"
DependsOnTargets="CopyNuGetConfig;GetRepositoryReferenceInfo"
Condition="'$(NuGetConfigFile)' != ''"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(BaseIntermediateOutputPath)UpdateNuGetConfig.complete">
<PropertyGroup>
<!-- Dev innerloop opt-in feed: /p:ExtraRestoreSourcePath=... -->
<ExtraSourcesNuGetSourceName>ExtraSources</ExtraSourcesNuGetSourceName>
</PropertyGroup>
<PropertyGroup Condition="'$(DotNetBuildSourceOnly)' == 'true'">
<PrebuiltNuGetSourceName>prebuilt</PrebuiltNuGetSourceName>
<PreviouslySourceBuiltNuGetSourceName>previously-source-built</PreviouslySourceBuiltNuGetSourceName>
<ReferencePackagesNuGetSourceName>reference-packages</ReferencePackagesNuGetSourceName>
</PropertyGroup>
<ItemGroup>
<_CommonBuildSources Include="@(DependentRepoSourceName)" />
<_CommonBuildSources Include="$(ExtraSourcesNuGetSourceName)" Condition="'$(ExtraRestoreSourcePath)' != ''" />
</ItemGroup>
<PropertyGroup Condition="'$(DotNetBuildSourceOnly)' != 'true'">
<!-- When not building source-only, repositories lagging behind on the .NET SDK (e.g. tooling repos)
that need to utilize a VS-aligned version for development purposes may not have the latest product
daily build feed in their NuGet.config. This means that when a newer globally-specified .NET SDK
attempts to restore shared framework packages, they will not be found. Work around this by
ensuring that repos have the supporting SDK feed. Note that this is not required when the SDK
in use is a released SDK.
Currently we are using a preview .NET 9 SDK and not all repos are using the Net 9 SDK
If either of these are not true, set below to false.
-->
<AddNetSdkSupportingFeed>true</AddNetSdkSupportingFeed>
<NetSdkSupportingFeedName>net-sdk-supporting-feed</NetSdkSupportingFeedName>
<NetSdkSupportingFeed>https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet10/nuget/v3/index.json</NetSdkSupportingFeed>
</PropertyGroup>
<ItemGroup>
<_BuildSources Include="$(PrebuiltNuGetSourceName);$(PreviouslySourceBuiltNuGetSourceName);$(ReferencePackagesNuGetSourceName)"
Condition="'$(DotNetBuildSourceOnly)' == 'true'"/>
<_BuildSources Include="@(_CommonBuildSources)" />
<_BuildSources Include="$(NetSdkSupportingFeedName)"
Condition="'$(AddNetSdkSupportingFeed)' == 'true'" />
</ItemGroup>
<RemoveInternetSourcesFromNuGetConfig
NuGetConfigFile="$(NuGetConfigFile)"
BuildWithOnlineFeeds="$(DotNetBuildWithOnlineFeeds)"
KeepFeedPrefixes="@(KeepFeedPrefixes)"
Condition="'$(DotNetBuildSourceOnly)' == 'true'" />
<AddSourceToNuGetConfig NuGetConfigFile="$(NuGetConfigFile)"
SourceName="$(PrebuiltNuGetSourceName)"
SourcePath="$(PrebuiltPackagesPath)"
Condition="'$(DotNetBuildSourceOnly)' == 'true'" />
<AddSourceToNuGetConfig NuGetConfigFile="$(NuGetConfigFile)"
SourceName="$(PreviouslySourceBuiltNuGetSourceName)"
SourcePath="$(PrebuiltSourceBuiltPackagesPath)"
Condition="'$(DotNetBuildSourceOnly)' == 'true'" />
<AddSourceToNuGetConfig NuGetConfigFile="$(NuGetConfigFile)"
SourceName="$(ReferencePackagesNuGetSourceName)"
SourcePath="$(ReferencePackagesDir)"
Condition="'$(DotNetBuildSourceOnly)' == 'true'" />
<AddSourceToNuGetConfig NuGetConfigFile="$(NuGetConfigFile)"
SourceName="%(RepositoryReferenceInfo.ShippingSourceName)"
SourcePath="%(RepositoryReferenceInfo.ShippingPackagesPath)"
Condition="Exists('%(RepositoryReferenceInfo.ShippingPackagesPath)')" />
<AddSourceToNuGetConfig NuGetConfigFile="$(NuGetConfigFile)"
SourceName="%(RepositoryReferenceInfo.NonShippingSourceName)"
SourcePath="%(RepositoryReferenceInfo.NonShippingPackagesPath)"
Condition="Exists('%(RepositoryReferenceInfo.NonShippingPackagesPath)')" />
<AddSourceToNuGetConfig NuGetConfigFile="$(NuGetConfigFile)"
SourceName="$(ExtraSourcesNuGetSourceName)"
SourcePath="$(ExtraRestoreSourcePath)"
Condition="'$(ExtraRestoreSourcePath)' != ''" />
<!-- See root Directory.Build.props for value. -->
<AddSourceToNuGetConfig NuGetConfigFile="$(NuGetConfigFile)"
SourceName="$(NetSdkSupportingFeedName)"
SourcePath="$(NetSdkSupportingFeed)"
Condition="'$(AddNetSdkSupportingFeed)' == 'true'" />
<UpdateNuGetConfigPackageSourcesMappings
NuGetConfigFile="$(NuGetConfigFile)"
BuildWithOnlineFeeds="$(DotNetBuildWithOnlineFeeds)"
SourceBuildSources="@(_BuildSources)"
SbrpRepoSrcPath="$(SbrpRepoSrcDir)"
SbrpCacheSourceName="$(SbrpCacheNuGetSourceName)"
ReferencePackagesSourceName="$(ReferencePackagesNuGetSourceName)"
PreviouslySourceBuiltSourceName="$(PreviouslySourceBuiltNuGetSourceName)"
PrebuiltSourceName="$(PrebuiltNuGetSourceName)"
SourceBuiltSourceNamePrefix="$(SourceBuiltSourceNamePrefix)"
CustomSources="$(NetSdkSupportingFeedName)" />
<MakeDir Directories="$(BaseIntermediateOutputPath)" />
<Touch Files="$(BaseIntermediateOutputPath)UpdateNuGetConfig.complete" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
<ItemGroup>
<!-- This is defined in this target to ensure the NuGet.config file is updated before it gets embedded. If this item
was define globally, it would immediately get embedded with the original, unmodified version of the file. -->
<EmbedInBinlog Include="$(NuGetConfigFile)" />
</ItemGroup>
</Target>
<!-- Update the SDK version in the repo's global.json file.
This guarantees that all repositories build with the VMR's SDK version. -->
<UsingTask TaskName="Microsoft.DotNet.UnifiedBuild.Tasks.UpdateJson" AssemblyFile="$(MicrosoftDotNetUnifiedBuildTasksAssembly)" TaskFactory="TaskHostFactory" />
<Target Name="UpdateGlobalJsonVersions"
Condition="'$(GlobalJsonFile)' != ''"
Inputs="$(MSBuildProjectFullPath);$(MSBuildThisFileFullPath)"
Outputs="$(BaseIntermediateOutputPath)UpdateGlobalJsonVersions.complete">
<ItemGroup>
<_PossibleCliVersionJsonPath Include="sdk:version" />
<_PossibleCliVersionJsonPath Include="tools:dotnet" />
</ItemGroup>
<UpdateJson JsonFilePath="$(GlobalJsonFile)"
PathToAttribute="%(_PossibleCliVersionJsonPath.Identity)"
NewAttributeValue="$(NETCoreSdkVersion)"
SkipUpdateIfMissingKey="true" />
<!-- VB PoC, remove the global runtimes until https://github.com/dotnet/arcade/issues/14283 is resolved. -->
<UpdateJson JsonFilePath="$(GlobalJsonFile)"
PathToAttribute="tools:runtimes"
SkipUpdateIfMissingKey="true" />
<MakeDir Directories="$(BaseIntermediateOutputPath)" />
<Touch Files="$(BaseIntermediateOutputPath)UpdateGlobalJsonVersions.complete" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
</Target>
<!-- TODO: Remove when all repos use a consistent set of eng/common files: https://github.com/dotnet/source-build/issues/3710. -->
<Target Name="UpdateEngCommonFiles">
<ItemGroup>
<OrchestratorEngCommonFile Include="$(RepositoryEngineeringDir)common\**\*" />
</ItemGroup>
<Copy SourceFiles="@(OrchestratorEngCommonFile)"
DestinationFolder="$(ProjectDirectory)eng\common\%(RecursiveDir)"
SkipUnchangedFiles="true" />
</Target>
<!-- Before a repository builds, set up the version property files that override the repo's defaults.
There are 3 files generated -->
<UsingTask TaskName="Microsoft.DotNet.UnifiedBuild.Tasks.WritePackageVersionsProps" AssemblyFile="$(MicrosoftDotNetUnifiedBuildTasksAssembly)" TaskFactory="TaskHostFactory" />
<UsingTask TaskName="Microsoft.DotNet.UnifiedBuild.Tasks.GetKnownArtifactsFromAssetManifests" AssemblyFile="$(MicrosoftDotNetUnifiedBuildTasksAssembly)" TaskFactory="TaskHostFactory" />
<Target Name="CreateBuildInputProps"
DependsOnTargets="GetProducedPackagesFromTransitiveReferences"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(BaseIntermediateOutputPath)CreateBuildInputProps.complete">
<!-- Get the previously-built-source-built package information from the manifest from that build. -->
<ItemGroup>
<_PrebuiltSourceBuiltAssetManifests Include="$(PrebuiltSourceBuiltPackagesPath)VerticalManifest.xml" />
</ItemGroup>
<GetKnownArtifactsFromAssetManifests AssetManifests="@(_PrebuiltSourceBuiltAssetManifests)" Condition="Exists(@(_PrebuiltSourceBuiltAssetManifests))">
<Output TaskParameter="KnownPackages" ItemName="_PreviouslyBuiltSourceBuiltPackages" />
</GetKnownArtifactsFromAssetManifests>
<Error Condition="'$(PackageVersionPropsFlowType)' != 'AllPackages' and '$(PackageVersionPropsFlowType)' != 'DependenciesOnly'"
Text="Invalid PackageVersionPropsFlowType '$(PackageVersionPropsFlowType)'. Must be 'AllPackages' or 'DependenciesOnly'." />
<PropertyGroup>
<_VersionDetailsXml Condition="'$(PackageVersionPropsFlowType)' == 'DependenciesOnly'">$(ProjectDirectory)/eng/Version.Details.xml</_VersionDetailsXml>
</PropertyGroup>
<!-- Write the build input properties, then save off a copy that will be used for generating usage reports later -->
<WritePackageVersionsProps KnownPackages="@(_DependencyProducedPackage->WithMetadataValue('ReferenceOnly', 'false'))"
ExtraProperties="@(ExtraPackageVersionPropsPackageInfo)"
VersionPropsFlowType="$(PackageVersionPropsFlowType)"
VersionDetails="$(_VersionDetailsXml)"
OutputPath="$(CurrentSourceBuiltPackageVersionPropsPath)" />
<!-- Create previously source-built inputs info -->
<WritePackageVersionsProps KnownPackages="@(_PreviouslyBuiltSourceBuiltPackages)"
VersionPropsFlowType="$(PackageVersionPropsFlowType)"
VersionDetails="$(_VersionDetailsXml)"
OutputPath="$(PreviouslySourceBuiltPackageVersionPropsPath)" />
<!-- Write a full package version props (unfiltered) that will be used to track which repo creates a package.
Because not all repos implement the repo API (e.g. some are external), it's difficult to consistently gather
a list of packages from the output of each repo. This may be an area for improvement later.
Instead, we rely on the package version props file that is built up
before each build. If the full list of packages grows by package A, B and C between repo Y and Z, then Y produced
A B and C.
A key element of this algorith is that we must write the full package version props and not the filtered version. -->
<WritePackageVersionsProps KnownPackages="@(_DependencyProducedPackage->WithMetadataValue('ReferenceOnly', 'false'))"
VersionPropsFlowType="AllPackages"
OutputPath="$(SnapshotPackageVersionPropsPath)" />
<!-- Write a single file that contains imports for both the current and previously built packages -->
<PropertyGroup>
<PackageVersionsPropsContents>
<![CDATA[
<Project>
<Import Project="$(PreviouslySourceBuiltPackageVersionPropsPath)" />
<Import Project="$(CurrentSourceBuiltPackageVersionPropsPath)" />
</Project>
]]>
</PackageVersionsPropsContents>
</PropertyGroup>
<WriteLinesToFile File="$(PackageVersionPropsPath)"
Lines="$(PackageVersionsPropsContents)"
Overwrite="true" />
<Message Importance="High" Text="$(RepositoryName) using package version properties saved at $(CurrentSourceBuiltPackageVersionPropsPath) and $(PreviouslySourceBuiltPackageVersionPropsPath)" />
<MakeDir Directories="$(BaseIntermediateOutputPath)" />
<Touch Files="$(BaseIntermediateOutputPath)CreateBuildInputProps.complete" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
</Target>
<!-- SkipRepoReferences is a developer innerloop switch to skip building dependencies. -->
<Target Name="BuildRepoReferences"
DependsOnTargets="GetTransitiveRepositoryReferences"
Condition="'@(RepositoryReference)' != '' and '$(SkipRepoReferences)' != 'true'">
<ItemGroup>
<_DependentProject Include="@(TransitiveRepositoryReference)"
Project="%(Identity).proj" />
</ItemGroup>
<!-- Filter out projects that aren't part of the current build pass. -->
<ItemGroup Condition="'$(DotNetBuildPass)' != '' and '$(DotNetBuildPass)' != '1'">
<_DependentProjectCurrentBuildPass Include="@(_DependentProject->WithMetadataValue('DotNetBuildPass', '$(DotNetBuildPass)'))" />
<_DependentProjectToSkip Include="@(_DependentProject)" Exclude="@(_DependentProjectCurrentBuildPass)" />
<_DependentProject Remove="@(_DependentProject)" />
<_DependentProject Include="@(_DependentProjectCurrentBuildPass)" />
</ItemGroup>
<Message Importance="High" Text="Building dependencies [@(_DependentProject)] needed by '$(RepositoryName)'." Condition="'@(_DependentProject)' != ''" />
<MSBuild Projects="@(_DependentProject->Metadata('Project'))"
Targets="Build"
BuildInParallel="$(BuildInParallel)"
StopOnFirstFailure="true"
RunEachTargetSeparately="$(RunEachTargetSeparately)"
Condition="'@(_DependentProject)' != ''" />
<!-- Repos that are skipped in later build passes and don't build, still need to be called in order to
extract tool packages (i.e. Arcade.Sdk). This is necessary as we use a custom sdk resolver. -->
<MSBuild Projects="@(_DependentProjectToSkip->Metadata('Project'))"
Targets="ExtractToolPackage"
BuildInParallel="$(BuildInParallel)"
Condition="'@(_DependentProjectToSkip)' != ''" />
</Target>
<Target Name="DiscoverBuiltSdkOverrides"
DependsOnTargets="BuildRepoReferences;GetProducedPackagesFromTransitiveReferences">
<!--
Discover the Arcade SDKs built from the live Arcade source and set them as overrides here.
This will automatically no-op for Arcade and SBRP, as these packages will not have been produced yet.
-->
<ItemGroup>
<ArcadeBuiltArcadeSdk Include="@(_DependencyProducedPackage->WithMetadataValue('Identity', 'Microsoft.DotNet.Arcade.Sdk'))" />
</ItemGroup>
<Error Text="The source-built Arcade SDK should be available for any repository that does not explicitly set UseBootstrapArcade to true." Condition="'@(ArcadeBuiltArcadeSdk)' == '' and '$(UseBootstrapArcade)' != 'true'" />
<ItemGroup Condition="'@(ArcadeBuiltArcadeSdk)' == ''">
<SourceBuiltSdkOverride Include="@(BootstrapArcadeSdkOverride)" />
</ItemGroup>
<ItemGroup>
<SourceBuiltSdkOverride Include="@(ArcadeBuiltArcadeSdk)" Group="ARCADE" />
<SourceBuiltSdkOverride Include="@(_DependencyProducedPackage->WithMetadataValue('Identity', 'Microsoft.DotNet.SharedFramework.Sdk'))" Group="ARCADE_SHARED_FX_SDK" />
<SourceBuiltSdkOverride Include="@(_DependencyProducedPackage->WithMetadataValue('Identity', 'Microsoft.DotNet.CMake.Sdk'))" Group="ARCADE_CMAKE_SDK" />
</ItemGroup>
<!--
Add Microsoft.Build.NoTargets and Microsoft.Build.Traversal SDK overrides, for all repos that have it built (ie. excluding SBRP as it builds the SDKs).
We need to override all SDK packages that are used by repos, to prevent NuGet SDK Resolver from trying to
restore these packages from online feeds. In offline build we only want to use local source-build feeds.
Therefore, we create a copy of repo's NuGet.config file, modify it, and pass it into repo build using
RestoreConfigFile property. MSBuild uses NuGetSdkResolver to restore missing SDKs, which doesn't honor
RestoreConfigFile property and uses NuGet.config file from repo's root which has online feeds.
-->
<ItemGroup>
<SourceBuiltSdkOverride Include="@(_DependencyProducedPackage->WithMetadataValue('Identity', 'Microsoft.Build.Traversal'))" Group="TRAVERSAL" />
<SourceBuiltSdkOverride Include="@(_DependencyProducedPackage->WithMetadataValue('Identity', 'Microsoft.Build.NoTargets'))" Group="NOTARGETS" />
</ItemGroup>
</Target>
<Target Name="SetSourceBuiltSdkOverrides"
DependsOnTargets="DiscoverBuiltSdkOverrides"
Condition="'@(SourceBuiltSdkOverride)' != ''">
<ItemGroup>
<!-- Set the environment variables for MSBuild to look for our additional SDK Resolvers and or our resolver to find our source-built SDKs. -->
<EnvironmentVariables Include="MSBUILDADDITIONALSDKRESOLVERSFOLDER=$(VSMSBuildSdkResolversDir)" />
<EnvironmentVariables Include="SOURCE_BUILT_SDK_ID_%(SourceBuiltSdkOverride.Group)=%(SourceBuiltSdkOverride.Identity)" />
<EnvironmentVariables Include="SOURCE_BUILT_SDK_VERSION_%(SourceBuiltSdkOverride.Group)=%(SourceBuiltSdkOverride.Version)" />
<EnvironmentVariables Condition="'%(SourceBuiltSdkOverride.Location)' != ''" Include="SOURCE_BUILT_SDK_DIR_%(SourceBuiltSdkOverride.Group)=%(SourceBuiltSdkOverride.Location)/" />
<EnvironmentVariables Condition="'%(SourceBuiltSdkOverride.Location)' == ''" Include="SOURCE_BUILT_SDK_DIR_%(SourceBuiltSdkOverride.Group)=$(SourceBuiltSdksDir)%(SourceBuiltSdkOverride.Identity)/" />
</ItemGroup>
</Target>
<Target Name="RepoBuild"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(BaseIntermediateOutputPath)Build.complete"
Condition="'$(BuildCommand)' != ''"
DependsOnTargets="BuildRepoReferences;
AddNoWarns;
UpdateNuGetConfig;
UpdateGlobalJsonVersions;
UpdateEngCommonFiles;
CreateBuildInputProps;
DiscoverBuiltSdkOverrides;
SetSourceBuiltSdkOverrides">
<Message Importance="High" Text="[$([System.DateTime]::Now.ToString('HH:mm:ss.ff'))] Building $(RepositoryName)" />
<Message Importance="High" Text="Running command:" />
<Message Importance="High" Text=" $(BuildCommand)" />
<Message Importance="High" Text=" Log: $(RepoConsoleLogFile)" Condition="'$(MinimalConsoleLogOutput)' == 'true'" />
<Message Importance="High" Text=" With Environment Variables:"/>
<Message Importance="High" Text=" %(EnvironmentVariables.Identity)" />
<Message Text="DirSize Before Building $(RepositoryName)" Importance="High"
Condition=" '$(CleanWhileBuilding)' == 'true' and '$(BuildOS)' != 'windows'" />
<Exec Command="df -h $(RepoRoot)"
Condition=" '$(CleanWhileBuilding)' == 'true' and '$(BuildOS)' != 'windows'" />
<PropertyGroup>
<FullCommand>$(BuildCommand)</FullCommand>
<FullCommand Condition="'$(LogVerbosityOptOut)' != 'true'">$(FullCommand) /v:$(LogVerbosity)</FullCommand>
<FullCommand Condition="'$(MinimalConsoleLogOutput)' == 'true'">$(FullCommand) > $(RepoConsoleLogFile) 2>&1</FullCommand>
</PropertyGroup>
<MakeDir Directories="$([System.IO.Path]::GetDirectoryName('$(RepoConsoleLogFile)'));
$(ArtifactsAssetsDir)" />
<!-- Create directories for extra debugging. -->
<MakeDir Directories="$(MSBuildDebugPathTargetDir);
$(RoslynDebugPathTargetDir);
$(AspNetRazorBuildServerLogDir)"
Condition="'$(EnableExtraDebugging)' == 'true'" />
<Exec Command="$(FullCommand)"
WorkingDirectory="$(ProjectDirectory)"
EnvironmentVariables="@(EnvironmentVariables)"
IgnoreStandardErrorWarningFormat="true">
<Output TaskParameter="ExitCode" PropertyName="RepoBuildExitCode" />
</Exec>
<Message Importance="High" Text="[$([System.DateTime]::Now.ToString('HH:mm:ss.ff'))] Building $(RepositoryName)...done" />
<MakeDir Directories="$(BaseIntermediateOutputPath)" />
<Touch Files="$(BaseIntermediateOutputPath)Build.complete" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
<OnError ExecuteTargets="MoveDotNetBuildLogs;LogRepoBuildError" />
</Target>
<!-- Propagate errors to the output when using the minimal console log feature. -->
<Target Name="LogRepoBuildError" Condition="'$(MinimalConsoleLogOutput)' == 'true'">
<Message Importance="High" Text="$([System.IO.File]::ReadAllText('$(RepoConsoleLogFile)'))" Condition="Exists('$(RepoConsoleLogFile)')" />
<Message Importance="High" Text="'$(RepositoryName)' failed during build." />
<Message Importance="High" Text="See '$(RepoConsoleLogFile)' for more information." Condition="Exists('$(RepoConsoleLogFile)')" />
</Target>
<!-- Log the new repo artifacts -->
<Target Name="LogRepoArtifacts"
DependsOnTargets="GetProducedPackages"
Inputs="@(RepoAssetManifest)"
Outputs="$(BaseIntermediateOutputPath)LogRepoArtifacts.complete"
Condition="'$(IsUtilityProject)' != 'true'">
<Message Importance="High" Text="New artifact(s) after building $(RepositoryName):" />
<Message Importance="High" Text=" -> %(ProducedPackage.Identity)/%(ProducedPackage.Version)" Condition="'@(ProducedPackage)' != ''" />
<Message Importance="High" Text=" -> %(ProducedAsset.Identity)" Condition="'@(ProducedAsset)' != ''" />
<MakeDir Directories="$(BaseIntermediateOutputPath)" />
<Touch Files="$(BaseIntermediateOutputPath)LogRepoArtifacts.complete" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
</Target>
<UsingTask TaskName="Microsoft.DotNet.UnifiedBuild.Tasks.GetKnownArtifactsFromAssetManifests" AssemblyFile="$(MicrosoftDotNetUnifiedBuildTasksAssembly)" TaskFactory="TaskHostFactory" />
<Target Name="GetProducedPackages"
Condition="'$(IsUtilityProject)' != 'true'"
Returns="@(ProducedPackage)">
<ItemGroup>
<RepoAssetManifest Include="$(RepoAssetManifestsDir)*.xml" />
</ItemGroup>
<Error Text="No repository asset manifest files found at $(RepoAssetManifestsDir)*.xml. This often means the build failed but did not log an error." Condition="'@(RepoAssetManifest)' == ''" />
<GetKnownArtifactsFromAssetManifests AssetManifests="@(RepoAssetManifest)">
<Output TaskParameter="KnownPackages" ItemName="ProducedPackage" />
<Output TaskParameter="KnownBlobs" ItemName="ProducedAsset" />
</GetKnownArtifactsFromAssetManifests>
<ItemGroup>
<ProducedPackage ReferenceOnly="$([MSBuild]::ValueOrDefault('$(ReferenceOnlyRepoArtifacts)', 'false'))" />
</ItemGroup>
</Target>
<Target Name="GetProducedPackagesFromTransitiveReferences" DependsOnTargets="GetTransitiveRepositoryReferences" Returns="@(_DependencyProducedPackage)">
<MSBuild Projects="@(TransitiveRepositoryReference->'%(Identity).proj')"
Targets="GetProducedPackages"
BuildInParallel="true">
<Output TaskParameter="TargetOutputs" ItemName="_DependencyProducedPackage" />
</MSBuild>
</Target>
<!-- Copy restored packages from inner build to ensure they're included in the
main build prebuilt check -->
<Target Name="CopyInnerBuildRestoredPackages"
Condition="'$(IsUtilityProject)' != 'true' and '$(DotNetBuildSourceOnly)' == 'true'">
<ItemGroup>
<_InnerPackageCacheFiles Include="$(ProjectDirectory)artifacts/sb/package-cache/**/*" />
</ItemGroup>
<!-- Retries can be necessary due to file locking when parallel builds are enabled and multiple repos
are trying to write their restored packages to this location.
See https://github.com/dotnet/source-build/issues/4234 -->
<Copy SourceFiles="@(_InnerPackageCacheFiles)"
DestinationFiles="$(NuGetPackageRoot)%(RecursiveDir)%(Filename)%(Extension)"
SkipUnchangedFiles="true"
Retries="5"
Condition="'@(_InnerPackageCacheFiles)' != ''" />
</Target>
<Target Name="MoveDotNetBuildLogs"
Condition="'$(IsUtilityProject)' != 'true' and
Exists('$(ProjectDirectory)artifacts')">
<ItemGroup>
<LogFilesToMove Include="$(ProjectDirectory)artifacts/**/*.log" />
<LogFilesToMove Include="$(ProjectDirectory)artifacts/**/*.binlog" />
<PrebuiltReportsToMove Include="$(ProjectDirectory)artifacts/sb/prebuilt-report/*" />
</ItemGroup>
<!-- Move the build logs -->
<Move SourceFiles="@(LogFilesToMove)"
DestinationFolder="$(ArtifactsLogRepoDir)"
Condition="'@(LogFilesToMove)' != ''" />
<!-- Move the prebuilt reports -->
<Move SourceFiles="@(PrebuiltReportsToMove)"
DestinationFolder="$(PackageReportRepoDir)"
Condition="'@(PrebuiltReportsToMove)' != ''" />
</Target>
<Target Name="CleanupRepo"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(BaseIntermediateOutputPath)CleanupRepo.complete"
Condition="'$(IsUtilityProject)' != 'true' and
'$(CleanWhileBuilding)' == 'true' and
Exists('$(ProjectDirectory)artifacts')">
<!--
Some repositories (WinForms) use source generators that open files manually and keep file handles open on the compiler server (CsWin32).
These source generators are written incorrectly (a source generator should never do IO itself),
but the required features to read in binary files as input to a source generator don't exist.
To work around these source generators, shut down the compiler server so we can delete the obj directories.
Don't fail the build when shutdown returns a failure.
-->
<Exec Command="$(DotnetTool) build-server shutdown --vbcscompiler"
IgnoreStandardErrorWarningFormat="true"
IgnoreExitCode="true" />
<PropertyGroup>
<BuildObjDir>$([MSBuild]::NormalizeDirectory('$(ProjectDirectory)', 'artifacts', 'buildObj'))</BuildObjDir>
</PropertyGroup>
<ItemGroup>
<ObjFilesToCopy Include="$(ProjectDirectory)artifacts/**/project.assets.json" />
</ItemGroup>
<!-- Make a copy of project.assets.json files -->
<Copy SourceFiles="@(ObjFilesToCopy)"
DestinationFolder="$(BuildObjDir)%(RecursiveDir)"
Condition="'@(ObjFilesToCopy)' != ''" />
<ItemGroup>
<DirsToDelete Include="$([System.IO.Directory]::GetDirectories('$(ProjectDirectory)artifacts'))" />
<DirsToDeleteWithTrailingSeparator Include="$([MSBuild]::EnsureTrailingSlash('%(DirsToDelete.Identity)'))" />
<DirsToDeleteWithTrailingSeparator Remove="$(BuildObjDir)" />
</ItemGroup>
<Message Text="DirSize After Building $(RepositoryName)" Importance="High" Condition="'$(BuildOS)' != 'windows' and '@(DirsToDeleteWithTrailingSeparator)' != ''" />
<Exec Command="df -h $(RepoRoot)" Condition="'$(BuildOS)' != 'windows' and '@(DirsToDeleteWithTrailingSeparator)' != ''" />
<!-- Cleanup everything else. Ignore errors as out-of-band build servers don't reliably shut down, even with the build-server shutdown command.
https://github.com/dotnet/source-build/issues/4175 tracks a long term fix. -->
<RemoveDir Directories="@(DirsToDeleteWithTrailingSeparator)" ContinueOnError="true" />
<Message Text="DirSize After CleanupRepo $(RepositoryName)" Importance="High" Condition="'$(BuildOS)' != 'windows'and '@(DirsToDeleteWithTrailingSeparator)' != ''" />
<Exec Command="df -h $(RepoRoot)" Condition="'$(BuildOS)' != 'windows'and '@(DirsToDeleteWithTrailingSeparator)' != ''" />
<MakeDir Directories="$(BaseIntermediateOutputPath)" />
<Touch Files="$(BaseIntermediateOutputPath)CleanupRepo.complete" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
</Target>
<Target Name="DiscoverToolPackageVersions" DependsOnTargets="GetProducedPackages">
<JoinItems Left="@(ProducedPackage)"
Right="@(BuiltSdkPackage)"
LeftMetadata="*">
<Output TaskParameter="JoinResult" ItemName="BuiltSdkPackageOverride" />
</JoinItems>
</Target>
<Target Name="ExtractToolPackageCore"
DependsOnTargets="DiscoverToolPackageVersions"
Condition="'@(BuiltSdkPackageOverride)' != ''"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(BaseIntermediateOutputPath)ExtractToolPackage.complete">
<PropertyGroup>
<_ToolPackagesRoot>$(RepoArtifactsNonShippingPackagesDir)</_ToolPackagesRoot>
</PropertyGroup>
<ItemGroup>
<_ToolPackage
Condition="'%(BuiltSdkPackageOverride.Version)' == ''"
Include="$(_ToolPackagesRoot)%(BuiltSdkPackageOverride.Identity)*.nupkg"
Exclude="$(_ToolPackagesRoot)%(BuiltSdkPackageOverride.Identity)*.symbols.nupkg"
Id="%(BuiltSdkPackageOverride.Identity)" />
<_ToolPackage
Condition="'%(BuiltSdkPackageOverride.Version)' != ''"
Include="$(_ToolPackagesRoot)%(BuiltSdkPackageOverride.Identity).%(BuiltSdkPackageOverride.Version).nupkg"
Exclude="$(_ToolPackagesRoot)%(BuiltSdkPackageOverride.Identity).%(BuiltSdkPackageOverride.Version).symbols.nupkg"
Id="%(BuiltSdkPackageOverride.Identity)" />
</ItemGroup>
<Unzip SourceFiles="%(_ToolPackage.Identity)"
DestinationFolder="$(SourceBuiltSdksDir)%(_ToolPackage.Id)\"
SkipUnchangedFiles="true" />
<ItemGroup>
<ExtractedToolFiles Include="$(SourceBuiltSdksDir)%(_ToolPackage.Id)/**/*netcore*/*.dll" />
</ItemGroup>
<Copy SourceFiles="@(ExtractedToolFiles)" DestinationFolder="$(SourceBuiltSdksDir)/" />
<MakeDir Directories="$(BaseIntermediateOutputPath)" />
<Touch Files="$(BaseIntermediateOutputPath)ExtractToolPackage.complete" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
</Target>
<Target Name="ExtractToolPackage"
DependsOnTargets="DiscoverToolPackageVersions;ExtractToolPackageCore" />
<Target Name="Build"
DependsOnTargets="
BuildRepoReferences;
RepoBuild;
LogRepoArtifacts;
CopyInnerBuildRestoredPackages;
ExtractToolPackage;
MoveDotNetBuildLogs;
CleanupRepo" />
<Target Name="Test">
<Message Importance="High" Text="[$([System.DateTime]::Now.ToString('HH:mm:ss.ff'))] Testing $(RepositoryName)" />
<Message Importance="High" Text="Running command:" />
<Message Importance="High" Text=" $(TestCommand)" />
<Message Importance="High" Text=" With Environment Variables:"/>
<Message Importance="High" Text=" %(TestEnvironmentVariable.Identity)" />
<PropertyGroup>
<FullTestCommand>$(TestCommand)</FullTestCommand>
<FullTestCommand Condition="'$(LogVerbosityOptOut)' != 'true'">$(FullTestCommand) /v:$(LogVerbosity)</FullTestCommand>
</PropertyGroup>
<Exec Command="$(FullTestCommand)"
WorkingDirectory="$(ProjectDirectory)"
EnvironmentVariables="@(TestEnvironmentVariable)">
<Output TaskParameter="ExitCode" PropertyName="RepoTestExitCode" />
</Exec>
<Message Importance="High" Text="[$([System.DateTime]::Now.ToString('HH:mm:ss.ff'))] Testing $(RepositoryName)...done" />
</Target>
<Target Name="VSTest" DependsOnTargets="Test" />
<UsingTask TaskName="Microsoft.DotNet.UnifiedBuild.Tasks.UsageReport.WritePackageUsageData" AssemblyFile="$(MicrosoftDotNetUnifiedBuildTasksAssembly)" TaskFactory="TaskHostFactory" />
<Target Name="WritePrebuiltUsageData"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(BaseIntermediateOutputPath)WritePrebuiltUsageData.complete">
<!-- Save the PVP snapshot of each build step to be evaluated while building the report. -->
<ItemGroup>
<PackageVersionPropsSnapshotFiles Include="$(PackageVersionsDir)PackageVersions.*.Snapshot.props" />
</ItemGroup>
<Copy SourceFiles="@(PackageVersionPropsSnapshotFiles)" DestinationFolder="$(PackageReportDir)snapshots/" />
<ItemGroup>
<!--
Note the usage of */*/*.nupkg and not **/*.nupkg. The latter would include nupkgs
carried as content, i.e. in Microsoft.FSharp.Compiler nupkg, and cause false positives.
Content nupkgs were not restored and should not be used in prebuit detection.
Example of a restored package:
$(NuGetPackageRoot)microsoft.fsharp.compiler/12.8.300-beta.24203.1/microsoft.fsharp.compiler.12.8.300-beta.24203.1.nupkg
Example of a content package:
$(NuGetPackageRoot)microsoft.fsharp.compiler/12.8.300-beta.24203.1/contentFiles/Release/FSharp.Core.8.0.300.nupkg
-->
<RestoredPackageFile Include="$(NuGetPackageRoot)*/*/*.nupkg"
Exclude="$(NuGetPackageRoot)tests/**/*.nupkg" />
<!-- Only contains packages when building. -->
<TarballPrebuiltPackageFile Include="$(PrebuiltPackagesPath)*.nupkg" />
<SourceBuiltPackageFile Include="$(ArtifactsPackagesDir)**/*.nupkg" />
<SourceBuiltPackageFile Include="$(PrebuiltSourceBuiltPackagesPath)*.nupkg" />
<ReferencePackageFile Include="$(ReferencePackagesDir)**/*.nupkg" />
<!-- Check all RIDs from all restored Microsoft.NETCore.Platforms packages. -->
<PlatformsRuntimeJsonFile Include="$(NuGetPackageRoot)microsoft.netcore.platforms/*/PortableRuntimeIdentifierGraph.json" />
</ItemGroup>
<ItemGroup>
<RepoProject Include="$(RepoProjectsDir)*.proj" />
<RepoProjectDirectory Include="@(RepoProject->'$(SrcDir)%(Filename)')" />
<!-- Add some other potential top-level project directories for a more specific report. -->
<RepoProjectDirectory Include="$(SourceBuiltSdksDir);$(TasksDir);$(ArtifactsObjDir)" />
<!-- Finally, scan entire source-build, in case project.assets.json ends up in an unexpected place. -->
<RepoProjectDirectory Include="$(RepoRoot)" />
</ItemGroup>
<ItemGroup>
<!-- This file is a resource tracked by Git, not generated by restore. Ignore false positive. -->
<IgnoredProjectAssetsJsonFile Include="$(SrcDir)*nuget-client*/**/test/NuGet.Core.Tests/NuGet.Build.Tasks.Pack.Test/compiler/resources/project.assets.json"/>
</ItemGroup>
<WritePackageUsageData
RestoredPackageFiles="@(RestoredPackageFile)"
TarballPrebuiltPackageFiles="@(TarballPrebuiltPackageFile)"
SourceBuiltPackageFiles="@(SourceBuiltPackageFile)"
ReferencePackageFiles="@(ReferencePackageFile)"
PlatformsRuntimeJsonFiles="@(PlatformsRuntimeJsonFile)"
TargetRid="$(TargetRid)"
ProjectDirectories="@(RepoProjectDirectory)"
RootDir="$(RepoRoot)"
IgnoredProjectAssetsJsonFiles="@(IgnoredProjectAssetsJsonFile)"
DataFile="$(PackageReportDataFile)"
ProjectAssetsJsonArchiveFile="$(ProjectAssetsJsonArchiveFile)" />
<!-- Copy packages detected as prebuilts to the artifacts prebuilt folder -->
<ItemGroup>
<AllowedPackageFile Include="@(TarballPrebuiltPackageFile)" />
<AllowedPackageFile Include="@(SourceBuiltPackageFile)" />
<AllowedPackageFile Include="@(ReferencePackageFile)" />
<AllowedPackageFile>
<LCFilename>$([System.String]::Copy(%(Filename)).ToLowerInvariant())</LCFilename>
</AllowedPackageFile>
<PrebuiltPackageFile Include="@(RestoredPackageFile)" >
<LCFilename>$([System.String]::Copy(%(Filename)).ToLowerInvariant())</LCFilename>
</PrebuiltPackageFile>
<PrebuiltPackageFile Remove="@(AllowedPackageFile)" MatchOnMetadata="LCFilename" />
</ItemGroup>
<Copy SourceFiles="@(PrebuiltPackageFile)" DestinationFolder="$(ResultingPrebuiltPackagesDir)" />
<MakeDir Directories="$(BaseIntermediateOutputPath)" />
<Touch Files="$(BaseIntermediateOutputPath)WritePrebuiltUsageData.complete" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
</Target>
<UsingTask TaskName="Microsoft.DotNet.UnifiedBuild.Tasks.UsageReport.ValidateUsageAgainstBaseline" AssemblyFile="$(MicrosoftDotNetUnifiedBuildTasksAssembly)" TaskFactory="TaskHostFactory" />
<UsingTask TaskName="Microsoft.DotNet.UnifiedBuild.Tasks.UsageReport.WriteUsageReports" AssemblyFile="$(MicrosoftDotNetUnifiedBuildTasksAssembly)" TaskFactory="TaskHostFactory" />
<Target Name="ReportPrebuiltUsage"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(BaseIntermediateOutputPath)ReportPrebuiltUsage.complete">
<PropertyGroup>
<FailOnPrebuiltBaselineError Condition="'$(FailOnPrebuiltBaselineError)' == ''">false</FailOnPrebuiltBaselineError>
</PropertyGroup>
<ItemGroup>
<PackageVersionPropsSavedSnapshotFile Include="$(PackageReportDir)snapshots/PackageVersions.*.Snapshot.props" />
</ItemGroup>
<WriteUsageReports DataFile="$(PackageReportDataFile)"
PackageVersionPropsSnapshots="@(PackageVersionPropsSavedSnapshotFile)"
ProdConBuildManifestFile="$(ProdConManifestFile)"
PoisonedReportFile="$(PoisonedReportFile)"
OutputDirectory="$(PackageReportDir)" />
<PropertyGroup Condition="'$(ContinueOnPrebuiltBaselineError)' == ''">
<ContinueOnPrebuiltBaselineError>false</ContinueOnPrebuiltBaselineError>
<ContinueOnPrebuiltBaselineError Condition="'$(FailOnPrebuiltBaselineError)' != 'true'">true</ContinueOnPrebuiltBaselineError>
</PropertyGroup>
<ValidateUsageAgainstBaseline
DataFile="$(PackageReportDataFile)"
BaselineDataFile="$(BaselineDataFile)"
OutputBaselineFile="$(PackageReportDir)generated-new-baseline.xml"
OutputReportFile="$(PackageReportDir)baseline-comparison.xml"
AllowTestProjectUsage="$(AllowTestProjectUsage)"
ContinueOnError="$(ContinueOnPrebuiltBaselineError)" />
<MakeDir Directories="$(BaseIntermediateOutputPath)" />
<Touch Files="$(BaseIntermediateOutputPath)ReportPrebuiltUsage.complete" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
</Target>
<!-- Outputs a dependency graph of the repos, in YAML form, to the console. -->
<Target Name="ShowDependencyGraph">
<MSBuild Projects="$(MSBuildProjectFullPath)"
Targets="GetDependencyGraphString"
Properties="DependencyGraphIndent=">
<Output TaskParameter="TargetOutputs" PropertyName="DependencyGraphString" />
</MSBuild>
<!-- Replace the '_' placeholder with spaces -->
<Message Importance="High" Text="$(DependencyGraphString.Replace('_', ' ').Trim())" />
</Target>
<!-- Recursively walks the repo dependency graph gathering each repo's dependencies which are returned as a YAML string representation -->
<Target Name="GetDependencyGraphString"
DependsOnTargets="GetTransitiveRepositoryReferences"
Returns="$(DependencyGraphString)">
<PropertyGroup>
<!-- Each step deeper in the graph builds up the indentation used for the YAML representation.
Use '_' as a placeholder for the space ' ' character since trailing spaces aren't handled well as property values. -->
<_NextIndent>$(DependencyGraphIndent)__</_NextIndent>
</PropertyGroup>
<!-- For each of the current project's direct repo dependencies, recursively call the target to get each of there dependency graphs -->
<MSBuild Projects="@(RepositoryReference->'%(Identity).proj')"
Targets="GetDependencyGraphString"
Properties="DependencyGraphIndent=$(_NextIndent)">
<Output TaskParameter="TargetOutputs" ItemName="_DependencyGraphString" />
</MSBuild>
<!-- Append all the separate dependency graph snippets together -->
<PropertyGroup>
<!-- Ensure the item `;` separators are removed from the the target output -->
<_DependencyGraphString>@(_DependencyGraphString, '')</_DependencyGraphString>
<_LineBreak>%0a</_LineBreak>
<DependencyGraphString>$(DependencyGraphIndent)-_$(RepositoryName)$(_LineBreak)$(_DependencyGraphString)</DependencyGraphString>
</PropertyGroup>
</Target>
</Project>