我确实有这样的问题,并最终节省资源DLL和lodaing为x86或x64,当库第一次initilized的DLL。这对我来说是最清洁的方式。
另一种方式,当你在nuget中包含dll时,你也必须确保当som一个删除/清除bin mapp时,同一个dll会重新运行。
所以,你必须添加到nuger并创建构建文件一个目标,再复制上构建
这里的dll文件是我做的。
internal class EmbeddedDllClass
{
public static void LoadAllDll()
{
Assembly assem = Assembly.GetExecutingAssembly();
if (IntPtr.Size == 8)
{
var path = Path.Combine(string.Join("\\", assem.Location.Split('\\').Reverse().Skip(1).Reverse()), "x64");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
path = Path.Combine(path, "SQLite.Interop.dll");
if (!File.Exists(path))
File.WriteAllBytes(path, Properties.Resources.SQLite_Interop_64);
}
else if (IntPtr.Size == 4)
{
var path = Path.Combine(string.Join("\\", assem.Location.Split('\\').Reverse().Skip(1).Reverse()), "x86");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
path = Path.Combine(path, "SQLite.Interop.dll");
if (!File.Exists(path))
File.WriteAllBytes(path, Properties.Resources.SQLite_Interop_86);
}
}
}
然后叫它
EmbeddedDllClass.LoadAllDll();
$(平台)有不同的价值观,像任何CPU,86,64。我会检查它是如何完成具有平台特定依赖性的开源库的。据我所知,有些通过单独的nuget软件包提供这种平台特定的依赖关系。就像他们在https://www.nuget.org/packages/CoreCompat.System.Drawing/1.0.0-beta006 –
中所做的那样,当您针对OSX构建时,$(Platform)变量的值是多少? –
'Platform = AnyCPU',但对于Windows和Linux版本来说则是一样的。 – sakra