sdk: dotnet format 7.0.304 fails when resolving types from COM references

Describe the bug

dotnet format cannot resolve types from COM references

To Reproduce

A trivial test project is available here:

https://github.com/molesmoke/WinFormsAppDotNetFormat

Exceptions (if any)

error CS0246: The type or namespace name 'SpVoice' could not be found (are you missing a using directive or an assembly reference?)

Further technical details

  • Include the output of dotnet --info

.NET SDK: Version: 7.0.304 Commit: 7e794e2806

Runtime Environment: OS Name: Windows OS Version: 10.0.22621 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.304\

Host: Version: 7.0.7 Architecture: x64 Commit: 5b20af47d9

.NET SDKs installed: 6.0.401 [C:\Program Files\dotnet\sdk] 6.0.402 [C:\Program Files\dotnet\sdk] 6.0.410 [C:\Program Files\dotnet\sdk] 7.0.304 [C:\Program Files\dotnet\sdk] 7.0.400-preview.23274.1 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables: Not set

global.json file: C:\Users\jerem\source\repos\tests\WinFormsAppDotNetFormat\global.json

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download

  • The IDE (VS / VS Code/ VS4Mac) you’re running on, and its version

Build Tools & VS Pro 17.6.3

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 3
  • Comments: 26 (12 by maintainers)

Most upvoted comments

I’m not sure how/why 7.0.107 worked for this. COMReference isn’t supported for the dotnet tool, which includes dotnet format. https://github.com/dotnet/msbuild/issues/3986

Perhaps the generated file isn’t really at that location, but given the analyzer treats/reports it like it is, then I expect that the editorconfig should actually apply.

The tracking issue for this is https://github.com/dotnet/roslyn/issues/47384.

But that’s where VS Pro puts them.

This is also covered in the issue above, e.g. comment https://github.com/dotnet/roslyn/issues/47384#issuecomment-1010270932.

The build correctly fails (returning 1 to the shell) with error IDE0055: Fix formatting

Running msbuild -warnaserror again, the build succeeds, so looks like the incremental build behaviour is broken 😦 Though it might still be usable for CI which would obviously be doing clean builds.

This is a weakness of MSBuild’s warning model, tracked as https://github.com/dotnet/msbuild/issues/3046.