C# 使用Roslyn发出Win32Icon
如何给我的roslyn编译器输出一个图标 在codedom中,我可以简单地使用编译器选项并将其添加为“/win32icon:” 但是在罗斯林怎么办 我已经知道了C# 使用Roslyn发出Win32Icon,c#,icons,roslyn,C#,Icons,Roslyn,如何给我的roslyn编译器输出一个图标 在codedom中,我可以简单地使用编译器选项并将其添加为“/win32icon:” 但是在罗斯林怎么办 我已经知道了 var syntaxTree = CSharpSyntaxTree.ParseText(File.ReadAllText("program.cs")); CSharpCommandLineArguments arguments = new CSharpCommandLineArguments();
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();
已经谢谢你的帮助了 您需要传入win32Resources选项以发射,通过创建,该选项采用
Stream iconicoformat
参数
compilation.Emit(
peStream: peStream,
pdbStream: pdbStream,
win32Resources: compilation.CreateDefaultWin32Resources(..., iconInIcoFormat: File.Open("<pathTo.ico>")))
compilation.Emit(
peStream:peStream,
PDB流:PDB流,
win32Resources:compilation.CreateDefaultWin32Resources(…,iconicoFormat:File.Open(“”))
更详细的exmaple是