按照平台调用的源生成中所述从DllImportAttribute迁移到LibraryImportAttribute,我偶然发现了DefaultDllImportSearchPathsAttribute,它指定了用于搜索DLL的路径。
假设我有以下DLL导入,
[DllImport("user32.dll")]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
更新为
[LibraryImport("user32.dll")]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
private static partial bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
,搜索路径也会像以前一样由 LibraryImportAttribute 处理吗?
正如评论中已经指出的,答案是肯定的,
DefaultDllImportSearchPaths 也将由 LibraryImport 处理。
可以在 .NET 源代码中看到,LibraryImportGenerator.cs 处理 DllImportSearchPathsAttribute。 使用一些最小的示例可执行文件对其进行反编译和测试也证实了这一点。