-
I have a solution containing an application and a library project, the app is using the lib, both will need to use Win32, how should I do it? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
By default the generated code is emitted as Another option is to use NativeMethods.json to configure the generator to emit If you generated internal code and use IVT, you can still use two NativeMethods.txt files. But any code generated in the library project will not be generated in the app project because CsWin32 automatically detects that the types are available and won't regenerated them. However, you may need to use nativemethods.json to reconfigure the class name into which extern methods and constants are emitted to avoid nasty compiler warnings about the same class being declared in two assemblies. While CsWin32 can suppress generation of methods and types that are already defined, C#/.NET cannot merge two classes across two assemblies, and the default |
Beta Was this translation helpful? Give feedback.
-
Thanks, I went for generating as public in the library as maintaining a single {
"$schema": "https://aka.ms/CsWin32.schema.json",
"public": true
} |
Beta Was this translation helpful? Give feedback.
By default the generated code is emitted as
internal
. If you do this in the library, the application will have access to it if and only if the library has anInternalsVisibleTo
attribute for the app.As I personally hate InternalsVisibleTo as it leads to lots of design and test issues, I would personally use NativeMethods.txt in each project and have them generate whatever they need independently.
Another option is to use NativeMethods.json to configure the generator to emit
public
APIs, in which case the code generated in the library would be available to the app without the need for the IVT attribute.If you generated internal code and use IVT, you can still use two NativeMethods.txt fi…