0

This is my compiler function and it works very well. But the output file has no description, like Copyright, ProductVersion or FileDescription :

public static bool CompileFromSource(string source, string output, string icon = null, string[] resources = null)
    {
        CompilerParameters cParams = new CompilerParameters
        {
            GenerateExecutable = true,
            OutputAssembly = output
        };

        string options = "/optimize+ /platform:x86 /target:winexe /unsafe";

        cParams.CompilerOptions = options;
        cParams.TreatWarningsAsErrors = false;

        cParams.ReferencedAssemblies.Add("System.dll");
        cParams.ReferencedAssemblies.Add("System.Windows.Forms.dll");
        cParams.ReferencedAssemblies.Add("System.Drawing.dll");
        cParams.ReferencedAssemblies.Add("System.Data.dll");
        cParams.ReferencedAssemblies.Add("Microsoft.VisualBasic.dll");

        if (resources != null && resources.Length > 0)
        {
            foreach (string res in resources)
            {
                cParams.EmbeddedResources.Add(res);
            }
        }

        Dictionary<string, string> providerOptions = new Dictionary<string, string> { { "CompilerVersion", "v2.0" } };
        CompilerResults results = new CSharpCodeProvider(providerOptions).CompileAssemblyFromSource(cParams, source);
}

How can i add this descriptions about my file programmatically in this compiler? And i dont want to use third-party app like resourceHacker

2 Answers2

0

Could you not just prepend/append [assembly: ...] into the source string?

If not, the standard Roslyn-as-code syntax can be discovered here: https://roslynquoter.azurewebsites.net/

[assembly: MyAttribute]
namespace S {
    class C { }
}

Results in:

CompilationUnit()
    .WithAttributeLists(
        SingletonList<AttributeListSyntax>(
            AttributeList(
                SingletonSeparatedList<AttributeSyntax>(
                    Attribute(IdentifierName("MyAttribute")))) 
               .WithTarget(
                    AttributeTargetSpecifier(
                       Token(SyntaxKind.AssemblyKeyword))))) 
    .WithMembers(
        SingletonList<MemberDeclarationSyntax>(
            NamespaceDeclaration(IdentifierName("S"))
                .WithMembers(
                    SingletonList<MemberDeclarationSyntax>(
                        ClassDeclaration("C")))))
    .NormalizeWhitespace()
jamespconnor
  • 1,382
  • 14
  • 29
0

This can be done in another way with Adding:

[assembly: AssemblyTitle("Loader")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Loader")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("f99d6ga6-3b37-43a6-9332-866f8s8g7f9b")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

To the top of source that you want to compile programmatically