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
12 changes: 11 additions & 1 deletion src/Build.UnitTests/BackEnd/SdkResolverService_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public void AssertResolutionWarnsIfResolvedVersionIsDifferentFromReferencedVersi

result.Path.ShouldBe("path");

_logger.BuildMessageEvents.Any(i => i.Message.StartsWith($"The SDK \"{sdk}\" was successfully resolved")).ShouldBeTrue();

_logger.WarningCount.ShouldBe(1);
_logger.Warnings.First().Code.ShouldStartWith("MSB4241");
}
Expand All @@ -111,7 +113,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 All @@ -124,6 +125,7 @@ public void AssertSecondResolverWithPatternCanResolve()
var result = SdkResolverService.Instance.ResolveSdk(BuildEventContext.InvalidSubmissionId, sdk, _loggingContext, new MockElementLocation("file"), "sln", "projectPath", interactive: false, isRunningInVisualStudio: false, failOnUnresolvedSdk: true);

result.Path.ShouldBe("resolverpathwithresolvablesdkpattern2");
_logger.BuildMessageEvents.Any(i => i.Message.StartsWith($"The SDK \"{sdk}\" was successfully resolved")).ShouldBeTrue();
_logger.BuildMessageEvents.Select(i => i.Message).ShouldContain("MockSdkResolverWithResolvableSdkPattern2 running");
_logger.BuildMessageEvents.Select(i => i.Message).ShouldNotContain("MockSdkResolver1 running");
_logger.BuildMessageEvents.Select(i => i.Message).ShouldNotContain("MockSdkResolver2 running");
Expand All @@ -141,6 +143,7 @@ public void AssertFirstResolverCanResolve()
var result = SdkResolverService.Instance.ResolveSdk(BuildEventContext.InvalidSubmissionId, sdk, _loggingContext, new MockElementLocation("file"), "sln", "projectPath", interactive: false, isRunningInVisualStudio: false, failOnUnresolvedSdk: true);

result.Path.ShouldBe("resolverpath1");
_logger.BuildMessageEvents.Any(i => i.Message.StartsWith($"The SDK \"{sdk}\" was successfully resolved")).ShouldBeTrue();
_logger.BuildMessageEvents.Select(i => i.Message).ShouldContain("MockSdkResolver1 running");
_logger.BuildMessageEvents.Select(i => i.Message).ShouldNotContain("MockSdkResolverWithResolvableSdkPattern1 running");
}
Expand All @@ -162,6 +165,7 @@ public void AssertFirstResolverWithPatternCantResolveChangeWave17_4()
var result = SdkResolverService.Instance.ResolveSdk(BuildEventContext.InvalidSubmissionId, sdk, _loggingContext, new MockElementLocation("file"), "sln", "projectPath", interactive: false, isRunningInVisualStudio: false, failOnUnresolvedSdk: true);

result.Path.ShouldBe("resolverpath1");
_logger.BuildMessageEvents.Any(i => i.Message.StartsWith($"The SDK \"{sdk}\" was successfully resolved")).ShouldBeTrue();
_logger.BuildMessageEvents.Select(i => i.Message).ShouldContain("MockSdkResolver1 running");
_logger.BuildMessageEvents.Select(i => i.Message).ShouldNotContain("MockSdkResolverWithResolvableSdkPattern1 running");
ChangeWaves.ResetStateForTests();
Expand All @@ -180,6 +184,7 @@ public void AssertFirstResolverWithPatternCanResolve()
var result = SdkResolverService.Instance.ResolveSdk(BuildEventContext.InvalidSubmissionId, sdk, _loggingContext, new MockElementLocation("file"), "sln", "projectPath", interactive: false, isRunningInVisualStudio: false, failOnUnresolvedSdk: true);

