microsoft / CsWin32

A source generator to add a user-defined set of Win32 P/Invoke methods and supporting types to a C# project.
MIT License
2.1k stars 90 forks source link

Visual Studio Quick Actions doesn't offer to import PInvoke namespaces #773

Closed riverar closed 1 year ago

riverar commented 1 year ago

Actual behavior

It's not clear if this is a CsWin32 issue or more general .NET / Visual Studio issue.

When attempting to use code generated types, Visual Studio typically provides a Quick Action to import the appropriate namespace to avoid fully qualifying the type. For example, using Quick Actions on a naked HWND should recommend importing Windows.Win32.Foundation and offer use of the fully qualified type name.

image Built-in types work great.

image Code-generated types do not.

Expected behavior

I expect to see a using Windows.Win32.Foundation; Quick Action.

Repro steps

  1. Create a new net6 C# project and add CsWin32 0.2.104-beta as a dependency.
  2. Add the following content to NativeMethods.txt:
    HWND
  3. In any class method or function, type HWND and click the light bulb (or type CTRL + .).
  4. Observe the Quick Actions menu does not offer to import the namespace in which HWND lives in.
AArnott commented 1 year ago

This is a roslyn limitation. https://github.com/dotnet/roslyn/issues/52184 is related (though more complex than the simple repro we see for CsWin32).

The feedback ticket I filed on this issue specifically is here. It's already been closed as won't fix, but feel free to vote it up and maybe they'll reconsider.

riverar commented 1 year ago

@AArnott Thanks, will make some noise!