Я пытаюсь скомпилировать код ниже с помощью CSharpCodeProvider. Файл успешно скомпилирован, но когда я нажимаю на сгенерированный EXE файл, я получаю сообщение об ошибке (Windows ищет решение этой проблемы), и ничего не происходит.
Когда я компилирую код ниже с помощью CSharpCodeProvider, я добавил MySql.Data.dll
в качестве встроенного файла ресурсов, используя эту строку кода:
if (provider.Supports(GeneratorSupport.Resources))
cp.EmbeddedResources.Add("MySql.Data.dll");
Файл успешно внедрен (потому что я заметил, что размер файла увеличен).
В приведенном ниже коде я пытаюсь извлечь встроенный DLL файл и сохранить его в System32, но приведенный ниже код не работает по какой-либо причине.
namespace ConsoleApplication1
{
class Program
{
public static void ExtractSaveResource(String filename, String location)
{
//Assembly assembly = Assembly.GetExecutingAssembly();
Assembly a = .Assembly.GetExecutingAssembly();
//Stream stream = assembly.GetManifestResourceStream("Installer.Properties.mydll.dll"); // or whatever
//string my_namespace = a.GetName().Name.ToString();
Stream resFilestream = a.GetManifestResourceStream(filename);
if (resFilestream != null)
{
BinaryReader br = new BinaryReader(resFilestream);
FileStream fs = new FileStream(location, FileMode.Create); // Say
BinaryWriter bw = new BinaryWriter(fs);
byte[] ba = new byte[resFilestream.Length];
resFilestream.Read(ba, 0, ba.Length);
bw.Write(ba);
br.Close();
bw.Close();
resFilestream.Close();
}
// this.Close();
}
static void Main(string[] args)
{
try
{
string systemDir = Environment.SystemDirectory;
ExtractSaveResource("MySql.Data.dll", systemDir);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadKey();
}
}
}
}
Как извлечь DLL файл, который встроен в качестве ресурса, и сохранить его в System32?