[英]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>
官方文檔對此有詳細的介紹。
您還可以使用 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.