Packing native libraries - ittegrat/ExcelDna GitHub Wiki

From this discussion: https://groups.google.com/g/exceldna/c/JtWnyEyJeM0

1 Add the native client as an embedded resource in your .csproj file

    <ItemGroup>
        <EmbeddedResource Include="$(MSBuildProjectDirectory)\Resource\Microsoft.Data.SqlClient.SNI.dll" />
    </ItemGroup>

2 Extract the file, save it to "temp" folder (if neede), load the the file. (Do it on AutoOpen() method)

            var assembly = Assembly.GetExecutingAssembly();
            var sqlClientFileName = "Microsoft.Data.SqlClient.SNI.dll";
            var sqlClientPath = @$"{Path.GetTempPath()}{sqlClientFileName}";
            if (!File.Exists(sqlClientPath))
            {
                using var sqlEmbebedStream = assembly.GetManifestResourceStream($"AddIn.Resource.{sqlClientFileName}");
                var sqlFileStream = File.Create(sqlClientPath);
                sqlEmbebedStream.CopyTo(sqlFileStream);
                sqlFileStream.Close();
            }
            NativeLibrary.Load(sqlClientPath);
⚠️ **GitHub.com Fallback** ⚠️