You will have to specify command line arguments containing spaces (and possibly other characters that I'm not sure about). Maybe something like this:
var commandLine = string.Join(" ", args.Select(s => s.Contains(' ') ? "\"" + s + "\"" : s)); var newProcess = Process.Start("yourapplication.exe", commandLine);
In addition, instead of using
string[] args = Environment.GetCommandLineArgs();
Instead, you can simply accept them in your Main
method:
public static void Main(string[] args) { var commandLine = string.Join(" ", args.Select(s => s.Contains(' ') ? "\"" + s + "\"" : s)); var newProcess = Process.Start(Environment.GetCommandLineArgs()[0], commandLine); }
The vshost workaround you have now seems fine, otherwise you can disable the whole vshost thing by unchecking the "Enable Visual Studio Hosting Process" checkbox on the debug tab of your project. Some debugging features are disabled when you do this. Here is a good explanation for this.
EDIT
The best way around this is to get the codebase for building the entry point:
public static void Main(string[] args) { var imagePath = Assembly.GetEntryAssembly().CodeBase; var commandLine = string.Join(" ", args.Select(s => s.Contains(' ') ? "\"" + s + "\"" : s)); var newProcess = Process.Start(imagePath, commandLine); }
This will work with or without vshost enabled.
source share