I'm trying to run csc.exe (the C# compiler) from within an AppDomain created from my executable. However, what I'm seeing is that any argument passed to my executable also seems to be passed to csc.exe, even though I'm not providing any arguments.
Here's my complete application:
class Program
{
static void Main(string[] args)
{
var cscPath = @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Roslyn\csc.exe";
var appDomain = AppDomain.CreateDomain("csc");
appDomain.ExecuteAssembly(cscPath);
Console.ReadLine();
}
}
When I run this without providing any arguments to my program, I see what I expect:
warning CS2008: No source files specified.
error CS1562: Outputs without source must have the /out option specified
However, when I add "-test" to the command line of my executable (using my project's Debug tab in Visual Studio), I get this output:
error CS2007: Unrecognized option: '-test'
warning CS2008: No source files specified.
error CS1562: Outputs without source must have the /out option specified
The "-test" now shows up as an error to csc.exe, and I don't know why it's even seeing that parameter.
Obviously, this is a contrived example, and I'm not really trying to call csc.exe without any parameters, but this is the minimal example where I can see the behavior.
If I call csc.exe using Process.Start, I don't see this behavior.
Any help would be appreciated!