Pass arguments to executable.exe c #


I created an application in c # very simple.

static void Main(string[] args)
    Console.WriteLine("Cantidad de argumentos: {0}", args.Length);
    foreach (string argumento in args)
        Console.WriteLine("Argumentos: {0}", argumento);

Debugging works fine since I've set the parameters in the project properties.

But when you publish it generates a setup.exe and when you run it ( setup.exe arg1 arg2 ) it gives me the following error!


This is a console type application, when publishing the following files are generated:

The versions are saved inside the folder

When running setup.exe the application is launched but it does not receive the arguments.

This application I need to run with arguento from the windows console to execute it with a .bat and this put it in a scheduled task.

I hope you can help me.

Greetings and thanks!

asked by Cristian 20.09.2016 в 07:06

3 answers


The issue is that e setup.exe is the installer of the application and not the application itself

When you publish these by creating a ClickOnce installer to redistribute your development, you should run the setup.exe, install the application on the user's PC and then execute the application with the arguments

How to: Publish a ClickOnce application without using the Publish Wizard

If you go to the properties of the project you will surely see a flap like this

is where you configure the options that the installer generates, which when compiled / published will generate the setup.exe, but I repeat this is the installer, not the application.

answered by 20.09.2016 в 07:34

you can get the arguments in the following way

string[] args = Environment.GetCommandLineArgs();

foreach(string arg in args){
// tu codigo

But keep in mind that Environment.GetCommandLineArgs ( ) returns an array with the name of the executable and the rest of the arguments, that is, in your case you will have 3 elements.

answered by 20.09.2016 в 16:04

Setup is the distribution file, It is NOT the executable . If your code works and your project is called "parameters" (just to give an example), select Compile and Compile Parameters, This will generate an EXE, which is regularly found in the folder / BIN / Debug.

and execute it from the command console.


c: \ Users \ cristian \ documents \ executable> parameters.exe miparameter



c: \ Users \ cristian \ documents \ executable> parameters miparameter

answered by 11.12.2016 в 06:39