0

I has a question, does CodeDom Compiler can compile c# code with custom configuration such as x64 bit or x86 bit.By default it compiles c# code to .exe with "Any CPU" configuration. Compiling c# code:

public static string BCS(string[] sources,string[] libs,string outPath,bool exef)
    {
        CSharpCodeProvider codeProvider = new CSharpCodeProvider();
        CompilerParameters parameters = new CompilerParameters(libs);
        parameters.GenerateExecutable = exef;
        parameters.OutputAssembly = outPath;
        CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, sources);

        if (results.Errors.Count > 0)
        {
            string errsText = "";
            foreach (CompilerError CompErr in results.Errors)
            {
                errsText = "("+CompErr.ErrorNumber +
                            ")Line " + CompErr.Line +
                            ",Column "+CompErr.Column +
                            ":"+CompErr.ErrorText + "" +
                            Environment.NewLine;
            }
            return errsText;
        }
        else
        {
            return "Success";
        }
    }

I think,youre understand my question,if not, leave a comment,i will give details.

2
  • Poorly written, can you please explain what is your error message? if you want to know can CodeDom be compile C# the answer is yes it can please refer to learn.microsoft.com/en-us/dotnet/framework/… Commented Jan 24, 2019 at 16:58
  • I dont have any errors.I just need a way to compile(to .exe) c# code for specific platforms such as x86 bit and x64 bit using CodeDom. Commented Jan 24, 2019 at 17:02

1 Answer 1

0

Try to set CompilerOptions this way

parameters.CompilerOptions = "-platform:anycpu32bitpreferred";

using params from this link

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/platform-compiler-option

P.S. CSharpCodeProvider uses csc.exe

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/command-line-building-with-csc-exe

Sign up to request clarification or add additional context in comments.

11 Comments

Also,is u know,how to compile c# with custom .NET Framework version? Like,i want to build c# with .NET Framework 4.6.1
stackoverflow.com/a/9591795/10496806 var options = new Dictionary<string, string> { { "CompilerVersion", "v4.0" } }; var compiler = new CSharpCodeProvider(options); but I'm not sure it is possible to point 4.6.1 as you want, here is compiler version, it differs from .net version stackoverflow.com/questions/13253967/…
Oh no! I has a error on CompilerResults line: System.InvalidOperationException: "Cannot find executable file of csc.exe compiler."
what "CompilerVersion" you have pointed? probably it is wrong or this version is not installed on your PC and.... yes, CSharpCodeProvider uses csc.exe learn.microsoft.com/en-us/dotnet/csharp/language-reference/…
please read more attentively my 2nd link in my 2nd comment stackoverflow.com/a/13255462/10496806
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.