dotnet / project-system

The .NET Project System for Visual Studio
MIT License
959 stars 385 forks source link

Avoid main thread switch in UpToDateCheckHost #9458

Closed drewnoakes closed 1 month ago

drewnoakes commented 2 months ago

Replaces API usage:

The latter is free-threaded, as described in: https://devdiv.visualstudio.com/DevDiv/_wiki/wikis/DevDiv.wiki/40079/Free-threaded-replacements

This requires bumping several VS packages to 17.11, in order to use __VSAPROPID10.VSAPROPID_IsInCommandLineMode.

Also, IVsAppCommandLine is free-threaded, so don't use IVsUIService for that, as given in: https://github.com/microsoft/VSSDK-Analyzers/blob/614165cfdca3245dd8c19530bd054e24cd80be32/src/Microsoft.VisualStudio.SDK.Analyzers.CodeFixes/build/AdditionalFiles/vs-threading.MembersRequiringMainThread.txt#L84

Together, these changes mean we don't need to switch to the main thread in UpToDateCheckHost 👍

Microsoft Reviewers: Open in CodeFlow
drewnoakes commented 2 months ago

Test is failing with:

System.TypeLoadException : Method 'ImportMetadata' in type 'Microsoft.Build.Execution.ProjectItemInstance' from assembly 'Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' does not have an implementation.

Seems like something related to the package updates here has broken mock object proxy generation. That's a tomorrow problem!

drewnoakes commented 1 month ago

I rebased this PR and it now fails with a similar error:

System.TypeInitializationException : The type initializer for 'Microsoft.Build.Shared.FrameworkLocationHelper' threw an exception. ---- System.MissingMethodException : Method not found: 'Boolean Microsoft.Build.Framework.NativeMethods.get_IsMono()'.

It seems like we have an unexpected version of MSBuild DLLs at runtime. I've added an explicit reference to a version of MSBuild to try and fix this. Unfortunately the problem does not reproduce locally.

drewnoakes commented 1 month ago

We now explicitly reference the version of MSBuild used in these tests, which makes CI pass.