C#C
C#3y ago
Logan M.

Packaging a non-C# binary into a NuGet package.

So I've been optimizing this logging library of mine to try to get it as fast as I can. with the main bottleneck appearing to be as fast as it can be I just wrote the main functions of it in Rust and decided to interop it in. this showed to give a rough ~50ms improvement on benchmarking but now I don't know how to package this thing really... In the C# section it roughly looks as so:
[DllImport("print.dll", CharSet = CharSet.Ansi)]
static extern void print(IntPtr input, IntPtr filePath, bool isInfo, uint lineNum);
[DllImport("print.dll", CharSet = CharSet.Ansi)]
static extern IntPtr formattedLog(IntPtr input, bool isInfo, IntPtr filePath,  uint lineNum);

but since the
DllImport
is directly just the dll, I'm pretty sure I have to have
print.dll
in the same path as the library right? which brings the question of how do I do that..?
Closest I've gotten is managing to package
print.dll
in there but not in the right path causing an exception when you try to print something. Currently what I have so far is as so
  <!--rust dll-->
  <ItemGroup>
    <None Update="bin\Release\net7.0\print.dll" Pack="true" PackagePath="runtimes/win/lib/net7.0">
      <files>
        <file src="bin\Release\net7.0\print.dll" target="runtimes\win\lib\net7.0\print.dll" />
      </files>
    </None>
  </ItemGroup>

which for some reason doesn't even pack
print.dll
into the package. Any help would be appreciated!
image.png
image.png
Was this page helpful?