簡體   English   中英

使用 Visual Studio C# 傳遞命令行參數

[英]Passing command line parameters with Visual Studio C#

如何為我在 Visual Studio 中調試的控制台應用程序設置命令行參數? 我已經在 Eclipse 中完成了這個,Visual Studio 中是否有類似的選項?

可以在項目Properties窗口的Debug標簽中設置Command Line Arguments

在此處輸入圖片說明

或者,可以選擇將StartArguments元素添加到.csproj.user文件中:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <PublishUrlHistory />
    <InstallUrlHistory />
    <SupportUrlHistory />
    <UpdateUrlHistory />
    <BootstrapperUrlHistory />
    <ErrorReportUrlHistory />
    <FallbackCulture>en-US</FallbackCulture>
    <VerifyUploadedFiles>false</VerifyUploadedFiles>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
    <StartArguments>Argument1 Argument2</StartArguments>   <<== THIS LINE
  </PropertyGroup>
</Project>

我只想添加可以通過Visual Studio 2010 項目菜單訪問圖片中顯示的菜單,然后一直到項目名稱屬性

在 2020 年,如果您現在使用 VSCode,則可以在 lauch.json 文件中設置參數。

 "version": "0.2.0",
"configurations": [
    {
        "name": ".NET Core Launch (console)",
        "type": "coreclr",
        "request": "launch",
        "preLaunchTask": "build",
        "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/CreatePRUDFileClient.dll",
        "args": [argument1, argument2, argument3],
        "cwd": "${workspaceFolder}",
        "console": "internalConsole",
        "stopAtEntry": false
    },
    {
        "name": ".NET Core Attach",
        "type": "coreclr",
        "request": "attach",
        "processId": "${command:pickProcess}"
    }
]

暫無
暫無

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

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