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;
1

3 Answers 3

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"
Sign up to request clarification or add additional context in comments.

Comments

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.

2 Comments

Yes ! That enabled me to see the error and its working fine now.
Marking correct answer helps notify others your problem is resolved and not to spend time trouebleshooting. cheers
1

Use:

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

Or you want use `CSharpCodeProvider?

2 Comments

No I dont want to use any precompiled code. I want to compile on the fly and execute it.
@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.

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.