Skip to content

Commit a3a7cc0

Browse files
[release/11.0.1xx] Source code updates from dotnet/msbuild (#9462)
[release/11.0.1xx] Source code updates from dotnet/msbuild
1 parent c90f609 commit a3a7cc0

59 files changed

Lines changed: 4689 additions & 1539 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/msbuild/documentation/wiki/ChangeWaves.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ Change wave checks around features will be removed in the release that accompani
3838
### 18.12
3939
- [TaskHosts used to run a task out of process under `-mt` stay connected to the process that launched them and exit with it, instead of remaining available for any other process to reuse. TaskHosts of a different runtime or architecture are unaffected.](https://github.com/dotnet/msbuild/pull/14584)
4040
- [Events that a task logs from a TaskHost - extended errors, warnings and messages, critical messages, telemetry, and any other event kind the router did not enumerate - reach the parent process instead of being dropped.](https://github.com/dotnet/msbuild/pull/14876)
41+
- [RAR writes one structured search event for each reference instead of one message for each rejected assembly candidate.](https://github.com/dotnet/msbuild/pull/14599) This change reduces binary-log size. The event's default message uses the invariant culture, while the console and terminal loggers render it using the current UI culture. Set `MSBUILDDISABLEFEATURESFROMVERSION=18.12` to retain individual candidate messages.
42+
- RAR now logs structured events for version-conflict dependency details. These events replace large text messages for MSB3277 warnings and low-importance diagnostics.
43+
- The events contain victor and victim identities, dependency chains, and source items.
44+
- Events render invariant English messages from their structured data without transmitting localized format strings. Built-in user-facing loggers re-render them in the active UI culture; other consumers can use the structured fields to do the same.
45+
- Strict readers older than binary-log format 28 reject the newer format. Forward-compatible readers skip the structured conflict records.
46+
- Set `MSBUILDDISABLEFEATURESFROMVERSION=18.12` to restore the legacy localized plain-text events.
4147

4248
### 18.11
4349
- [XmlPeek, XmlPoke, and XslTransformation default to prohibiting embedded DTDs](https://github.com/dotnet/msbuild/pull/14285)
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Globalization;
6+
using System.IO;
7+
using System.Text;
8+
using Microsoft.Build.BackEnd.Logging;
9+
using Microsoft.Build.Framework;
10+
using Microsoft.Build.Logging;
11+
using Shouldly;
12+
using Xunit;
13+
14+
namespace Microsoft.Build.UnitTests;
15+
16+
public class AssemblyConflictLogger_Tests
17+
{
18+
[Fact]
19+
public void ConsoleLoggerLocalizesStructuredConflictMessages()
20+
{
21+
(AssemblyConflictDependencyDetailsMessageEventArgs details, AssemblyConflictWarningEventArgs warning) = CreateEvents();
22+
var output = new StringBuilder();
23+
var eventSource = new EventSourceSink();
24+
var logger = new ConsoleLogger(LoggerVerbosity.Diagnostic, message => output.Append(message), null, null);
25+
logger.Initialize(eventSource);
26+
27+
WithFrenchUICulture(() =>
28+
{
29+
eventSource.Consume(details);
30+
AssertFrenchDetailsOutput(output.ToString(), details);
31+
output.Clear();
32+
eventSource.Consume(warning);
33+
});
34+
35+
AssertFrenchWarningOutput(output.ToString(), warning);
36+
}
37+
38+
[Fact]
39+
public void TerminalLoggerLocalizesStructuredConflictMessages()
40+
{
41+
(AssemblyConflictDependencyDetailsMessageEventArgs details, AssemblyConflictWarningEventArgs warning) = CreateEvents();
42+
using var output = new StringWriter();
43+
using var terminal = new Terminal(output);
44+
var eventSource = new EventSourceSink();
45+
var logger = new TerminalLogger(terminal)
46+
{
47+
Verbosity = LoggerVerbosity.Diagnostic,
48+
};
49+
logger.Initialize(eventSource, nodeCount: 1);
50+
51+
WithFrenchUICulture(() =>
52+
{
53+
eventSource.Consume(details);
54+
eventSource.Consume(warning);
55+
});
56+
57+
AssertFrenchWarningOutput(output.ToString(), warning);
58+
details.IsMessageMaterialized.ShouldBeFalse();
59+
}
60+
61+
private static void AssertFrenchDetailsOutput(
62+
string output,
63+
AssemblyConflictDependencyDetailsMessageEventArgs details)
64+
{
65+
output.ShouldContain("Références qui dépendent de");
66+
output.ShouldContain("Item Include d'un fichier projet");
67+
output.ShouldNotContain("References which depend on");
68+
output.ShouldNotContain("Project file item includes");
69+
details.IsMessageMaterialized.ShouldBeFalse();
70+
}
71+
72+
private static void AssertFrenchWarningOutput(
73+
string output,
74+
AssemblyConflictWarningEventArgs warning)
75+
{
76+
output.ShouldContain("Conflit existant entre");
77+
output.ShouldContain("détection de conflits non résolus");
78+
output.ShouldContain("Références qui dépendent de");
79+
output.ShouldContain("Item Include d'un fichier projet");
80+
output.ShouldNotContain("There was a conflict between");
81+
output.ShouldNotContain("Found conflicts between different versions");
82+
warning.IsMessageMaterialized.ShouldBeFalse();
83+
}
84+
85+
private static void WithFrenchUICulture(Action action)
86+
{
87+
CultureInfo originalUICulture = CultureInfo.CurrentUICulture;
88+
try
89+
{
90+
CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo("fr-FR");
91+
action();
92+
}
93+
finally
94+
{
95+
CultureInfo.CurrentUICulture = originalUICulture;
96+
}
97+
}
98+
99+
internal static (AssemblyConflictDependencyDetailsMessageEventArgs, AssemblyConflictWarningEventArgs) CreateEvents()
100+
{
101+
var victor = new AssemblyConflictReferenceDetails(
102+
"D, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null",
103+
@"C:\libs\v2\D.dll",
104+
isPrimary: true,
105+
isResolved: true,
106+
unresolvedPrimaryItemSpec: null,
107+
primarySourceItemSpecs: ["D"],
108+
dependees: []);
109+
110+
var victim = new AssemblyConflictReferenceDetails(
111+
"D, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
112+
@"C:\libs\v1\D.dll",
113+
isPrimary: false,
114+
isResolved: true,
115+
unresolvedPrimaryItemSpec: null,
116+
primarySourceItemSpecs: [],
117+
dependees: [new AssemblyConflictDependee(@"C:\libs\B.dll", ["B"])]);
118+
119+
var details = new AssemblyConflictDependencyDetailsMessageEventArgs(
120+
victor,
121+
victim,
122+
"ResolveAssemblyReference",
123+
MessageImportance.Low,
124+
DateTime.UtcNow);
125+
126+
var warning = new AssemblyConflictWarningEventArgs(
127+
"D",
128+
AssemblyConflictLossReason.WasNotPrimary,
129+
victor,
130+
victim,
131+
"MSB3277",
132+
file: null,
133+
lineNumber: 0,
134+
columnNumber: 0,
135+
helpKeyword: "MSBuild.ResolveAssemblyReference.FoundConflicts",
136+
senderName: "ResolveAssemblyReference",
137+
eventTimestamp: DateTime.UtcNow);
138+
139+
var context = new BuildEventContext(1, 2, 3, 4);
140+
details.BuildEventContext = context;
141+
warning.BuildEventContext = context;
142+
143+
return (details, warning);
144+
}
145+
}

‎src/msbuild/src/Build.UnitTests/BackEnd/LoggingService_Tests.cs‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections;
66
using System.Collections.Generic;
7+
using System.Globalization;
78
using System.Linq;
89
using System.Reflection;
910
using System.Threading;
@@ -885,6 +886,35 @@ public void TreatWarningsAsMessagesWhenSpecified(int loggerMode, int nodeId)
885886
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.Timestamp, actualBuildEvent.Timestamp);
886887
}
887888

889+
[Theory]
890+
[InlineData(false)]
891+
[InlineData(true)]
892+
public void StructuredConflictWarningTransformationUsesCurrentUICulture(bool treatAsError)
893+
{
894+
CultureInfo originalUICulture = CultureInfo.CurrentUICulture;
895+
try
896+
{
897+
CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo("fr-FR");
898+
AssemblyConflictWarningEventArgs warning = AssemblyConflictLogger_Tests.CreateEvents().Item2;
899+
var warnings = new HashSet<string> { warning.Code };
900+
901+
MockLogger logger = GetLoggedEventsWithWarningsAsErrorsOrMessages(
902+
warning,
903+
warningsAsErrors: treatAsError ? warnings : null,
904+
warningsAsMessages: treatAsError ? null : warnings);
905+
906+
BuildEventArgs transformedEvent = treatAsError
907+
? logger.Errors.ShouldHaveSingleItem()
908+
: logger.BuildMessageEvents.ShouldHaveSingleItem();
909+
transformedEvent.Message.ShouldStartWith("détection de conflits non résolus");
910+
warning.IsMessageMaterialized.ShouldBeFalse();
911+
}
912+
finally
913+
{
914+
CultureInfo.CurrentUICulture = originalUICulture;
915+
}
916+
}
917+
888918
/// <summary>
889919
/// Verifies that a warning is not treated as a low importance message when other warning codes are specified.
890920
/// </summary>

‎src/msbuild/src/Build.UnitTests/BackEnd/NodePackets_Tests.cs‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ public void VerifyEventType()
8383
BuildCanceledEventArgs buildCanceled = new("message", DateTime.UtcNow);
8484
WorkerNodeTelemetryEventArgs workerNodeTelemetry = new();
8585
LoggersRegisteredEventArgs loggersRegistered = new(new List<RegisteredLoggerInfo> { new RegisteredLoggerInfo("FileLogger", new[] { @"C:\logs\build.log" }) });
86+
AssemblyResolutionSearchTraceEventArgs assemblyResolutionSearch = CreateAssemblyResolutionSearch();
87+
AssemblyConflictDependencyDetailsMessageEventArgs assemblyConflictDependencyDetails = CreateAssemblyConflictDependencyDetails();
88+
AssemblyConflictWarningEventArgs assemblyConflictWarning = CreateAssemblyConflictWarning();
8689

8790
VerifyLoggingPacket(buildFinished, LoggingEventType.BuildFinishedEvent);
8891
VerifyLoggingPacket(buildStarted, LoggingEventType.BuildStartedEvent);
@@ -121,6 +124,9 @@ public void VerifyEventType()
121124
VerifyLoggingPacket(buildCanceled, LoggingEventType.BuildCanceledEvent);
122125
VerifyLoggingPacket(workerNodeTelemetry, LoggingEventType.WorkerNodeTelemetryEvent);
123126
VerifyLoggingPacket(loggersRegistered, LoggingEventType.LoggersRegisteredEvent);
127+
VerifyLoggingPacket(assemblyResolutionSearch, LoggingEventType.AssemblyResolutionSearchTraceEvent);
128+
VerifyLoggingPacket(assemblyConflictDependencyDetails, LoggingEventType.AssemblyConflictDependencyDetailsEvent);
129+
VerifyLoggingPacket(assemblyConflictWarning, LoggingEventType.AssemblyConflictWarningEvent);
124130
}
125131

126132
private static BuildEventContext CreateBuildEventContext()
@@ -338,6 +344,9 @@ public void TestTranslation()
338344
verbosity: LoggerVerbosity.Diagnostic,
339345
parameters: "LogFile=a.log;LogFile=b.log"),
340346
}),
347+
CreateAssemblyResolutionSearch(),
348+
CreateAssemblyConflictDependencyDetails(),
349+
CreateAssemblyConflictWarning(),
341350
};
342351
foreach (BuildEventArgs arg in testArgs)
343352
{
@@ -367,6 +376,78 @@ public void TestTranslation()
367376
}
368377
}
369378

