forked from madewokherd/wine-mono
-
Notifications
You must be signed in to change notification settings - Fork 0
/
csc-wrapper.cs
54 lines (45 loc) · 1.44 KB
/
csc-wrapper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
class CscWrapper
{
#if VERSION20
const string VERSION_STRING = "2.0-api";
#elif VERSION40
const string VERSION_STRING = "4.0-api";
#endif
static string GetCorlibName()
{
Assembly corlib = Assembly.ReflectionOnlyLoad("mscorlib");
return corlib.Location;
}
static void Main(string[] arguments)
{
var addStdlib = true;
for (int i = 0; i< arguments.Length; i++)
{
if (arguments[i] == "/nostdlib" || arguments[i] == "-nostdlib")
addStdlib = false;
arguments[i] = '"' + arguments[i] + '"';
}
string corlib = GetCorlibName();
string current_lib = Path.GetDirectoryName(corlib);
string api_lib = Path.Combine(Path.GetDirectoryName(current_lib), VERSION_STRING);
string mcs_name = Path.Combine(current_lib, "mcs.exe");
corlib = Path.Combine(api_lib, "mscorlib.dll");
var versionArguments = "";
if (addStdlib)
versionArguments = String.Format("/nostdlib /r:{0} /lib:{1} ", corlib, api_lib);
var process = new Process();
process.StartInfo.FileName = mcs_name;
process.StartInfo.Arguments = versionArguments + String.Join(" ", arguments);
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.OutputDataReceived += (sender, args) => Console.WriteLine(args.Data);
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
}
}