Search code examples
c#code-generationcodedom

CompileAssemblyFromSource comments


my c# script contains some fields with commetns , when i use the CodeDomProvider to compile it , everything is great but when i look at the code i see there is no comments included

thats my code:

CodeDomProvider codeDomProvider = CodeDomProvider.CreateProvider("C#");           
System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
parameters.GenerateExecutable = false;
parameters.OutputAssembly = AppDomain.CurrentDomain.BaseDirectory + "myFile.dll";

CompilerResults results = codeDomProvider.CompileAssemblyFromSource(parameters, "Some C# code with documentation");

Solution

  • You won't get non-XML comments anyway - they're never part of the result of compilation. However, you can generate the XML documentation file using the CompilerOptions property to just pass a command-line parameter to the compiler:

    parameters.CompilerOptions = "/doc:myFile.xml";
    

    So if you have code like this:

    /// <summary>This will be included in myFile.xml</summary>
    public class Foo
    {
        // This will not, as it's not an XML comment.
    }