CppSharp icon indicating copy to clipboard operation
CppSharp copied to clipboard

Use LibraryImportAttribute instead of DllImportAttribute

Open jasoncouture opened this issue 2 years ago • 2 comments

Brief Description

When code generation is targeting .NET 7, LibraryImport should be used in place of DllImport as this will pre-generate marshalling operations normally performed at runtime.

When framework target is lower than .NET 7, DllImport should continue to be used.

More information about LibraryImportAttribute can be found here: https://devblogs.microsoft.com/dotnet/announcing-dotnet-7-preview-7/#libraryimport-p-invoke-source-generator

(Non os specific, code generation)

OS: N/A

jasoncouture avatar Oct 06 '22 12:10 jasoncouture

Thanks for the heads up.

tritao avatar Oct 06 '22 13:10 tritao

+1. Having the option to generate LibraryImport would be really useful!

caihongxu avatar Jan 18 '23 08:01 caihongxu