1

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.

enter image description here

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

1 Answer 1

2

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.

i.e. 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'

Sign up to request clarification or add additional context in comments.

1 Comment

You're absolutely correct. Minor addition: I believe you can also set "input-file.txt" > Properties to "Copy" in the MSVS UI (vs. manually hacking the .csproj).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.