In the project I'm currently working on, the library (and any library) is stored in the GAC which has a couple of down-sides:
This lib isn't strongly named, so cannot be put in the GAC.
This lib does not export the unmanaged libraries to a location where the applications can work with them (breaking the lib's functionality).
For the first issue I've signed the library with a company certificate, however it would be nice to have a signed version in NuGet as well.
For the second issue, I have made the dlls embedded resources, then I can automatically 'deploy' them as soon as I start using the library. For now I used this code in the PechkinBindings class:
static PechkinBindings()
{
// Get the Pechkin assembly.
Assembly assembly = Assembly.GetExecutingAssembly();
// Determine the target path for the dlls.
string targetPath = Path.GetDirectoryName(assembly.GetName().CodeBase.Replace("file:///", ""));
// Make sure the target directory exists.
if (!Directory.Exists(targetPath))
Directory.CreateDirectory(targetPath);
// Write all the dlls.
string[] resourceNames = assembly.GetManifestResourceNames();
IEnumerable<string> dllResourceNames = resourceNames
.Where(name => name.EndsWith(".dll"));
foreach (string dllResourceName in dllResourceNames)
{
string fileName = Path.Combine(targetPath, dllResourceName.Substring(dllResourceName.LastIndexOf("/") + "/Pechkin.".Length));
if (!File.Exists(fileName))
{
using (Stream inputStream = assembly.GetManifestResourceStream(dllResourceName))
using (FileStream outputStream = File.Open(fileName, FileMode.Create))
{
byte[] buffer = new byte[8 * 1024];
int len;
while ((len = inputStream.Read(buffer, 0, buffer.Length)) > 0)
outputStream.Write(buffer, 0, len);
}
}
}
}
In the project I'm currently working on, the library (and any library) is stored in the GAC which has a couple of down-sides:
For the first issue I've signed the library with a company certificate, however it would be nice to have a signed version in NuGet as well. For the second issue, I have made the dlls embedded resources, then I can automatically 'deploy' them as soon as I start using the library. For now I used this code in the PechkinBindings class: