0

I am using the following batch script code to compile c# code but what I see is a black window (csc.exe) flashes and I can not see the exe file created.

start /wait C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe /out:aa.exe Program.cs
start aa.exe
pause

I want to create the file aa.exe at the same location as Program.cs

Basically what I want is to dynamically compile the code in Program.exe and run it. I am

using this following references:  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
using System.Net.Mail;
Akshay J
  • 5,362
  • 13
  • 68
  • 105
  • Here's more info on the subject: [Command-line Building With csc.exe](http://msdn.microsoft.com/en-us/library/vstudio/78f4aasd.aspx) – Jeremy Thompson Nov 21 '12 at 04:20

3 Answers3

3

Don't forget to add the references in the command:

/reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\<dotnet_version>\Microsoft.CSharp.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\<dotnet_version>\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\<dotnet_version>\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\<dotnet_version>\System.dll"
Daniel San
  • 1,937
  • 3
  • 19
  • 36
2

Rather than using start to launch the program, consider cmd. If you use cmd /K it should stay open after the command runs, giving you time to inspect the output.

jimbo
  • 11,004
  • 6
  • 29
  • 46
1

Use:

csc.exe /out:StackBackTraceOrRT_FATAL.exe StackBackTraceOrRT_FATAL.cs

Or you want use `CSharpCodeProvider?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
  • No I dont want to use any precompiled code. I want to compile on the fly and execute it. – Akshay J Nov 21 '12 at 03:32
  • @AkshayJ: See MSDN what can do CSharpCodeProvider. It is the programmable wrapper against C# Compiler to compile a code from string and generate an assembly, both on disk or in memory. And execute by demand. – abatishchev Nov 21 '12 at 06:45