Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log SDK resolution result #9621

Merged
merged 11 commits into from
Jan 12, 2024
16 changes: 15 additions & 1 deletion src/Build.UnitTests/BackEnd/SdkResolverService_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public void AssertResolverThrows()
e.Sdk.Name.ShouldBe("1sdkName");
}


[Fact]
// Scenario: MockSdkResolverWithResolvableSdkPattern2 is a specific resolver (i.e. resolver with pattern)
// and it successfully resolves sdk.
Expand Down Expand Up @@ -184,6 +183,21 @@ public void AssertFirstResolverWithPatternCanResolve()
_logger.BuildMessageEvents.Select(i => i.Message).ShouldNotContain("MockSdkResolver1 running");
}

[Fact]
public void AssertSdkResolutionMessagesAreLogged()
{
SdkResolverService.Instance.InitializeForTests(new MockLoaderStrategy());
SdkReference sdk = new SdkReference("1sdkName", "referencedVersion", "minimumVersion");

var result = SdkResolverService.Instance.ResolveSdk(BuildEventContext.InvalidSubmissionId, sdk, _loggingContext, new MockElementLocation("file"), "sln", "projectPath", interactive: false, isRunningInVisualStudio: false, failOnUnresolvedSdk: true);

// First resolver attempted to resolve, but failed.
_logger.BuildMessageEvents.Select(i => i.Message).ShouldContain(ResourceUtilities.FormatResourceStringStripCodeAndKeyword("SDKResolverAttempt", nameof(MockResolverReturnsNull), sdk.ToString(), "null",
ResourceUtilities.FormatResourceStringStripCodeAndKeyword("SDKResolverReturnedNull", nameof(MockResolverReturnsNull))));
// Second resolver succeeded.
_logger.BuildMessageEvents.Select(i => i.Message).ShouldContain(ResourceUtilities.FormatResourceStringStripCodeAndKeyword("SucceededToResolveSDK", sdk.ToString(), nameof(MockSdkResolver1), result.Path, result.Version));
}

[Fact]
public void AssertFirstResolverErrorsSupressedWhenResolved()
{
Expand Down
11 changes: 9 additions & 2 deletions src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,6 @@ private bool TryResolveSdkUsingSpecifiedResolvers(
// Loop through resolvers which have already been sorted by priority, returning the first result that was successful
SdkLogger buildEngineLogger = new SdkLogger(loggingContext);

loggingContext.LogComment(MessageImportance.Low, "SdkResolving", sdk.ToString());

foreach (SdkResolver sdkResolver in resolvers)
{
SdkResolverContext context = new SdkResolverContext(buildEngineLogger, projectPath, solutionPath, ProjectCollection.Version, interactive, isRunningInVisualStudio)
Expand Down Expand Up @@ -355,6 +353,8 @@ private bool TryResolveSdkUsingSpecifiedResolvers(

if (result.Success)
{
loggingContext.LogComment(MessageImportance.Low, "SucceededToResolveSDK", sdk.ToString(), sdkResolver.Name, result.Path ?? "null", result.Version ?? "null");

LogWarnings(loggingContext, sdkReferenceLocation, result.Warnings);

if (!IsReferenceSameVersion(sdk, result.Version))
Expand All @@ -369,6 +369,13 @@ private bool TryResolveSdkUsingSpecifiedResolvers(
sdkResult = result;
return true;
}
else if (loggingContext.LoggingService.MinimumRequiredMessageImportance >= MessageImportance.Low)
{
string resultWarnings = result.Warnings?.Any() == true ? string.Join(Environment.NewLine, result.Warnings) : "null";
string resultErrors = result.Errors?.Any() == true ? string.Join(Environment.NewLine, result.Errors) : "null";

loggingContext.LogComment(MessageImportance.Low, "SDKResolverAttempt", sdkResolver.Name, sdk.ToString(), resultWarnings, resultErrors);
}

results.Add(result);
}
Expand Down
17 changes: 11 additions & 6 deletions src/Build/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,17 @@
<value>Could not resolve SDK "{0}". Exactly one of the probing messages below indicates why we could not resolve the SDK. Investigate and resolve that message to correctly specify the SDK.
{1}</value>
</data>
<data name="SucceededToResolveSDK" xml:space="preserve">
<value>The SDK "{0}" was successfully resolved by the "{1}" resolver to location "{2}" and version "{3}".</value>
</data>
<data name="SDKResolverAttempt" xml:space="preserve">
<value>The "{0}" resolver attempted to resolve the SDK "{1}".
Warnings: {2}
Errors: {3}</value>
<comment>
LOCALIZATION: Do not localize the word SDK. "{2}" is new line separated warnings or "null". "{3}" is new line separated errors or "null".
</comment>
</data>
<data name="CouldNotRunNuGetSdkResolver" xml:space="preserve">
<value>The NuGet-based SDK resolver failed to run because NuGet assemblies could not be located. Check your installation of MSBuild or set the environment variable "{0}" to the folder that contains the required NuGet assemblies. {1}</value>
</data>
Expand Down Expand Up @@ -1769,12 +1780,6 @@ Utilization: {0} Average Utilization: {1:###.0}</value>
LOCALIZATION: Do not localize the word SDK.
</comment>
</data>
<data name="SdkResolving" xml:space="preserve">
<value>Resolving SDK '{0}'...</value>
<comment>
LOCALIZATION: Do not localize the word SDK.
</comment>
</data>
<data name="ProjectGraphDoesNotSupportProjectReferenceWithToolset" xml:space="preserve">
<value>MSB4250: ProjectGraph does not support ProjectReference items with the ToolsVersion metadata set. Found ProjectReference "{0}" with ToolsVersion in file "{1}"</value>
<comment>
Expand Down
23 changes: 16 additions & 7 deletions src/Build/Resources/xlf/Strings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 16 additions & 7 deletions src/Build/Resources/xlf/Strings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 16 additions & 7 deletions src/Build/Resources/xlf/Strings.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 16 additions & 7 deletions src/Build/Resources/xlf/Strings.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 16 additions & 7 deletions src/Build/Resources/xlf/Strings.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading