-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
ProjectGraph_Tests.cs
2332 lines (1950 loc) · 101 KB
/
ProjectGraph_Tests.cs
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
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Exceptions;
using Microsoft.Build.Execution;
using static Microsoft.Build.Graph.UnitTests.GraphTestingUtilities;
using Microsoft.Build.Shared;
using Microsoft.Build.UnitTests;
using Shouldly;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.Build.Graph.UnitTests
{
[ActiveIssue("https://github.com/Microsoft/msbuild/issues/4368")]
public class ProjectGraphTests : IDisposable
{
private TestEnvironment _env;
private static readonly string ProjectReferenceTargetsWithMultitargeting = @"<ItemGroup>
<!-- Item order is important to ensure outer build targets are put in front of inner build ones -->
<ProjectReferenceTargets Include='A' Targets='AHelperInner;A' />
<ProjectReferenceTargets Include='A' Targets='AHelperOuter' OuterBuild='true' />
</ItemGroup>";
private static string[] NonOuterBuildTargets = {"AHelperOuter", "AHelperInner", "A"};
private static string[] OuterBuildTargets = {"AHelperOuter"};
private static readonly string OuterBuildSpecificationWithProjectReferenceTargets = MultitargetingSpecificationPropertyGroup + ProjectReferenceTargetsWithMultitargeting;
public ProjectGraphTests(ITestOutputHelper outputHelper)
{
_env = TestEnvironment.Create(outputHelper);
}
[Fact]
public void ConstructWithNoNodes()
{
var projectGraph = new ProjectGraph(Enumerable.Empty<ProjectGraphEntryPoint>());
projectGraph.ProjectNodes.ShouldBeEmpty();
projectGraph.EntryPointNodes.ShouldBeEmpty();
projectGraph.GraphRoots.ShouldBeEmpty();
projectGraph.ProjectNodesTopologicallySorted.ShouldBeEmpty();
projectGraph.GetTargetLists(new []{"restore", "build"}).ShouldBeEmpty();
}
[Fact]
public void ConstructWithSingleNode()
{
using (var env = TestEnvironment.Create())
{
TransientTestFile entryProject = CreateProjectFile(env, 1);
var projectGraph = new ProjectGraph(entryProject.Path);
projectGraph.ProjectNodes.Count.ShouldBe(1);
projectGraph.ProjectNodes.First().ProjectInstance.FullPath.ShouldBe(entryProject.Path);
}
}
[Fact]
public void ConstructionMetricsAreAvailable()
{
var graph = Helpers.CreateProjectGraph(
_env,
new Dictionary<int, int[]>()
{
{1, new[] {2, 3}}
});
graph.ConstructionMetrics.ConstructionTime.Ticks.ShouldBeGreaterThan(0);
graph.ConstructionMetrics.NodeCount.ShouldBe(3);
graph.ConstructionMetrics.EdgeCount.ShouldBe(2);
}
[Fact]
public void ConstructWithSingleNodeWithProjectInstanceFactory()
{
using (var env = TestEnvironment.Create())
{
TransientTestFile entryProject = CreateProjectFile(env, 1);
bool factoryCalled = false;
var projectGraph = new ProjectGraph(
entryProject.Path,
ProjectCollection.GlobalProjectCollection,
(projectPath, globalProperties, projectCollection) =>
{
factoryCalled = true;
return ProjectGraph.DefaultProjectInstanceFactory(
projectPath,
globalProperties,
projectCollection);
});
projectGraph.ProjectNodes.Count.ShouldBe(1);
projectGraph.ProjectNodes.First().ProjectInstance.FullPath.ShouldBe(entryProject.Path);
factoryCalled.ShouldBeTrue();
}
}
[Fact]
public void ProjectGraphNodeConstructorNoNullArguments()
{
_env.DoNotLaunchDebugger();
Assert.Throws<InternalErrorException>(() => new ProjectGraphNode(null));
}
[Fact]
public void UpdatingReferencesIsBidirectional()
{
using (var env = TestEnvironment.Create())
{
var projectInstance = new Project().CreateProjectInstance();
var node = new ProjectGraphNode(projectInstance);
var reference1 = new ProjectGraphNode(projectInstance);
var referenceItem1 = new ProjectItemInstance(projectInstance, "Ref1", "path1", "file1");
var reference2 = new ProjectGraphNode(projectInstance);
var referenceItem2 = new ProjectItemInstance(projectInstance, "Ref2", "path2", "file2");
var edges = new GraphBuilder.GraphEdges();
node.AddProjectReference(reference1, referenceItem1, edges);
node.AddProjectReference(reference2, referenceItem2, edges);
node.ProjectReferences.ShouldBeSameIgnoringOrder(new []{reference1, reference2});
node.ReferencingProjects.ShouldBeEmpty();
reference1.ReferencingProjects.ShouldBeSameIgnoringOrder(new[] {node});
reference1.ProjectReferences.ShouldBeEmpty();
reference2.ReferencingProjects.ShouldBeSameIgnoringOrder(new[] {node});
reference2.ProjectReferences.ShouldBeEmpty();
edges[(node, reference1)].ShouldBe(referenceItem1);
edges[(node, reference2)].ShouldBe(referenceItem2);
edges.Count.ShouldBe(2);
node.RemoveReferences(edges);
node.ProjectReferences.ShouldBeEmpty();
node.ReferencingProjects.ShouldBeEmpty();
reference1.ProjectReferences.ShouldBeEmpty();
reference1.ReferencingProjects.ShouldBeEmpty();
reference2.ProjectReferences.ShouldBeEmpty();
reference2.ReferencingProjects.ShouldBeEmpty();
edges.Count.ShouldBe(0);
}
}
[Fact]
public void FirstEdgeWinsWhenMultipleEdgesPointToSameReference()
{
using (var env = TestEnvironment.Create())
{
var projectInstance = new Project().CreateProjectInstance();
var node = new ProjectGraphNode(projectInstance);
var reference1 = new ProjectGraphNode(projectInstance);
var referenceItem1 = new ProjectItemInstance(projectInstance, "Ref1", "path1", "file1");
var referenceItem2 = new ProjectItemInstance(projectInstance, "Ref2", "path1", "file1");
var edges = new GraphBuilder.GraphEdges();
node.AddProjectReference(reference1, referenceItem1, edges);
// add same reference but via a different edge
node.AddProjectReference(reference1, referenceItem2, edges);
edges.Count.ShouldBe(1);
edges[(node, reference1)].ShouldBe(referenceItem1);
}
}
[Fact]
public void ConstructWithProjectInstanceFactory_FactoryReturnsNull_Throws()
{
using (var env = TestEnvironment.Create())
{
TransientTestFile entryProject = CreateProjectFile(env, 1);
Should.Throw<InvalidOperationException>(() => new ProjectGraph(
entryProject.Path,
ProjectCollection.GlobalProjectCollection,
(projectPath, globalProperties, projectCollection) => null));
}
}
/// <summary>
/// 1
/// / \
/// 2 3
/// </summary>
[Fact]
public void ConstructWithThreeNodes()
{
using (var env = TestEnvironment.Create())
{
TransientTestFile entryProject = CreateProjectFile(env, 1, new[] { 2, 3 });
CreateProjectFile(env, 2);
CreateProjectFile(env, 3);
ProjectGraph graph = new ProjectGraph(entryProject.Path);
graph.ProjectNodes.Count.ShouldBe(3);
GetFirstNodeWithProjectNumber(graph, 1).ProjectReferences.Count.ShouldBe(2);
GetFirstNodeWithProjectNumber(graph, 2).ProjectReferences.Count.ShouldBe(0);
GetFirstNodeWithProjectNumber(graph, 3).ProjectReferences.Count.ShouldBe(0);
}
}
/// <summary>
/// Test the following graph with entry project 2
/// 2 depends on 3,5,6
/// 6 depends on 1
/// 5 depends on 7
/// 1 depends on 4,5
/// </summary>
[Fact]
public void ConstructWithMultipleNodes()
{
using (var env = TestEnvironment.Create())
{
CreateProjectFile(env, 1, new[] { 4, 5 });
TransientTestFile entryProject = CreateProjectFile(env, 2, new[] { 3, 5, 6 });
CreateProjectFile(env, 3);
CreateProjectFile(env, 4);
CreateProjectFile(env, 5, new[] { 7 });
CreateProjectFile(env, 6, new[] { 1 });
CreateProjectFile(env, 7);
ProjectGraph graph = new ProjectGraph(entryProject.Path);
graph.ProjectNodes.Count.ShouldBe(7);
ProjectGraphNode node1 = GetFirstNodeWithProjectNumber(graph, 1);
ProjectGraphNode node2 = GetFirstNodeWithProjectNumber(graph, 2);
ProjectGraphNode node3 = GetFirstNodeWithProjectNumber(graph, 3);
ProjectGraphNode node4 = GetFirstNodeWithProjectNumber(graph, 4);
ProjectGraphNode node5 = GetFirstNodeWithProjectNumber(graph, 5);
ProjectGraphNode node6 = GetFirstNodeWithProjectNumber(graph, 6);
ProjectGraphNode node7 = GetFirstNodeWithProjectNumber(graph, 7);
node1.ProjectReferences.Count.ShouldBe(2);
node2.ProjectReferences.Count.ShouldBe(3);
node3.ProjectReferences.Count.ShouldBe(0);
node4.ProjectReferences.Count.ShouldBe(0);
node5.ProjectReferences.Count.ShouldBe(1);
node6.ProjectReferences.Count.ShouldBe(1);
node7.ProjectReferences.Count.ShouldBe(0);
node1.ReferencingProjects.Count.ShouldBe(1);
node2.ReferencingProjects.Count.ShouldBe(0);
node3.ReferencingProjects.Count.ShouldBe(1);
node4.ReferencingProjects.Count.ShouldBe(1);
node5.ReferencingProjects.Count.ShouldBe(2);
node6.ReferencingProjects.Count.ShouldBe(1);
node7.ReferencingProjects.Count.ShouldBe(1);
// confirm that there is a path from 2 -> 6 -> 1 -> 5 -> 7
node2.ProjectReferences.ShouldContain(node6);
node6.ProjectReferences.ShouldContain(node1);
node1.ProjectReferences.ShouldContain(node5);
node5.ProjectReferences.ShouldContain(node7);
// confirm that there is a path from 7 -> 5 -> 1 -> 6 -> 2 using ReferencingProjects
node7.ReferencingProjects.ShouldContain(node5);
node5.ReferencingProjects.ShouldContain(node1);
node1.ReferencingProjects.ShouldContain(node6);
node6.ReferencingProjects.ShouldContain(node2);
}
}
[Fact]
public void ConstructWithCycle()
{
using (var env = TestEnvironment.Create())
{
TransientTestFile entryProject = CreateProjectFile(env, 1, new[] { 2 });
var proj2 = CreateProjectFile(env, 2, new[] { 3 });
var proj3 = CreateProjectFile(env, 3, new[] { 1 });
var projectsInCycle = new List<string> {entryProject.Path, proj3.Path, proj2.Path, entryProject.Path};
string expectedErrorMessage = GraphBuilder.FormatCircularDependencyError(projectsInCycle);
Should.Throw<CircularDependencyException>(() => new ProjectGraph(entryProject.Path)).Message.ShouldContain(expectedErrorMessage);
}
}
[Fact]
public void ConstructWithSelfLoop()
{
using (var env = TestEnvironment.Create())
{
TransientTestFile entryProject = CreateProjectFile(env, 1, new[] { 2, 3 });
CreateProjectFile(env, 2, new[] { 2 });
CreateProjectFile(env, 3);
Should.Throw<CircularDependencyException>(() => new ProjectGraph(entryProject.Path));
}
}
[Fact]
// graph with a cycle between 2->6->7->3->2
public void ConstructBigGraphWithCycle()
{
using (var env = TestEnvironment.Create())
{
TransientTestFile entryProject = CreateProjectFile(env, 1, new[] {2,3,4});
var proj2 = CreateProjectFile(env, 2, new[] {5, 6});
var proj3 = CreateProjectFile(env, 3, new[] {2, 8});
CreateProjectFile(env, 4);
CreateProjectFile(env, 5, new []{9, 10});
var proj6 = CreateProjectFile(env, 6, new[] { 7});
var proj7 = CreateProjectFile(env, 7, new[] { 3 });
CreateProjectFile(env, 8);
CreateProjectFile(env, 9);
CreateProjectFile(env, 10);
var projectsInCycle = new List<string> {proj2.Path, proj3.Path, proj7.Path, proj6.Path, proj2.Path };
var errorMessage = GraphBuilder.FormatCircularDependencyError(projectsInCycle);
Should.Throw<CircularDependencyException>(() => new ProjectGraph(entryProject.Path)).Message.ShouldContain(errorMessage);
}
}
[Fact]
public void ProjectCollectionShouldNotInfluenceGlobalProperties()
{
var entryFile1 = CreateProjectFile(_env, 1, new[] { 3, 4 });
var entryFile2 = CreateProjectFile(_env, 2, new []{ 4, 5 });
CreateProjectFile(_env, 3);
CreateProjectFile(_env, 4);
CreateProjectFile(_env, 5);
var entryPoint1 = new ProjectGraphEntryPoint(entryFile1.Path, new Dictionary<string, string> {["B"] = "EntryPointB", ["C"] = "EntryPointC"});
var entryPoint2 = new ProjectGraphEntryPoint(entryFile2.Path, null);
var collection = _env.CreateProjectCollection().Collection;
collection.SetGlobalProperty("A", "CollectionA");
collection.SetGlobalProperty("B", "CollectionB");
var graph = new ProjectGraph(
entryPoints: new[] { entryPoint1, entryPoint2 },
projectCollection: collection,
projectInstanceFactory: null);
var root1 = GetFirstNodeWithProjectNumber(graph, 1);
var globalPropertiesFor1 = new Dictionary<string, string> { ["B"] = "EntryPointB", ["C"] = "EntryPointC", ["IsGraphBuild"] = "true" };
root1.ProjectInstance.GlobalProperties.ShouldBeSameIgnoringOrder(globalPropertiesFor1);
root1.ProjectReferences.First(r => GetProjectNumber(r) == 3).ProjectInstance.GlobalProperties.ShouldBeSameIgnoringOrder(globalPropertiesFor1);
root1.ProjectReferences.First(r => GetProjectNumber(r) == 4).ProjectInstance.GlobalProperties.ShouldBeSameIgnoringOrder(globalPropertiesFor1);
var root2 = GetFirstNodeWithProjectNumber(graph, 2);
var globalPropertiesFor2 = new Dictionary<string, string> { ["IsGraphBuild"] = "true" };
root2.ProjectInstance.GlobalProperties.ShouldBeSameIgnoringOrder(globalPropertiesFor2);
root2.ProjectReferences.First(r => GetProjectNumber(r) == 4).ProjectInstance.GlobalProperties.ShouldBeSameIgnoringOrder(globalPropertiesFor2);
root2.ProjectReferences.First(r => GetProjectNumber(r) == 5).ProjectInstance.GlobalProperties.ShouldBeSameIgnoringOrder(globalPropertiesFor2);
}
[Fact]
public void ConstructWithDifferentGlobalProperties()
{
using (var env = TestEnvironment.Create())
{
TransientTestFile entryProject = CreateProjectFile(env, 1, new[] { 2, 3 });
env.CreateFile("2.proj", @"
<Project>
<ItemGroup>
<ProjectReference Include=""4.proj"" />
</ItemGroup>
</Project>");
env.CreateFile("3.proj", @"
<Project>
<ItemGroup>
<ProjectReference Include=""4.proj"" AdditionalProperties=""A=B"" />
</ItemGroup>
</Project>");
CreateProjectFile(env, 4);
ProjectGraph graph = new ProjectGraph(entryProject.Path);
// Project 4 requires 2 nodes
graph.ProjectNodes.Count.ShouldBe(5);
// Projects 2 and 3 both reference project 4, but with different properties, so they should not point to the same node.
GetFirstNodeWithProjectNumber(graph, 2).ProjectReferences.First().ShouldNotBe(GetFirstNodeWithProjectNumber(graph, 3).ProjectReferences.First());
GetFirstNodeWithProjectNumber(graph, 2).ProjectReferences.First().ProjectInstance.FullPath.ShouldEndWith("4.proj");
GetFirstNodeWithProjectNumber(graph, 2).ProjectReferences.First().ProjectInstance.GlobalProperties.ShouldBeSameIgnoringOrder(EmptyGlobalProperties);
GetFirstNodeWithProjectNumber(graph, 3).ProjectReferences.First().ProjectInstance.FullPath.ShouldEndWith("4.proj");
GetFirstNodeWithProjectNumber(graph, 3).ProjectReferences.First().ProjectInstance.GlobalProperties.Count.ShouldBeGreaterThan(1);
}
}
[Fact]
public void TestGlobalPropertiesInProjectReferences()
{
using (var env = TestEnvironment.Create())
{
TransientTestFile entryProject = env.CreateFile("1.proj", @"
<Project>
<ItemGroup>
<ProjectReference Include=""2.proj"" AdditionalProperties=""A=B""/>
</ItemGroup>
</Project>");
CreateProjectFile(env, 2, new[] { 3 });
CreateProjectFile(env, 3);
ProjectGraph graph = new ProjectGraph(entryProject.Path);
graph.ProjectNodes.Count.ShouldBe(3);
GetFirstNodeWithProjectNumber(graph, 3).ProjectInstance.GlobalProperties["A"].ShouldBe("B");
}
}
[Fact]
public void ConstructWithConvergingProperties()
{
using (var env = TestEnvironment.Create())
{
TransientTestFile entryProject = CreateProjectFile(env, 1, new[] { 2, 3 });
env.CreateFile("2.proj", @"
<Project>
<ItemGroup>
<ProjectReference Include=""4.proj"" AdditionalProperties=""Foo=A"" />
</ItemGroup>
</Project>");
env.CreateFile("3.proj", @"
<Project>
<ItemGroup>
<ProjectReference Include=""4.proj"" AdditionalProperties=""Foo=B"" />
</ItemGroup>
</Project>");
env.CreateFile("4.proj", @"
<Project>
<ItemGroup>
<ProjectReference Include=""5.proj"" GlobalPropertiesToRemove=""Foo"" />
</ItemGroup>
</Project>");
CreateProjectFile(env, 5);
ProjectGraph graph = new ProjectGraph(entryProject.Path);
// Project 4 requires 2 nodes, but project 5 does not
graph.ProjectNodes.Count.ShouldBe(6);
var node4A = GetFirstNodeWithProjectNumber(graph, 2).ProjectReferences.First();
var node4B = GetFirstNodeWithProjectNumber(graph, 3).ProjectReferences.First();
node4A.ShouldNotBe(node4B);
node4A.ProjectReferences.Count.ShouldBe(1);
node4B.ProjectReferences.Count.ShouldBe(1);
node4A.ProjectReferences.First().ShouldBe(node4B.ProjectReferences.First());
}
}
[Fact]
public void ConstructWithSameEffectiveProperties()
{
using (var env = TestEnvironment.Create())
{
TransientTestFile entryProject = CreateProjectFile(env, 1, new[] { 2, 3 });
env.CreateFile("2.proj", @"
<Project>
<ItemGroup>
<ProjectReference Include=""4.proj"" AdditionalProperties=""Foo=Bar"" />
</ItemGroup>
</Project>");
env.CreateFile("3.proj", @"
<Project>
<ItemGroup>
<ProjectReference Include=""4.proj"" GlobalPropertiesToRemove=""DoesNotExist"" />
</ItemGroup>
</Project>");
CreateProjectFile(env, 4);
ProjectGraph graph = new ProjectGraph(
entryProject.Path,
new Dictionary<string, string> { { "Foo", "Bar" } });
// Project 4 does not require 2 nodes
graph.ProjectNodes.Count.ShouldBe(4);
// The project references end up using the same effective properties
GetFirstNodeWithProjectNumber(graph, 2).ProjectReferences.First().ShouldBe(GetFirstNodeWithProjectNumber(graph, 3).ProjectReferences.First());
}
}
[Fact]
public void ConstructWithCaseDifferences()
{
using (var env = TestEnvironment.Create())
{
TransientTestFile entryProject = CreateProjectFile(env, 1, new[] { 2, 3, 4 });
env.CreateFile("2.proj", @"
<Project>
<ItemGroup>
<ProjectReference Include=""5.proj"" AdditionalProperties=""foo=bar"" />
</ItemGroup>
</Project>");
env.CreateFile("3.proj", @"
<Project>
<ItemGroup>
<ProjectReference Include=""5.proj"" AdditionalProperties=""FOO=bar"" />
</ItemGroup>
</Project>");
env.CreateFile("4.proj", @"
<Project>
<ItemGroup>
<ProjectReference Include=""5.proj"" AdditionalProperties=""foo=BAR"" />
</ItemGroup>
</Project>");
CreateProjectFile(env, 5);
ProjectGraph graph = new ProjectGraph(entryProject.Path);
// Project 5 requires 2 nodes
graph.ProjectNodes.Count.ShouldBe(6);
// Property names are case-insensitive, so projects 2 and 3 point to the same project 5 node.
GetFirstNodeWithProjectNumber(graph, 2).ProjectReferences.First().ShouldBe(GetFirstNodeWithProjectNumber(graph, 3).ProjectReferences.First());
GetFirstNodeWithProjectNumber(graph, 2).ProjectReferences.First().ProjectInstance.FullPath.ShouldEndWith("5.proj");
GetFirstNodeWithProjectNumber(graph, 2).ProjectReferences.First().ProjectInstance.GlobalProperties["FoO"].ShouldBe("bar");
// Property values are case-sensitive, so project 4 points to a different project 5 node than proejcts 2 and 3
GetFirstNodeWithProjectNumber(graph, 4).ProjectReferences.First().ShouldNotBe(GetFirstNodeWithProjectNumber(graph, 2).ProjectReferences.First());
GetFirstNodeWithProjectNumber(graph, 4).ProjectReferences.First().ProjectInstance.FullPath.ShouldEndWith("5.proj");
GetFirstNodeWithProjectNumber(graph, 4).ProjectReferences.First().ProjectInstance.GlobalProperties["FoO"].ShouldBe("BAR");
}
}
[Fact]
public void ConstructWithInvalidProperties()
{
using (var env = TestEnvironment.Create())
{
TransientTestFile entryProject = CreateProjectFile(env, 1, new[] { 2 });
env.CreateFile("2.proj", @"
<Project>
<ItemGroup>
<ProjectReference Include=""3.proj"" AdditionalProperties=""ThisIsntValid"" />
</ItemGroup>
</Project>");
CreateProjectFile(env, 3);
Should.Throw<InvalidProjectFileException>(() => new ProjectGraph(entryProject.Path));
}
}
[Fact]
public void ConstructWithMultipleEntryPoints()
{
using (var env = TestEnvironment.Create())
{
TransientTestFile entryProject1 = CreateProjectFile(env, 1, new[] { 3 });
TransientTestFile entryProject2 = CreateProjectFile(env, 2, new[] { 3 });
CreateProjectFile(env, 3);
var projectGraph = new ProjectGraph(new [] { entryProject1.Path, entryProject2.Path });
projectGraph.ProjectNodes.Count.ShouldBe(3);
var node1 = GetFirstNodeWithProjectNumber(projectGraph, 1);
var node2 = GetFirstNodeWithProjectNumber(projectGraph, 2);
var node3 = GetFirstNodeWithProjectNumber(projectGraph, 3);
node1.ProjectReferences.Count.ShouldBe(1);
node1.ProjectReferences.First().ShouldBe(node3);
node2.ProjectReferences.Count.ShouldBe(1);
node2.ProjectReferences.First().ShouldBe(node3);
}
}
[Fact]
public void ConstructWithMultipleEntryPointsWithDifferentGlobalProperties()
{
using (var env = TestEnvironment.Create())
{
TransientTestFile entryProject = CreateProjectFile(env, 1, new[] { 2 });
CreateProjectFile(env, 2);
var entryPoint1 = new ProjectGraphEntryPoint(entryProject.Path, new Dictionary<string, string> { { "Platform", "x86" } });
var entryPoint2 = new ProjectGraphEntryPoint(entryProject.Path, new Dictionary<string, string> { { "Platform", "x64" } });
var projectGraph = new ProjectGraph(new[] { entryPoint1, entryPoint2 });
projectGraph.ProjectNodes.Count.ShouldBe(4);
projectGraph.EntryPointNodes.Count.ShouldBe(2);
var entryPointNode1 = projectGraph.EntryPointNodes.First();
var entryPointNode2 = projectGraph.EntryPointNodes.Last();
// The entry points should not be the same node, but should point to the same project
entryPointNode1.ShouldNotBe(entryPointNode2);
entryPointNode1.ProjectInstance.FullPath.ShouldBe(entryPointNode2.ProjectInstance.FullPath);
entryPointNode1.ProjectInstance.GlobalProperties["Platform"].ShouldBe("x86");
entryPointNode2.ProjectInstance.GlobalProperties["Platform"].ShouldBe("x64");
// The entry points should not have the same project reference, but should point to the same project reference file
entryPointNode1.ProjectReferences.Count.ShouldBe(1);
entryPointNode2.ProjectReferences.Count.ShouldBe(1);
entryPointNode1.ProjectReferences.First().ShouldNotBe(entryPointNode2.ProjectReferences.First());
entryPointNode1.ProjectReferences.First().ProjectInstance.FullPath.ShouldBe(entryPointNode2.ProjectReferences.First().ProjectInstance.FullPath);
entryPointNode1.ProjectReferences.First().ProjectInstance.GlobalProperties["Platform"].ShouldBe("x86");
entryPointNode2.ProjectReferences.First().ProjectInstance.GlobalProperties["Platform"].ShouldBe("x64");
}
}
[Fact]
public void ConstructWithMultipleEntryPointsWithDifferentGlobalPropertiesConverging()
{
using (var env = TestEnvironment.Create())
{
TransientTestFile entryProject = env.CreateFile("1.proj", @"
<Project>
<ItemGroup>
<ProjectReference Include=""2.proj"" GlobalPropertiesToRemove=""Platform"" />
</ItemGroup>
</Project>");
CreateProjectFile(env, 2);
var entryPoint1 = new ProjectGraphEntryPoint(entryProject.Path, new Dictionary<string, string> { { "Platform", "x86" } });
var entryPoint2 = new ProjectGraphEntryPoint(entryProject.Path, new Dictionary<string, string> { { "Platform", "x64" } });
var projectGraph = new ProjectGraph(new[] { entryPoint1, entryPoint2 });
projectGraph.ProjectNodes.Count.ShouldBe(3);
projectGraph.EntryPointNodes.Count.ShouldBe(2);
var entryPointNode1 = projectGraph.EntryPointNodes.First();
var entryPointNode2 = projectGraph.EntryPointNodes.Last();
// The entry points should not be the same node, but should point to the same project
entryPointNode1.ShouldNotBe(entryPointNode2);
entryPointNode1.ProjectInstance.FullPath.ShouldBe(entryPointNode2.ProjectInstance.FullPath);
entryPointNode1.ProjectInstance.GlobalProperties["Platform"].ShouldBe("x86");
entryPointNode2.ProjectInstance.GlobalProperties["Platform"].ShouldBe("x64");
// The entry points should have the same project reference since they're platform-agnostic
entryPointNode1.ProjectReferences.Count.ShouldBe(1);
entryPointNode2.ProjectReferences.Count.ShouldBe(1);
entryPointNode1.ProjectReferences.First().ShouldBe(entryPointNode2.ProjectReferences.First());
entryPointNode1.ProjectReferences.First().ProjectInstance.GlobalProperties.ContainsKey("Platform").ShouldBeFalse();
}
}
[Fact]
public void ConstructGraphWithDifferentEntryPointsAndGraphRoots()
{
using(var env = TestEnvironment.Create())
{
TransientTestFile entryProject1 = CreateProjectFile(env, 1, new[] { 4 });
TransientTestFile entryProject2 = CreateProjectFile(env, 2, new[] { 4, 5 });
TransientTestFile entryProject3 = CreateProjectFile(env, 3, new[] { 2, 6 });
CreateProjectFile(env, 4);
CreateProjectFile(env, 5);
CreateProjectFile(env, 6);
var projectGraph = new ProjectGraph(new[] { entryProject1.Path, entryProject2.Path, entryProject3.Path });
projectGraph.EntryPointNodes.Count.ShouldBe(3);
projectGraph.GraphRoots.Count.ShouldBe(2);
projectGraph.GraphRoots.ShouldNotContain(GetFirstNodeWithProjectNumber(projectGraph, 2));
}
}
[Fact]
public void GetTargetListsAggregatesFromMultipleEdges()
{
using (var env = TestEnvironment.Create())
{
TransientTestFile entryProject = CreateProjectFile(env: env, projectNumber: 1, projectReferences: new[] { 2, 3 }, projectReferenceTargets: new Dictionary<string, string[]> { { "A", new[] { "B" } } });
CreateProjectFile(env: env, projectNumber: 2, projectReferences: new[] { 4 }, projectReferenceTargets: new Dictionary<string, string[]> { { "B", new[] { "C" } } });
CreateProjectFile(env: env, projectNumber: 3, projectReferences: new[] { 4 }, projectReferenceTargets: new Dictionary<string, string[]> { { "B", new[] { "D" } } });
CreateProjectFile(env: env, projectNumber: 4);
var projectGraph = new ProjectGraph(entryProject.Path);
projectGraph.ProjectNodes.Count.ShouldBe(4);
IReadOnlyDictionary<ProjectGraphNode, ImmutableList<string>> targetLists = projectGraph.GetTargetLists(new[] { "A" });
targetLists.Count.ShouldBe(projectGraph.ProjectNodes.Count);
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 1)].ShouldBe(new[] { "A" });
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 2)].ShouldBe(new[] { "B" });
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 3)].ShouldBe(new[] { "B" });
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 4)].ShouldBe(new[] { "C", "D" }); // From B => C and B => D
}
}
[Fact]
public void GetTargetListsDedupesTargets()
{
var projectReferenceTargets = new Dictionary<string, string[]>
{
{ "A" , new[] { "B", "X", "C" } },
{ "B" , new[] { "X", "Y" } },
{ "C" , new[] { "X", "Z" } },
};
using (var env = TestEnvironment.Create())
{
TransientTestFile entryProject = CreateProjectFile(env: env, projectNumber: 1, projectReferences: new[] { 2 }, projectReferenceTargets: projectReferenceTargets);
CreateProjectFile(env: env, projectNumber: 2, projectReferences: new[] { 3 }, projectReferenceTargets: projectReferenceTargets);
CreateProjectFile(env: env, projectNumber: 3, projectReferences: Array.Empty<int>(), projectReferenceTargets: projectReferenceTargets);
var projectGraph = new ProjectGraph(entryProject.Path);
projectGraph.ProjectNodes.Count.ShouldBe(3);
IReadOnlyDictionary<ProjectGraphNode, ImmutableList<string>> targetLists = projectGraph.GetTargetLists(new[] { "A" });
targetLists.Count.ShouldBe(projectGraph.ProjectNodes.Count);
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 1)].ShouldBe(new[] { "A" });
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 2)].ShouldBe(new[] { "B", "X", "C" });
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 3)].ShouldBe(new[] { "X", "Y", "Z" }); // Simplified from X, Y, X, Z
}
}
[Fact]
public void GetTargetListsForComplexGraph()
{
var projectReferenceTargets = new Dictionary<string, string[]>
{
{ "A" , new[] { "B" } },
{ "B" , new[] { "C" } },
{ "C" , new[] { "D" } },
{ "D" , new[] { "E" } },
};
using (var env = TestEnvironment.Create())
{
TransientTestFile entryProject = CreateProjectFile(env: env, projectNumber: 1, projectReferences: new[] { 2, 3, 5 }, projectReferenceTargets: projectReferenceTargets);
CreateProjectFile(env: env, projectNumber: 2, projectReferences: new[] { 4, 5 }, projectReferenceTargets: projectReferenceTargets);
CreateProjectFile(env: env, projectNumber: 3, projectReferences: new[] { 5, 6 }, projectReferenceTargets: projectReferenceTargets);
CreateProjectFile(env: env, projectNumber: 4, projectReferences: new[] { 5 }, projectReferenceTargets: projectReferenceTargets);
CreateProjectFile(env: env, projectNumber: 5, projectReferences: new[] { 6 }, projectReferenceTargets: projectReferenceTargets);
CreateProjectFile(env: env, projectNumber: 6, projectReferences: Array.Empty<int>(), projectReferenceTargets: projectReferenceTargets);
var projectGraph = new ProjectGraph(entryProject.Path);
projectGraph.ProjectNodes.Count.ShouldBe(6);
IReadOnlyDictionary<ProjectGraphNode, ImmutableList<string>> targetLists = projectGraph.GetTargetLists(new[] { "A" });
targetLists.Count.ShouldBe(projectGraph.ProjectNodes.Count);
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 1)].ShouldBe(new[] { "A" });
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 2)].ShouldBe(new[] { "B" });
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 3)].ShouldBe(new[] { "B" });
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 4)].ShouldBe(new[] { "C" });
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 5)].ShouldBe(new[] { "B", "C", "D" });
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 6)].ShouldBe(new[] { "C", "D", "E" });
}
}
[Fact]
public void GetTargetListsNullEntryTargets()
{
using (var env = TestEnvironment.Create())
{
TransientTestFile entryProject = CreateProjectFile(env: env, projectNumber: 1, projectReferences: new[] { 2 }, projectReferenceTargets: new Dictionary<string, string[]> { { "A", new[] { "B" } } }, defaultTargets: "A");
CreateProjectFile(env: env, projectNumber: 2);
var projectGraph = new ProjectGraph(entryProject.Path);
projectGraph.ProjectNodes.Count.ShouldBe(2);
IReadOnlyDictionary<ProjectGraphNode, ImmutableList<string>> targetLists = projectGraph.GetTargetLists(null);
targetLists.Count.ShouldBe(projectGraph.ProjectNodes.Count);
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 1)].ShouldBe(new[] { "A" });
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 2)].ShouldBe(new[] { "B" });
}
}
[Fact]
public void GetTargetsListsShouldApplyDefaultTargetsOnlyToGraphRoots()
{
using (var env = TestEnvironment.Create())
{
var root1 = CreateProjectFile(env: env, projectNumber: 1, projectReferences: new[] {2}, projectReferenceTargets: new Dictionary<string, string[]> {{"A", new[] {"B"}}}, defaultTargets: "A").Path;
var root2 = CreateProjectFile(env: env, projectNumber: 2, projectReferences: new[] {3}, projectReferenceTargets: new Dictionary<string, string[]> {{"B", new[] {"C"}}, {"X", new[] {"Y"}}}, defaultTargets: "X").Path;
CreateProjectFile(env: env, projectNumber: 3);
var projectGraph = new ProjectGraph(new []{root1, root2});
projectGraph.ProjectNodes.Count.ShouldBe(3);
IReadOnlyDictionary<ProjectGraphNode, ImmutableList<string>> targetLists = projectGraph.GetTargetLists(null);
targetLists.Count.ShouldBe(projectGraph.ProjectNodes.Count);
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 1)].ShouldBe(new[] { "A" });
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 2)].ShouldBe(new[] { "B" });
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 3)].ShouldBe(new[] { "C" });
}
}
[Fact]
public void GetTargetsListReturnsEmptyTargetsForNodeIfNoTargetsPropagatedToIt()
{
using (var env = TestEnvironment.Create())
{
TransientTestFile entryProject = CreateProjectFile(env: env, projectNumber: 1, projectReferences: new[] { 2 }, projectReferenceTargets: new Dictionary<string, string[]> { { "A", new []{ "B" }} }, defaultTargets: "A");
CreateProjectFile(env: env, projectNumber: 2);
var projectGraph = new ProjectGraph(entryProject.Path);
projectGraph.ProjectNodes.Count.ShouldBe(2);
IReadOnlyDictionary<ProjectGraphNode, ImmutableList<string>> targetLists = projectGraph.GetTargetLists(new []{ "Foo" });
targetLists.Count.ShouldBe(projectGraph.ProjectNodes.Count);
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 1)].ShouldBe(new []{ "Foo" });
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 2)].ShouldBeEmpty();
}
}
[Fact]
public void GetTargetListsReturnsEmptyTargetsForAllNodesWhenDefaultTargetsAreRequestedAndThereAreNoDefaultTargets()
{
using (var env = TestEnvironment.Create())
{
// Root project has no default targets.
// The project file does not contain any targets
TransientTestFile entryProject = CreateProjectFile(env: env, projectNumber: 1, projectReferences: new[] { 2 }, projectReferenceTargets: new Dictionary<string, string[]> { { "A", new[] { "B" } }}, defaultTargets: string.Empty);
// Dependency has default targets. Even though it gets called with empty targets, B will not get called,
// because target propagation only equates empty targets to default targets for the root nodes.
CreateProjectFile(env: env, projectNumber: 2, defaultTargets: "B");
var projectGraph = new ProjectGraph(entryProject.Path);
projectGraph.ProjectNodes.Count.ShouldBe(2);
IReadOnlyDictionary<ProjectGraphNode, ImmutableList<string>> targetLists = projectGraph.GetTargetLists(null);
targetLists.Count.ShouldBe(projectGraph.ProjectNodes.Count);
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 1)].ShouldBeEmpty();
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 2)].ShouldBeEmpty();
}
}
[Fact]
public void GetTargetListsDoesNotPropagateEmptyTargets()
{
using (var env = TestEnvironment.Create())
{
// Target protocol produces empty target
// The project file also does not contain any targets
TransientTestFile entryProject = CreateProjectFile(env: env, projectNumber: 1, projectReferences: new[] { 2 }, projectReferenceTargets: new Dictionary<string, string[]> { { "A", new[] { " ; ; " } }}, defaultTargets: string.Empty);
// Dependency has default targets. Even though it gets called with empty targets, B will not get called,
// because target propagation only equates empty targets to default targets for the root nodes.
CreateProjectFile(env: env, projectNumber: 2, defaultTargets: "B");
var projectGraph = new ProjectGraph(entryProject.Path);
projectGraph.ProjectNodes.Count.ShouldBe(2);
IReadOnlyDictionary<ProjectGraphNode, ImmutableList<string>> targetLists = projectGraph.GetTargetLists(new []{ "A" });
targetLists.Count.ShouldBe(projectGraph.ProjectNodes.Count);
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 1)].ShouldBe(new []{ "A" });
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 2)].ShouldBeEmpty();
}
}
[Fact]
public void GetTargetListsThrowsOnInvalidTargetNames()
{
using (var env = TestEnvironment.Create())
{
TransientTestFile entryProject = CreateProjectFile(env: env, projectNumber: 1);
var projectGraph = new ProjectGraph(entryProject.Path);
projectGraph.ProjectNodes.Count.ShouldBe(1);
Should.Throw<ArgumentException>(() => projectGraph.GetTargetLists(new []{ " " }));
}
}
[Fact]
public void GetTargetListsUsesAllTargetsForNonMultitargetingNodes()
{
using (var env = TestEnvironment.Create())
{
var root1 = CreateProjectFile(
env: env,
projectNumber: 1,
projectReferences: new[] {2},
projectReferenceTargets: null,
defaultTargets: null,
extraContent: ProjectReferenceTargetsWithMultitargeting)
.Path;
CreateProjectFile(env, 2);
var projectGraph = new ProjectGraph(root1);
var dot = projectGraph.ToDot();
projectGraph.ProjectNodes.Count.ShouldBe(2);
IReadOnlyDictionary<ProjectGraphNode, ImmutableList<string>> targetLists = projectGraph.GetTargetLists(new List<string>{"A"});
targetLists.Count.ShouldBe(projectGraph.ProjectNodes.Count);
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 1)].ShouldBe(new[] { "A" });
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 2)].ShouldBe(NonOuterBuildTargets);
}
}
[Fact]
public void GetTargetsListInnerBuildToInnerBuild()
{
using (var env = TestEnvironment.Create())
{
string singleTargetedSpec = OuterBuildSpecificationWithProjectReferenceTargets +
$@"<PropertyGroup>
<{InnerBuildPropertyName}>a</{InnerBuildPropertyName}>
</PropertyGroup>";
var root1 =CreateProjectFile(
env: env,
projectNumber: 1,
projectReferences: new[] {2},
projectReferenceTargets: null,
defaultTargets: null,
extraContent: singleTargetedSpec)
.Path;
CreateProjectFile(
env: env,
projectNumber: 2,
projectReferences: null,
projectReferenceTargets: null,
defaultTargets: null,
extraContent: singleTargetedSpec);
var projectGraph = new ProjectGraph(root1);
var dot = projectGraph.ToDot();
projectGraph.ProjectNodes.Count.ShouldBe(2);
IReadOnlyDictionary<ProjectGraphNode, ImmutableList<string>> targetLists = projectGraph.GetTargetLists(new List<string>{"A"});
targetLists.Count.ShouldBe(projectGraph.ProjectNodes.Count);
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 1)].ShouldBe(new[] { "A" });
targetLists[GetFirstNodeWithProjectNumber(projectGraph, 2)].ShouldBe(NonOuterBuildTargets);
}
}
[Fact]
public void GetTargetListsFiltersTargetsForOuterAndInnerBuilds()
{
using (var env = TestEnvironment.Create())
{
var root1 = CreateProjectFile(
env: env,
projectNumber: 1,
projectReferences: new[] { 2 },
projectReferenceTargets: null,
defaultTargets: null,
extraContent: ProjectReferenceTargetsWithMultitargeting).Path;
CreateProjectFile(
env: env,
projectNumber: 2,
projectReferences: null,
projectReferenceTargets: null,
defaultTargets: null,
extraContent: OuterBuildSpecificationWithProjectReferenceTargets);
var projectGraph = new ProjectGraph(root1);
var dot = projectGraph.ToDot();
projectGraph.ProjectNodes.Count.ShouldBe(4);
IReadOnlyDictionary<ProjectGraphNode, ImmutableList<string>> targetLists = projectGraph.GetTargetLists(new List<string>{"A"});
targetLists.Count.ShouldBe(projectGraph.ProjectNodes.Count);
var root = GetFirstNodeWithProjectNumber(projectGraph, 1);
var outerBuild = GetOuterBuild(projectGraph, 2);
var innerBuilds = GetInnerBuilds(projectGraph, 2).ToArray();
targetLists[root].ShouldBe(new[] { "A" });
targetLists[outerBuild].ShouldBe(OuterBuildTargets);
foreach (var innerBuild in innerBuilds)
{
targetLists[innerBuild].ShouldBe(NonOuterBuildTargets);
}
}
}
[Fact]
public void GetTargetListsDoesNotUseTargetsMetadataOnInnerBuildsFromRootOuterBuilds()
{
var projectReferenceTargetsProtocol =
$@"<ItemGroup>
<ProjectReferenceTargets Include='A' Targets='{MSBuildConstants.ProjectReferenceTargetsOrDefaultTargetsMarker};A;AInner' />
<ProjectReferenceTargets Include='A' Targets='{MSBuildConstants.ProjectReferenceTargetsOrDefaultTargetsMarker};A;AOuter' OuterBuild='true' />
</ItemGroup>";
var entryProject = CreateProjectFile(
env: _env,
projectNumber: 1,
projectReferences: null,
projectReferenceTargets: null,
defaultTargets: "D1",
extraContent: MultitargetingSpecificationPropertyGroup +
projectReferenceTargetsProtocol +
$@"
<ItemGroup>
<ProjectReference Include='2.proj' Targets='T2' />
</ItemGroup>
"
).Path;
CreateProjectFile(
env: _env,
projectNumber: 2,
projectReferences: null,