I can't pass arguments to my console app. I tried it like this:
App.exe arg1
App.exe "arg1"
App.exe
When I run the app with arguments, the app quits running without any messages.
When debugging there is nothing in string[] args
.
My C# project is a plain .net 4.5.2 command line project. My OS is Windows 10 x64.
Sample Code:
using System;
using System.Collections.ObjectModel;
using System.Management.Automation;
namespace Setup
{
class Program
{
static void Main(string[] args)
{
if (args.Length == 0)
{
using (PowerShell psInstance = PowerShell.Create())
{
string cmd = "Set-ExecutionPolicy RemoteSigned -Force; " +
"echo \"Set-ExecutionPolicy RemoteSigned -Force\"; echo \"\"; " +
"Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force; ";
psInstance.AddScript(cmd);
Collection<PSObject> PSOutput = psInstance.Invoke();
Console.WriteLine(psInstance.Streams.Error[0].ErrorDetails.Message);
foreach (var item in PSOutput)
{
if (item != null)
{
Console.WriteLine(item.BaseObject.ToString());
}
}
Console.ReadLine();
}
}
else
{
// Will not work
Console.WriteLine(args[0]);
}
}
}
}
Does anyone have an idea?