Debugging With Command-Line Parameters in Visual Studio

Debugging with command-line parameters in Visual Studio

Yes, it's in the Debugging section of the properties page of the project.

In Visual Studio since 2008: right-click the project, choose Properties, go to the Debugging section -- there is a box for "Command Arguments". (Tip: not solution, but project).

Debugging with Command Arguments in Visual Studio not working

As explained in https://social.msdn.microsoft.com/Forums/vstudio/en-US/4097114c-8678-46bb-ba3b-7a2da8514efc/visual-studio-2017-not-passing-command-line-arguments-to-the-application?forum=vsdebug, you are setting the arguments only for x64 target when you need to set them for some other CPU.

It's possible that you're running x86 instead, where the arguments are empty.

The best method is to set them to "Any CPU" as it is very unlikely to be different depending on your target processor.

Debug Command line in Visual Studio code

You need to edit your configuration to receive command line arguments.

See this: Configuring launch.json

Debugging Outlook with command line arguments with visual studio

It seems that changing the Visual Studio start action from "start project" to "start external program" (pointing it to outlook) resolves the issue; the command line parameters are passed on and can be accessed from an add-in.

Are there any disadvantages to using "start external program" vs "start project" when debugging an outlook add-in in visual studio?

How can I get Visual Studio cmd parameters for debugging working?

Do not create a constructor with a parameter declared as [Optional]. It is never assigned. If you remove the attribute, you will even get a compilation error.

Instead use the built in Startup event of the Application type. From the documentation:

A typical Windows Presentation Foundation application may perform a variety of initialization tasks when it starts up, including:

  • Processing command-line parameters.

[...] application-scope properties and command-line parameters can only be used programmatically. Programmatic initialization can be performed by handling the Startup event [...]

Assign an event handler in App.xaml and implement it in App.xaml.cs.

<Application x:Class="YourWpfApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml"
Startup="App_OnStartup">
<Application.Resources>
<!-- ...your resources. -->
</Application.Resources>
</Application>
public partial class App : Application
{
private void App_OnStartup(object sender, StartupEventArgs e)
{
Console.WriteLine("accessed app");
if (e.Args.Length == 0)
{
Shutdown(-1);
}
else
{
Console.WriteLine("Before PONumber Setting");
PONumber = e.Args[0];
}
}

// ...other code.
}

An alternative is to override the OnStartup method in your App type. From the documentation:

OnStartup raises the Startup event.

A type that derives from Application may override OnStartup. The overridden method must call OnStartup in the base class if the Startup event needs to be raised.

public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

Console.WriteLine("accessed app");
if (e.Args.Length == 0)
{
Shutdown(-1);
}
else
{
Console.WriteLine("Before PONumber Setting");
PONumber = e.Args[0];
}
}

// ...other code.
}


Related Topics



Leave a reply



Submit