简体   繁体   中英

Build Configuration and Start Arguments

Will the value entered in "command line arguments" under start options be actually passed on as command line arguments to the executable in the release configuration or is it only a debug thing.

The question is, will it be part of the executable when deployed?

在此处输入图像描述

which ends up in the csproj file as shown below

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
    <StartArguments>-blah</StartArguments>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
    <StartArguments>-blah</StartArguments>
  </PropertyGroup>
</Project>

Command-Line Arguments

The official documentation has a detailed introduction to this.

You can also use Environment.CommandLine or Environment.GetCommandLineArgs to access the command-line arguments from any point in a console or Windows Forms application.

Demo:

在此处输入图像描述

using System;

namespace ConsoleApp2 {
    internal class Program {
        static void Main (string[] args) {
            if (args.Length == 0)
                Console.WriteLine("Please enter a numeric argument.");
            else
                foreach (string arg in args)
                    {
                    Console.WriteLine(arg);
                    }
            Console.ReadLine();
            }
        }
    }

在此处输入图像描述

exe:

When running independently: the following output:

在此处输入图像描述

" They will not be part of your application when you build it and give it to a user to run." Llama is right.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM