简体   繁体   中英

Redirect input to .NET Core Console App on debugging in Visual Studio 2019

In a C# .NET Core Console App, how I can define a redirect input to app on debugging?

I've tried with "Application arguments" of project properties, but not work.

在此处输入图像描述

The application open and immediately closes.

In VSCode it is possible with args config of launch.json file: https://code.visualstudio.com/Docs/editor/debugging#_redirect-inputoutput-tofrom-the-debug-target

It's done in the same way. A Properties/launchSettings.json file should be generated, similar to this one:

{
  "profiles": {
    "YourProjectName": {
      "commandName": "Project",
      "commandLineArgs": "< input-file.txt"
    }
  }
}

Please note that, if you're debugging from Visual Studio, you need to make sure your input file is copied to the output folder so that the redirection works.

ie you can manually add this to the .csproj :

  <ItemGroup>
    <None Update="input-file.txt">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>

or, as @paulsm4 suggested, configure it via VS interface: input-file.txt -> Properties -> 'Copy'

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