Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[vs17.14] Fix SdkResult Evalution when ProjectRootElement is null #11636

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

Merged
merged 3 commits into from
Mar 27, 2025

Conversation

surayya-MS
Copy link
Member

Fixes #11550

Context

This is a regression caused by changes in MSBuildSdkResolver that were introduced in dotnet/sdk#45364. Specifically by adding 2 new properties.
This results in hitting the path that was not hit before - handling properties and items of SdkResult:

if ((sdkResult.PropertiesToAdd?.Any() == true) ||
(sdkResult.ItemsToAdd?.Any() == true))
{
projectList ??= new List<ProjectRootElement>();
// Inserting at the beginning will mean that the properties or items from the SdkResult will be evaluated before
// any projects from paths returned by the SDK Resolver.
projectList.Insert(0, CreateProjectForSdkResult(sdkResult));
}

When Project is created from XmlReader and not from ProjectRootElement, it results in null ProjectRootElement during Evaluation. Which results in internal exception like InternalErrorException: MSB0001: Internal MSBuild Error: .SdkResolver.1981936763.proj unexpectedly not a rooted path here:

string projectPath = $"{_projectRootElement.FullPath}.SdkResolver.{propertiesAndItemsHash}.proj";

Above created project path is just .SdkResolver.1981936763.proj with no directory. Later exception is thrown here because of it:
ErrorUtilities.VerifyThrowInternalRooted(projectFile);

or here if you use SimpleProjectRootElementCache:
ErrorUtilities.VerifyThrowInternalRooted(projectFile);

Changes Made

Changed the projet path that is created for SdkResult properties and items - if there is no ProjectRootElement then generate name like {Guid}.SdkResolver.{propertiesAndItemsHash}.proj in the current directory.

Testing

Added test. Tested manually as well

Notes

@surayya-MS surayya-MS merged commit 903614e into dotnet:vs17.14 Mar 27, 2025
9 checks passed
@surayya-MS surayya-MS deleted the fix-sdk-result-xmlReader branch March 27, 2025 14:27
@tsvietOK
Copy link

Is there a workaround to use until this is released as part of the VS (build tools)?

@surayya-MS
Copy link
Member Author

surayya-MS commented Apr 15, 2025

@tsvietOK you could try to copy the old MSBuildSdkResolver folder from Visual Studio 17.12 and put it in the newer Visual Studio. You can find it in your Visual Studio location (usually C:\Program Files\Microsoft Visual Studio\2022\Enterprise) {Visual Studio path}\MSBuild\Current\Bin\SdkResolvers\Microsoft.DotNet.MSBuildSdkResolver.

@tsvietOK
Copy link

@tsvietOK you could try to copy the old MSBuildSdkResolver folder from Visual Studio 17.12 and put it in the newer Visual Studio. You can find it in your Visual Studio location (usually C:\Program Files\Microsoft Visual Studio\2022\Enterprise) {Visual Studio path}\MSBuild\Current\Bin\SdkResolvers\Microsoft.DotNet.MSBuildSdkResolver.

Thank you, will try. Do you have any estimates of when this fix will be released?

@surayya-MS
Copy link
Member Author

Thank you, will try. Do you have any estimates of when this fix will be released?

This fix will be in Visual Studio 17.14

@tsvietOK
Copy link

@tsvietOK you could try to copy the old MSBuildSdkResolver folder from Visual Studio 17.12 and put it in the newer Visual Studio. You can find it in your Visual Studio location (usually C:\Program Files\Microsoft Visual Studio\2022\Enterprise) {Visual Studio path}\MSBuild\Current\Bin\SdkResolvers\Microsoft.DotNet.MSBuildSdkResolver.

This suggestion helped, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants