簡體   English   中英

構建配置並啟動 Arguments

[英]Build Configuration and Start Arguments

在啟動選項下的“命令行參數”中輸入的值是否會作為命令行 arguments 實際傳遞給發布配置中的可執行文件,或者它只是一個調試的東西。

問題是,部署時它會成為可執行文件的一部分嗎?

在此處輸入圖像描述

最終出現在 csproj 文件中,如下所示

<?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>

命令行 Arguments

官方文檔對此有詳細的介紹。

您還可以使用 Environment.CommandLine 或 Environment.GetCommandLineArgs 從控制台中的任何位置訪問命令行 arguments 或 Windows Forms 應用程序。

演示:

在此處輸入圖像描述

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();
            }
        }
    }

在此處輸入圖像描述

可執行程序:

獨立運行時:輸出如下:

在此處輸入圖像描述

“當您構建應用程序並將其提供給用戶運行時,它們不會成為您應用程序的一部分。” 駱駝是對的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM