CSharp Compiler / Interpretor

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Azeem M. Suleman

    CSharp Compiler / Interpretor

    Hello,

    I need to use Csharp compiler and an interpretor. In my application user
    will use the application and application will write CSharp code on backend.
    But now i don't need to reinvent the wheel, just need to know how i can give
    user an option to build the project which will compile and make an
    executable file.

    thanks.


  • AirPete

    #2
    Re: CSharp Compiler / Interpretor

    Azeem M. Suleman wrote:[color=blue]
    > Hello,
    >
    > I need to use Csharp compiler and an interpretor. In my application
    > user will use the application and application will write CSharp code
    > on backend. But now i don't need to reinvent the wheel, just need to
    > know how i can give user an option to build the project which will
    > compile and make an executable file.
    >
    > thanks.[/color]

    Check out the Microsoft.CShar p.Compiler class.

    - Pete


    Comment

    • Miha Markic [MVP C#]

      #3
      Re: CSharp Compiler / Interpretor

      Hi Azeem,

      Check out Microsoft.CShar p.Compiler class.

      --
      Miha Markic [MVP C#] - RightHand .NET consulting & development
      miha at rthand com

      "Azeem M. Suleman" <asuleman@verco m.com> wrote in message
      news:%23g8gl3z6 DHA.1816@TK2MSF TNGP12.phx.gbl. ..> Hello,[color=blue]
      >
      > I need to use Csharp compiler and an interpretor. In my application user
      > will use the application and application will write CSharp code on[/color]
      backend.[color=blue]
      > But now i don't need to reinvent the wheel, just need to know how i can[/color]
      give[color=blue]
      > user an option to build the project which will compile and make an
      > executable file.
      >
      > thanks.
      >
      >[/color]


      Comment

      • Azeem M. Suleman

        #4
        Re: CSharp Compiler / Interpretor

        Yeah i looked on msdn, is their any implementation sample for it. Like for
        basic idea i found this article:



        But it didn't compile windows form and other controls.

        Thanks.
        "Miha Markic [MVP C#]" <miha at rthand com> wrote in message
        news:uQYdv%23z6 DHA.1556@tk2msf tngp13.phx.gbl. ..[color=blue]
        > Hi Azeem,
        >
        > Check out Microsoft.CShar p.Compiler class.
        >
        > --
        > Miha Markic [MVP C#] - RightHand .NET consulting & development
        > miha at rthand com
        > www.rthand.com
        > "Azeem M. Suleman" <asuleman@verco m.com> wrote in message
        > news:%23g8gl3z6 DHA.1816@TK2MSF TNGP12.phx.gbl. ..> Hello,[color=green]
        > >
        > > I need to use Csharp compiler and an interpretor. In my application user
        > > will use the application and application will write CSharp code on[/color]
        > backend.[color=green]
        > > But now i don't need to reinvent the wheel, just need to know how i can[/color]
        > give[color=green]
        > > user an option to build the project which will compile and make an
        > > executable file.
        > >
        > > thanks.
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Miha Markic [MVP C#]

          #5
          Re: CSharp Compiler / Interpretor

          Hi,

          You'll have to specify parameters.Refe rencedAssemblie s to let compiler knows
          which assemblies you reference in your code.

          --
          Miha Markic [MVP C#] - RightHand .NET consulting & development
          miha at rthand com


          "Azeem M. Suleman" <asuleman@verco m.com> wrote in message
          news:em7a4%2306 DHA.2560@TK2MSF TNGP09.phx.gbl. ..[color=blue]
          > Yeah i looked on msdn, is their any implementation sample for it. Like for
          > basic idea i found this article:
          >
          >[/color]
          http://support.microsoft.com/default...NoWebContent=1[color=blue]
          >
          > But it didn't compile windows form and other controls.
          >
          > Thanks.
          > "Miha Markic [MVP C#]" <miha at rthand com> wrote in message
          > news:uQYdv%23z6 DHA.1556@tk2msf tngp13.phx.gbl. ..[color=green]
          > > Hi Azeem,
          > >
          > > Check out Microsoft.CShar p.Compiler class.
          > >
          > > --
          > > Miha Markic [MVP C#] - RightHand .NET consulting & development
          > > miha at rthand com
          > > www.rthand.com
          > > "Azeem M. Suleman" <asuleman@verco m.com> wrote in message
          > > news:%23g8gl3z6 DHA.1816@TK2MSF TNGP12.phx.gbl. ..> Hello,[color=darkred]
          > > >
          > > > I need to use Csharp compiler and an interpretor. In my application[/color][/color][/color]
          user[color=blue][color=green][color=darkred]
          > > > will use the application and application will write CSharp code on[/color]
          > > backend.[color=darkred]
          > > > But now i don't need to reinvent the wheel, just need to know how i[/color][/color][/color]
          can[color=blue][color=green]
          > > give[color=darkred]
          > > > user an option to build the project which will compile and make an
          > > > executable file.
          > > >
          > > > thanks.
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • AirPete

            #6
            Re: CSharp Compiler / Interpretor

            Azeem M. Suleman wrote:[color=blue]
            > Yeah i looked on msdn, is their any implementation sample for it.
            > Like for basic idea i found this article:
            >
            >[/color]
            http://support.microsoft.com/default...NoWebContent=1[color=blue]
            >
            > But it didn't compile windows form and other controls.[/color]

            Did you reference System.Windows. Forms.dll?
            [color=blue]
            >[/color]
            [snip]


            Comment

            • Azeem M. Suleman

              #7
              Re: CSharp Compiler / Interpretor

              Where to reference that dll, as i'm just using this code. Any sample...Here
              is the concept code that i saw from the url:

              private void button1_Click(o bject sender, System.EventArg s e)
              {
              CSharpCodeProvi der codeProvider = new CSharpCodeProvi der();
              ICodeCompiler icc = codeProvider.Cr eateCompiler();
              string Output = "Output.exe ";
              Button ButtonObject = (Button) sender;

              textBox2.Text = "";
              System.CodeDom. Compiler.Compil erParameters parameters = new
              CompilerParamet ers();
              //Make sure we generate an EXE, not a DLL
              parameters.Gene rateExecutable = true;
              parameters.Outp utAssembly = Output;
              CompilerResults results =
              icc.CompileAsse mblyFromSource( parameters,text Box1.Text);

              if (results.Errors .Count > 0)
              {
              textBox2.ForeCo lor = Color.Red;
              foreach(Compile rError CompErr in results.Errors)
              {
              textBox2.Text = textBox2.Text +
              "Line number " + CompErr.Line +
              ", Error Number: " + CompErr.ErrorNu mber +
              ", '" + CompErr.ErrorTe xt + ";" +
              Environment.New Line + Environment.New Line;
              }
              }
              else
              {
              //Successful Compile
              textBox2.ForeCo lor = Color.Blue;
              textBox2.Text = "Success!";
              //If we clicked run then launch our EXE
              if (ButtonObject.T ext == "Run") Process.Start(O utput);
              }

              "AirPete" <x@x.x> wrote in message
              news:4ubUb.1305 7$uM2.6920@news read1.news.pas. earthlink.net.. .[color=blue]
              > Azeem M. Suleman wrote:[color=green]
              > > Yeah i looked on msdn, is their any implementation sample for it.
              > > Like for basic idea i found this article:
              > >
              > >[/color]
              >[/color]
              http://support.microsoft.com/default...NoWebContent=1[color=blue][color=green]
              > >
              > > But it didn't compile windows form and other controls.[/color]
              >
              > Did you reference System.Windows. Forms.dll?
              >[color=green]
              > >[/color]
              > [snip]
              >
              >[/color]


              Comment

              • Azeem M. Suleman

                #8
                Re: CSharp Compiler / Interpretor

                I found the solution.

                I just added:

                parameters.Refe rencedAssemblie s.Add("System.d ll");

                parameters.Refe rencedAssemblie s.Add("System.D rawing.dll");

                parameters.Refe rencedAssemblie s.Add"System.Wi ndows.Forms.dll ");

                It works fine. But it always loads from command prompt. How to handle that.
                I just need to pass C# code to compiler and generate executable in such a
                way that no process can be seen.

                Thanks.

                "AirPete" <x@x.x> wrote in message
                news:ev9Ub.1167 6$F23.4052@news read2.news.pas. earthlink.net.. .[color=blue]
                > Azeem M. Suleman wrote:[color=green]
                > > Hello,
                > >
                > > I need to use Csharp compiler and an interpretor. In my application
                > > user will use the application and application will write CSharp code
                > > on backend. But now i don't need to reinvent the wheel, just need to
                > > know how i can give user an option to build the project which will
                > > compile and make an executable file.
                > >
                > > thanks.[/color]
                >
                > Check out the Microsoft.CShar p.Compiler class.
                >
                > - Pete
                >
                >[/color]


                Comment

                • AirPete

                  #9
                  Re: CSharp Compiler / Interpretor

                  Azeem M. Suleman wrote:[color=blue]
                  > I found the solution.
                  >
                  > I just added:
                  >
                  > parameters.Refe rencedAssemblie s.Add("System.d ll");
                  >
                  > parameters.Refe rencedAssemblie s.Add("System.D rawing.dll");
                  >
                  > parameters.Refe rencedAssemblie s.Add"System.Wi ndows.Forms.dll ");
                  >
                  > It works fine. But it always loads from command prompt. How to handle
                  > that. I just need to pass C# code to compiler and generate executable
                  > in such a way that no process can be seen.[/color]

                  parameters.Comp ilerOptions = "/target:winexe";

                  Not tested, but should work.

                  - Pete
                  [color=blue]
                  >
                  > Thanks.[/color]
                  [snip]


                  Comment

                  • Azeem M. Suleman

                    #10
                    Re: CSharp Compiler / Interpretor

                    What to do for multiple files. Like if i have 3 class files at different
                    places and they all are using objects of each others....what will be the
                    parameter.....

                    Thanks.

                    "AirPete" <x@x.x> wrote in message
                    news:VHeUb.1325 1$uM2.2406@news read1.news.pas. earthlink.net.. .[color=blue]
                    > Azeem M. Suleman wrote:[color=green]
                    > > I found the solution.
                    > >
                    > > I just added:
                    > >
                    > > parameters.Refe rencedAssemblie s.Add("System.d ll");
                    > >
                    > > parameters.Refe rencedAssemblie s.Add("System.D rawing.dll");
                    > >
                    > > parameters.Refe rencedAssemblie s.Add"System.Wi ndows.Forms.dll ");
                    > >
                    > > It works fine. But it always loads from command prompt. How to handle
                    > > that. I just need to pass C# code to compiler and generate executable
                    > > in such a way that no process can be seen.[/color]
                    >
                    > parameters.Comp ilerOptions = "/target:winexe";
                    >
                    > Not tested, but should work.
                    >
                    > - Pete
                    >[color=green]
                    > >
                    > > Thanks.[/color]
                    > [snip]
                    >
                    >[/color]


                    Comment

                    Working...