result.Path.ShouldBe("resolverpathwithresolvablesdkpattern1");
_logger.BuildMessageEvents.Any(i => i.Message.StartsWith($"The SDK \"{sdk}\" was successfully resolved")).ShouldBeTrue();
_logger.BuildMessageEvents.Select(i => i.Message).ShouldContain("MockSdkResolverWithResolvableSdkPattern1 running");
_logger.BuildMessageEvents.Select(i => i.Message).ShouldNotContain("MockSdkResolver1 running");
}
Expand All @@ -196,6 +201,7 @@ public void AssertFirstResolverErrorsSupressedWhenResolved()
var result = SdkResolverService.Instance.ResolveSdk(BuildEventContext.InvalidSubmissionId, sdk, _loggingContext, new MockElementLocation("file"), "sln", "projectPath", interactive: false, isRunningInVisualStudio: false, failOnUnresolvedSdk: true);

result.Path.ShouldBe("resolverpath2");
_logger.BuildMessageEvents.Any(i => i.Message.StartsWith($"The SDK \"{sdk}\" was successfully resolved")).ShouldBeTrue();
surayya-MS marked this conversation as resolved.
Show resolved Hide resolved

// Both resolvers should run, and no ERROR string.
_logger.BuildMessageEvents.Select(i => i.Message).ShouldContain("MockSdkResolver1 running");
Expand Down Expand Up @@ -366,6 +372,7 @@ public void SdkResolverCanReturnNoPaths(bool includePropertiesAndItems)

ValidateExpectedPropertiesAndItems(includePropertiesAndItems, result);

_logger.BuildMessageEvents.Any(i => i.Message.StartsWith($"The SDK \"{sdk}\" was successfully resolved")).ShouldBeTrue();
_logger.WarningCount.ShouldBe(0);
}

Expand Down Expand Up @@ -402,6 +409,7 @@ public void SdkResultCanReturnPropertiesAndItems()

ValidateExpectedPropertiesAndItems(true, result);

_logger.BuildMessageEvents.Any(i => i.Message.StartsWith($"The SDK \"{sdk}\" was successfully resolved")).ShouldBeTrue();
_logger.WarningCount.ShouldBe(0);
}

Expand Down Expand Up @@ -454,6 +462,7 @@ public void SdkResultCanReturnMultiplePaths(bool includePropertiesAndItems)

ValidateExpectedPropertiesAndItems(includePropertiesAndItems, result);

_logger.BuildMessageEvents.Any(i => i.Message.StartsWith($"The SDK \"{sdk}\" was successfully resolved")).ShouldBeTrue();
_logger.WarningCount.ShouldBe(0);
}

Expand Down Expand Up @@ -499,6 +508,7 @@ public void AssertResolutionWarnsIfResolvedVersionIsDifferentFromReferencedVersi

ValidateExpectedPropertiesAndItems(true, result);

_logger.BuildMessageEvents.Any(i => i.Message.StartsWith($"The SDK \"{sdk}\" was successfully resolved")).ShouldBeTrue();
_logger.WarningCount.ShouldBe(1);
_logger.Warnings.First().Code.ShouldStartWith("MSB4241");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,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 Down
3 changes: 3 additions & 0 deletions src/Build/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,9 @@
<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 SDK resolver "{1}". SDK Result: "Path : {2}, Version : {3}"</value>
surayya-MS marked this conversation as resolved.
Show resolved Hide resolved
</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
5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 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.

5 changes: 5 additions & 0 deletions src/Build/Resources/xlf/Strings.ja.xlf

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

5 changes: 5 additions & 0 deletions src/Build/Resources/xlf/Strings.ko.xlf

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

5 changes: 5 additions & 0 deletions src/Build/Resources/xlf/Strings.pl.xlf

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

5 changes: 5 additions & 0 deletions src/Build/Resources/xlf/Strings.pt-BR.xlf

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

5 changes: 5 additions & 0 deletions src/Build/Resources/xlf/Strings.ru.xlf

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

5 changes: 5 additions & 0 deletions src/Build/Resources/xlf/Strings.tr.xlf

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

5 changes: 5 additions & 0 deletions src/Build/Resources/xlf/Strings.zh-Hans.xlf

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

5 changes: 5 additions & 0 deletions src/Build/Resources/xlf/Strings.zh-Hant.xlf

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

Loading