Skip to content

Commit 9d084eb

Browse files
Merge pull request #408 from tannergooding/main
Small fixes for the dotnet tool
2 parents bbf343f + f93ceba commit 9d084eb

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

sources/ClangSharp.Interop/Extensions/clang.ResolveLibrary.cs

+19-8
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ static @clang()
1818

1919
private static IntPtr OnDllImport(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
2020
{
21-
return TryResolveLibrary(libraryName, assembly, searchPath, out var nativeLibrary)
22-
? nativeLibrary
23-
: libraryName.Equals("libclang") && TryResolveClang(assembly, searchPath, out nativeLibrary)
24-
? nativeLibrary
25-
: libraryName.Equals("libClangSharp") && TryResolveClangSharp(assembly, searchPath, out nativeLibrary)
26-
? nativeLibrary
27-
: IntPtr.Zero;
21+
var result = TryResolveLibrary(libraryName, assembly, searchPath, out var nativeLibrary) ? nativeLibrary
22+
: libraryName.Equals("libclang") && TryResolveClang(assembly, searchPath, out nativeLibrary) ? nativeLibrary
23+
: libraryName.Equals("libClangSharp") && TryResolveClangSharp(assembly, searchPath, out nativeLibrary) ? nativeLibrary
24+
: IntPtr.Zero;
25+
26+
if (result == IntPtr.Zero)
27+
{
28+
Console.WriteLine("Failed to resolve libClang or libClangSharp.");
29+
Console.WriteLine("If you are running as a dotnet tool, you may need to manually copy the appropriate DLLs from NuGet due to limitations in the dotnet tool support.");
30+
}
31+
return result;
2832
}
2933

3034
private static bool TryResolveClang(Assembly assembly, DllImportSearchPath? searchPath, out IntPtr nativeLibrary)
@@ -47,7 +51,14 @@ private static bool TryResolveLibrary(string libraryName, Assembly assembly, Dll
4751

4852
foreach (DllImportResolver resolver in resolvers.Cast<DllImportResolver>())
4953
{
50-
nativeLibrary = resolver(libraryName, assembly, searchPath);
54+
try
55+
{
56+
nativeLibrary = resolver(libraryName, assembly, searchPath);
57+
}
58+
catch
59+
{
60+
nativeLibrary = IntPtr.Zero;
61+
}
5162

5263
if (nativeLibrary != IntPtr.Zero)
5364
{

sources/ClangSharpPInvokeGenerator/ClangSharpPInvokeGenerator.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<PropertyGroup>
55
<OutputType>Exe</OutputType>
66
<PackAsTool>true</PackAsTool>
7+
<PackAsToolShimRuntimeIdentifiers>win-x64</PackAsToolShimRuntimeIdentifiers>
78
<RuntimeIdentifier></RuntimeIdentifier>
89
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
910
</PropertyGroup>

0 commit comments

Comments
 (0)