0

When I load certain old project into MSBuildWorkspace I get the Diagnostic error:

Msbuild failed when processing the file "...SomeProj.csproj" with message: The tools version "Current" is unrecognized. Available tools versions are "2.0", "3.5", "4.0".

and empty list of MetadataReferences.
(The project opens correctly in the VS 2022 on the same PC.)

But if I edit the ...SomeProj.csproj file in the notepad and remove the "ToolsVersion" attribute, then the project with MetadataReferences loads correctly into the MSBuildWorkspace. How to make the ToolsVersion attribute be ignored programmatically without modifying the csproj file itself?

I have clean windows with installed VS 2022. If I additionally install the build tools 2019, the issue stops reproducing, but there must be a way to avoid additional installations since the project opens correctly in the VS 2022.

2
  • How are you using MSBuildLocator prior to calling MSBuildWorkspace? Commented Oct 23, 2023 at 23:33
  • @JasonMalinowski, MSBuildLocator.QueryVisualStudioInstances() returns the only instance (MSBuildPath: "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin"). So I register this instance (MSBuildLocator.RegisterInstance(_instance);) Commented Oct 24, 2023 at 5:03

1 Answer 1

0

Installing the Microsoft.Build nuget resolved the issue

Sign up to request clarification or add additional context in comments.

1 Comment

That's a perfectly fine answer for now, but going forward once I've got github.com/dotnet/roslyn/pull/70469 merged that shouldn't be necessary anymore. So you might be able to simplify this once the 4.9 NuGet packages are out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.