C# Assembly Info Dynamic change

1.4k views Asked by At

I've finished my APP builder using Codedom, now I want to implement Assembly info change feature before compile. So when client open .exe file (codedom file not compiled one) he get 5-6 Text Boxes, and then when user fill them up and click build info from those boxes is used to fill Assembly info in AssemblyInfo.cs of file I'm compiling.

Here's example of what I tried to use: Form:

 using (ResourceWriter w = new ResourceWriter("res.resources"))
        {
            w.AddResource("AssemblyTitle", AssemblyTitle.Text);
            w.AddResource("AssemblyDescription", AssemblyDescription.Text);
            w.AddResource("AssemblyCompany", AssemblyCompany.Text);
            w.AddResource("AssemblyProduct", AssemblyProduct.Text);
            w.AddResource("AssemblyCopyright", AssemblyCopyright.Text);
            w.AddResource("AssemblyVersion", AssemblyVersion.Text);
            w.AddResource("FileName", FileName.Text);
            w.Generate();
        }
        if (CodeDom.Compile(FileName.Text + ".exe", new[] { source1, source2, source3, source4}, null, "res.resources"))
        {
            File.Delete("res.resources");
            MessageBox.Show("Done");

        }
    }

Assemblyinfo.cs:

private static void Main()
    {
        ResourceManager resourceManager = new ResourceManager("res", Assembly.GetExecutingAssembly());
        string Title = resourceManager.GetString("AssemblyTitle");
        string Description = resourceManager.GetString("AssemblyDescription");
        string Company = resourceManager.GetString("AssemblyCompany");
        string Product = resourceManager.GetString("AssemblyProduct");
        string Copyright = resourceManager.GetString("AssemblyCopyright");
        string Version = resourceManager.GetString("AssemblyVersion");


        [assembly: AssemblyTitle(Title)]
        [assembly: AssemblyDescription(Description)]
        [assembly: AssemblyConfiguration("")]
        [assembly: AssemblyCompany(Company)]
        [assembly: AssemblyProduct(Product)]
        [assembly: AssemblyCopyright(Copyright)]
        [assembly: AssemblyTrademark("")]
        [assembly: AssemblyCulture("")]


        [assembly: AssemblyVersion(Version)]
        [assembly: AssemblyFileVersion("0.74")]
    }

If anyone have any idea how to do this please write

EDIT: Debug:

Error: Expected class, delegate, enum, interface, or struct
6
Error: Expected class, delegate, enum, interface, or struct
8
Error: Assembly and module attributes must precede all other elements defined in a file except        using clauses and extern alias declarations
17
Error: Assembly and module attributes must precede all other elements defined in a file except using clauses and extern alias declarations
18
Error: Assembly and module attributes must precede all other elements defined in a file except using clauses and extern alias declarations
19
Error: Assembly and module attributes must precede all other elements defined in a file except   using clauses and extern alias declarations
20
Error: Assembly and module attributes must precede all other elements defined in a file except using clauses and extern alias declarations
21
Error: Assembly and module attributes must precede all other elements defined in a file except using clauses and extern alias declarations
22
Error: Assembly and module attributes must precede all other elements defined in a file except using clauses and extern alias declarations
23
Error: Assembly and module attributes must precede all other elements defined in a file except using clauses and extern alias declarations
24
Error: Assembly and module attributes must precede all other elements defined in a file except using clauses and extern alias declarations
26
Error: Assembly and module attributes must precede all other elements defined in a file except using clauses and extern alias declarations
29
Error: Assembly and module attributes must precede all other elements defined in a file except using clauses and extern alias declarations
31
Error: Assembly and module attributes must precede all other elements defined in a file except using clauses and extern alias declarations
32
Error: Type or namespace definition, or end-of-file expected
33
0

There are 0 answers