Skip to content

Fix SdkResult Evalution when ProjectRootElement is null#11627

Closed
surayya-MS wants to merge 7 commits intodotnet:mainfrom
surayya-MS:sdk-result-fix
Closed

Fix SdkResult Evalution when ProjectRootElement is null#11627
surayya-MS wants to merge 7 commits intodotnet:mainfrom
surayya-MS:sdk-result-fix

Conversation

@surayya-MS
Copy link
Member

@surayya-MS surayya-MS commented Mar 26, 2025

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

dotnet-bot and others added 6 commits February 25, 2025 23:08
…: Build ID 11098688 (dotnet#11501)

This is the pull request automatically created by the OneLocBuild task
in the build process to check-in localized files generated based upon
translation source files (.lcl files) handed-back from the downstream
localization pipeline. If there are issues in translations, visit
https://aka.ms/icxLocBug and log bugs for fixes. The OneLocBuild wiki is
https://aka.ms/onelocbuild and the localization process in general is
documented at https://aka.ms/AllAboutLoc.
@surayya-MS surayya-MS requested a review from a team as a code owner March 26, 2025 09:31
@surayya-MS surayya-MS closed this Mar 26, 2025
@surayya-MS
Copy link
Member Author

surayya-MS commented Mar 26, 2025

I meant to target vs17.13 not main #11628

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.

Regression in eval API: InternalErrorException: MSB0001: Internal MSBuild Error: .SdkResolver.1981936763.proj unexpectedly not a rooted path

5 participants