2
如何給我的roslyn編譯器輸出一個圖標?用Roslyn發送Win32Icon
在CodeDOM的,我可以簡單地使用CompilerOptions並將其添加爲「/ win32icon:」
但如何在羅斯林辦?
我已經讚了。
var syntaxTree = CSharpSyntaxTree.ParseText(File.ReadAllText("program.cs"));
CSharpCommandLineArguments arguments = new CSharpCommandLineArguments();
arguments.Win32Icon = @"ICON PATH";
CSharpCompilation compilation = CSharpCompilation.Create(
"program",
new[] { syntaxTree },
new[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location) },
new CSharpCompilationOptions(OutputKind.ConsoleApplication));
ResourceWriter rs = new ResourceWriter("res.resources");
var resourceDescription = new ResourceDescription("program.Resources.resources",() => new MemoryStream(File.ReadAllBytes("res.resources")), true);
using (var dllStream = new MemoryStream())
using (var pdbStream = new MemoryStream())
{
var emitResult = compilation.Emit(dllStream, pdbStream, null,null, manifestResources: new [] {resourceDescription});
if (emitResult.Success)
{
File.WriteAllBytes("test.exe",dllStream.GetBuffer());
Console.WriteLine("compiled");
}
else
{
Console.WriteLine("foutje: {0}", emitResult.Diagnostics[0].ToString());
}
}
Console.ReadLine();
感謝您的幫助!