Как добавить манифест в сборку при динамической компиляции CodeDOM?C#

Место общения программистов C#
Ответить
Anonymous
 Как добавить манифест в сборку при динамической компиляции CodeDOM?

Сообщение Anonymous »

Мой код для компиляции:

Код: Выделить всё

CSharpCodeProvider codeProvider = new CSharpCodeProvider();
ICodeCompiler icc = codeProvider.CreateCompiler();
string Output = "program.exe";

System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
parameters.ReferencedAssemblies.Add("System.dll");
parameters.GenerateExecutable = true;
parameters.OutputAssembly = Output;
CompilerResults results = icc.CompileAssemblyFromSource(parameters, codeCompile);
Я также узнал о mt.exe, который позволяет мне добавлять файл манифеста в мою сборку. Файл app.manifest находится в папке проекта в Debug, туда же помещается и mt.exe.
Команду я тоже нашел

Код: Выделить всё

C:\winsdk61>mt.exe -nologo -manifest "r:\shared\hl.exe.manifest" -updateresource:"r:\shared\hl33m.exe;#1"
что должно помочь мне добавить файл манифеста в сборку.
Я не могу точно понять, как и на каком этапе мне следует подать заявку это, учитывая имя моего файла манифеста и приведенный выше код компиляции.
Я попробовал этот вариант

Код: Выделить всё

//Add an application manifest using mt.exe
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();

startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = Path.Combine( System.Web.HttpContext.Current.Server.MapPath( "~/Content/" ), "mt.exe" );
string AppManifestPath = Path.Combine( System.Web.HttpContext.Current.Server.MapPath( "~/Content/" ), "CustomInstaller.exe.manifest" );
startInfo.Arguments = string.Format( "-nologo -manifest \"{0}\" -outputresource:\"{1};#1\"", AppManifestPath, cp.OutputAssembly );

process.StartInfo = startInfo;
process.Start();

process.WaitForExit( 10000 ); //wait until finished (up to 10 sec)
После добавления мой код выглядит так

Код: Выделить всё

CSharpCodeProvider codeProvider = new CSharpCodeProvider();
ICodeCompiler icc = codeProvider.CreateCompiler();
string Output = "program.exe";

System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
parameters.ReferencedAssemblies.Add("System.dll");
parameters.EmbeddedResources.Add(@"WindowsProcessDll.dll");
parameters.GenerateExecutable = true;
parameters.OutputAssembly = Output;

//Add an application manifest using mt.exe
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();

startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = Path.Combine("MY_PATH\\mt.exe");
string AppManifestPath = Path.Combine("MY_PATH\\app.manifest");
startInfo.Arguments = string.Format("-nologo -manifest \"{0}\" -outputresource:\"{1};#1\"", AppManifestPath, parameters.OutputAssembly);

process.StartInfo = startInfo;
process.Start();

process.WaitForExit(2000); //wait until finished (up to 10 sec)

CompilerResults results = icc.CompileAssemblyFromSource(parameters, codeCompile);
но я получаю ошибку
"System.ComponentModel.Win32Exception" в System.dll
Что я делаю не так?

Подробнее здесь: https://stackoverflow.com/questions/790 ... ynamically
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»