You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Several aspects of the generated code can be customized, including:
....
The namespace that declares all interop types
...
But I can't find this setting for the NativeMethods.json or in GeneratorOptions.
I ran across a problem when using the generator when my code is inside a namespace that contains .Windows.
For example, writing Windows.Win32.Foundation.LRESULT results in VS attempting to find Win32.Foundation.LRESULT inside my own namespace Engine.Windowing.Windows. And emit an The type or namespace name 'Win32' does not exist in the namespace 'Engine.Windowing.Windows'. error.
Solution
It would be awesome if we could change the default namespace name. If I were to change it from Windows.Win32 to something like CsWin32 that solves the problem.
The text was updated successfully, but these errors were encountered:
Thanks for bringing the doc to our attention. We used to allow customizing the namespace but removed it, leaving the doc behind. It turned out to create problems, particularly when multiple metadata inputs are used with CsWin32 together.
But you can solve your problem by adding global:: in front of the namespace. You can even create an alias for it to make it more convenient. For example at the top of your code file (or as a global using in just one file so it applies to your entire project):
using win32 = global::Windows.Win32;
Then everywhere you can use win32.Foundation.LRESULT and it will resolve correctly.
I hope that helps.
Thanks for bringing the doc to our attention. We used to allow customizing the namespace but removed it, leaving the doc behind. It turned out to create problems, particularly when multiple metadata inputs are used with CsWin32 together.
But you can solve your problem by adding global:: in front of the namespace. You can even create an alias for it to make it more convenient. For example at the top of your code file (or as a global using in just one file so it applies to your entire project):
using win32 = global::Windows.Win32;
Then everywhere you can use win32.Foundation.LRESULT and it will resolve correctly. I hope that helps.
Thank you, creating an alias is exactly what I did. If customizing the namespace created problems, then doing this instead is completely fine with me.
Problem
The readme of the project states:
Several aspects of the generated code can be customized, including:
But I can't find this setting for the
NativeMethods.json
or inGeneratorOptions
.I ran across a problem when using the generator when my code is inside a namespace that contains
.Windows
.For example, writing
Windows.Win32.Foundation.LRESULT
results in VS attempting to findWin32.Foundation.LRESULT
inside my own namespaceEngine.Windowing.Windows
. And emit anThe type or namespace name 'Win32' does not exist in the namespace 'Engine.Windowing.Windows'.
error.Solution
It would be awesome if we could change the default namespace name. If I were to change it from
Windows.Win32
to something likeCsWin32
that solves the problem.The text was updated successfully, but these errors were encountered: