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 theStartup
event.A type that derives from
Application
may overrideOnStartup
. The overridden method must callOnStartup
in the base class if theStartup
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
C++0X Has No Semaphores? How to Synchronize Threads
Difference Between Char A[] = String; and Char *P = String;
Convert Python Program to C/C++ Code
C++: Life Span of Temporary Arguments
Is It Good Practice to Null a Pointer After Deleting It
What Are the Mechanics of Short String Optimization in Libc++
What Happens to a Detached Thread When Main() Exits
Testing Stream.Good() or !Stream.Eof() Reads Last Line Twice
Return a 2D Array from a Function
How to Write a Large Buffer into a Binary File in C++, Fast
Position of Least Significant Bit That Is Set
Why Cast Unused Return Values to Void
How to Remove Unused C/C++ Symbols With Gcc and Ld
C++ Std::Set Update Is Tedious: I Can't Change an Element in Place
Why Isn't Vector≪Bool≫ a Stl Container
What Is the Closest Thing Windows Has to Fork()
Why Should the Copy Constructor Accept Its Parameter by Reference in C++