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.07k stars 87 forks source link

SourceGenerator not working with version 0.1.506 #326

Closed stiezinger closed 3 years ago

stiezinger commented 3 years ago

Hello,

I was using version 0.1.422 without issues, updated to 0.1.506 and the Source Generator will not work anymore.

I receive the error: The type or namespace name 'Windows' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?).

Rolling back to 0.1.422 fixes everything.

I am using Visual Studio Version 16.10.3 with Windows 10 Version 1909.

jnm2 commented 3 years ago

The namespaces all changed. VS also has a bug where it will not give you light bulb fixes to add using directives for types declared by source generators, so it's temporarily a painstaking process to find and type in all the right using directives. The quickest way I know of to deal with this is to click on the type that can't be found, press Ctrl+T to open "Go To All" with that type name prefilled, press enter to navigate to the .g.cs file that should be the top entry found, then observe the namespace (and nested namespace) surrounding the type name.

Once you have a block of using statements, you can go file to file pasting in that block and then pressing Ctrl+R, Ctrl+G to remove and sort usings.

anhhh11 commented 3 years ago

Use using Windows.Win32; instead of using Microsoft.Windows.Sdk;

malcolms commented 3 years ago

This thoroughly confused me for about half an hour.

I note that the Readme.md still references the old namespaces though.

jnm2 commented 3 years ago

Is anyone interested in contributing a readme fix to update Microsoft.Windows.Sdk to the new namespace?

AArnott commented 3 years ago

Fixed in cc0ac97207d36937ba793bcf8d47b5775fcbad9b.