Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用Roslyn发出Win32Icon_C#_Icons_Roslyn - Fatal编程技术网

C# 使用Roslyn发出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();

如何给我的roslyn编译器输出一个图标

在codedom中,我可以简单地使用编译器选项并将其添加为“/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();

已经谢谢你的帮助了

您需要传入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是