Skip to content

Conversation

@donnie-msft
Copy link
Contributor

@donnie-msft donnie-msft commented Aug 10, 2022

Bug

Fixes: https://github.com/NuGet/Client.Engineering/issues/1813

Regression? Last working version:

Description

MSBuild does not support runtime scenarios where the Microsoft.Build DLL is placed in an output directory.
See https://docs.microsoft.com/en-us/visualstudio/msbuild/updating-an-existing-application?view=vs-2022#use-nuget-packages-preferred

The symptom of this is that depending on where MSBuild resolves its runtime assets on a given machine, it may utilize the DLL in our Test project's output directory. When this happens, certain tests fail because our MSBuild utilities attempt to load project files by Activator.CreateInstance. When Version 4.x of MSBuild is loaded (likely in the GAC), it expects a ToolsVersion, but does not support the Current value which is used by latest MSBuild versions.

An example of an error that goes away with this change is:

Error: Microsoft.Build.Exceptions.InvalidProjectFileException : The tools version "Current" is unrecognized. Available tools versions are "2.0", "3.5", "4.0". D:\a_work\1\s.test\work\f6aff01c\749cdace\solution\proj1\proj1.nfproj

Stack:    at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
   at Microsoft.Build.Evaluation.Project.Data.InitializeForEvaluation(IToolsetProvider toolsetProvider, EvaluationContext evaluationContext)
   at Microsoft.Build.Evaluation.Evaluator`4..ctor(IEvaluatorData`4 data, Project project, ProjectRootElement projectRootElement, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDictionary`1 environmentProperties, IItemFactory`2 itemFactory, IToolsetProvider toolsetProvider, ProjectRootElementCacheBase projectRootElementCache, ISdkResolverService sdkResolverService, Int32 submissionId, EvaluationContext evaluationContext, Boolean profileEvaluation, Boolean interactive, ILoggingService loggingService, BuildEventContext buildEventContext)
   at Microsoft.Build.Evaluation.Evaluator`4.Evaluate(IEvaluatorData`4 data, Project project, ProjectRootElement root, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDictionary`1 environmentProperties, ILoggingService loggingService, IItemFactory`2 itemFactory, IToolsetProvider toolsetProvider, ProjectRootElementCacheBase projectRootElementCache, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, EvaluationContext evaluationContext, Boolean interactive)
   at Microsoft.Build.Evaluation.Project.ProjectImpl.Reevaluate(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
   at Microsoft.Build.Evaluation.Project.ProjectImpl.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
   at Microsoft.Build.Evaluation.Project.ProjectImpl.ReevaluateIfNecessary(EvaluationContext evaluationContext)
   at Microsoft.Build.Evaluation.Project.ProjectImpl.Initialize(IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
   at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext, IDirectoryCacheFactory directoryCacheFactory)
   at Microsoft.Build.Evaluation.Project..ctor(String projectFile)

PR Checklist

  • PR has a meaningful title

  • PR has a linked issue.

  • Described changes

  • Tests

    • Automated tests added
    • OR
    • Test exception
    • OR
    • N/A
  • Documentation

    • Documentation PR or issue filled
    • OR
    • N/A

@donnie-msft donnie-msft requested a review from a team as a code owner August 10, 2022 22:51
@donnie-msft donnie-msft requested a review from jeffkl August 10, 2022 22:51
@donnie-msft donnie-msft merged commit 557d846 into dev Aug 11, 2022
@donnie-msft donnie-msft deleted the dev-donnie-msft-msBuildExcludeAssets branch August 11, 2022 15:21
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.

3 participants