379+
private static AssemblyResolutionSearchTraceEventArgs CreateAssemblyResolutionSearch()
380+
=> new(
381+
"Requested, Version=1.0.0.0",
382+
"MSIL",
383+
[
384+
new AssemblyResolutionSearchAttempt(
385+
"first.dll",
386+
"search-path",
387+
"parent.dll",
388+
"Candidate, Version=2.0.0.0",
389+
AssemblyResolutionSearchResult.FusionNamesDidNotMatch,
390+
processorArchitecture: null,
391+
logAssemblyFoldersEx: true),
392+
new AssemblyResolutionSearchAttempt(
393+
"second.dll",
394+
"search-path",
395+
"parent.dll",
396+
assemblyName: null,
397+
AssemblyResolutionSearchResult.TargetHadNoFusionName,
398+
processorArchitecture: null,
399+
logAssemblyFoldersEx: true),
400+
],
401+
"ResolveAssemblyReference",
402+
MessageImportance.Low,
403+
DateTime.UtcNow);
404+
405+
private static AssemblyConflictReferenceDetails CreateAssemblyConflictVictorDetails()
406+
=> new(
407+
"D, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
408+
"/libs/v1/D.dll",
409+
isPrimary: true,
410+
isResolved: true,
411+
unresolvedPrimaryItemSpec: null,
412+
primarySourceItemSpecs: ["D"],
413+
dependees: []);
414+
415+
private static AssemblyConflictReferenceDetails CreateAssemblyConflictVictimDetails()
416+
=> new(
417+
"D, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null",
418+
"/libs/v2/D.dll",
419+
isPrimary: false,
420+
isResolved: true,
421+
unresolvedPrimaryItemSpec: null,
422+
primarySourceItemSpecs: [],
423+
dependees: [new AssemblyConflictDependee("/libs/B.dll", ["B"])]);
424+
425+
private static AssemblyConflictDependencyDetailsMessageEventArgs CreateAssemblyConflictDependencyDetails()
426+
=> new(
427+
CreateAssemblyConflictVictorDetails(),
428+
CreateAssemblyConflictVictimDetails(),
429+
"ResolveAssemblyReference",
430+
MessageImportance.Low,
431+
DateTime.UtcNow);
432+
433+
private static AssemblyConflictWarningEventArgs CreateAssemblyConflictWarning()
434+
{
435+
AssemblyConflictReferenceDetails victor = CreateAssemblyConflictVictorDetails();
436+
AssemblyConflictReferenceDetails victim = CreateAssemblyConflictVictimDetails();
437+
return new(
438+
"D",
439+
AssemblyConflictLossReason.WasNotPrimary,
440+
victor,
441+
victim,
442+
"MSB3277",
443+
@"C:\foo\bar.proj",
444+
42,
445+
7,
446+
"MSBuild.ResolveAssemblyReference.FoundConflicts",
447+
"ResolveAssemblyReference",
448+
DateTime.UtcNow);
449+
}
450+
370451
/// <summary>
371452
/// Verify the LoggingMessagePacket is properly created from a build event.
372453
/// This includes the packet type and the event type depending on which build event arg is passed in.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using Microsoft.Build.BackEnd;
7+
using Microsoft.Build.Framework;
8+
using Shouldly;
9+
using Xunit;
10+
11+
#nullable disable
12+
13+
namespace Microsoft.Build.UnitTests.BackEnd
14+
{
15+
public class TaskHostTask_Tests
16+
{
17+
[Fact]
18+
public void HandlesAssemblyResolutionSearchTraceEvent()
19+
{
20+
var buildEngine = new MockEngine();
21+
var searchEvent = new AssemblyResolutionSearchTraceEventArgs(
22+
"Requested",
23+
targetProcessorArchitecture: null,
24+
[
25+
new AssemblyResolutionSearchAttempt(
26+
"candidate.dll",
27+
"search-path",
28+
parentAssembly: null,
29+
assemblyName: null,
30+
AssemblyResolutionSearchResult.FileNotFound,
31+
processorArchitecture: null,
32+
logAssemblyFoldersEx: false),
33+
],
34+
"ResolveAssemblyReference",
35+
MessageImportance.Low,
36+
DateTime.UtcNow);
37+
var packet = new LogMessagePacket(new KeyValuePair<int, BuildEventArgs>(0, searchEvent));
38+
39+
TaskHostTask.HandleLoggedMessage(buildEngine, packet);
40+
41+
buildEngine.MessageEvents.ShouldHaveSingleItem().ShouldBeSameAs(searchEvent);
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)