I installed VS Code and created a simple C# source. After installing OmniSharp and .Net Debugger extension, I want to start debugging the code.
VS Code asks me to Select Environment and by default there are Node.js and .Net Core.
I selected More... from the drop-down menu and tried to find an environment for standard .net framework (I mean the non-core version) but could not find any.
Does this mean VS Code only supports .NET Core?
For whatever reason, non-core .NET functionality is nowhere to be found in any of the GUI drop downs on my configuration, while your mileage may vary in that respect, directly editing launch.json always works. To convert an auto-generated dotnet core debug config to use non-core .NET, simply change the line "type":"coreclr" to "type":"clr". Here's an example configuration:
{
"name": ".NET Launch (console)",
"type": "clr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/Project/bin/Debug/net461/Project.exe",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"console": "internalConsole"
},
Related
Godot 4.0 beta has shipped with C# support, and it reportedly works out of the box with hot-reload support in Visual Studio.
I would like to get this working on my Mac, which doesn't have Visual Studio. I took the launchSettings.json and put it in my Godot project in "Properties/launchSettings.json" with this content (taken from what Visual Studio autogenerated):
{
"profiles": {
"Development": {
"commandName": "Executable",
"executablePath": "/path/to/Godot_csharp_b1.app/Contents/MacOS/Godot",
"commandLineArgs": "--debug-server tcp://127.0.0.1:6666",
"workingDirectory": "/path/to/my/project",
"authenticationMode": "None",
"remoteDebugEnabled": false,
"remoteDebugMachine": ""
}
}
}
Now I try to do this:
dotnet watch run --launch-profile Development
However, it doesn't work. It gives this error:
The launch profile "Development" could not be applied.
The launch profile type 'Executable' is not supported.
Unable to run your project.
Ensure you have a runnable project type and ensure 'dotnet run' supports this project.
A runnable project should target a runnable TFM (for instance, net5.0) and have OutputType 'Exe'.
The current OutputType is 'Library'.
Is it possible to work around this? Any way to run Godot on MacOS with hot reloading would be acceptable for me - command line or anything else.
I'm on MacOS + M1 if that is important.
Edit: My original answer misunderstood the question, but I will leave it below as it may be helpful.
Regarding hot reloading, I am not sure Godot 4 is capable of playing nicely with dotnet watch as I haven't been able to find much on it. However, I was able to find this outstanding issue regarding hot reload in Godot 4 beta 3, but that's about it. It will likely be some time before Godot 4 reaches stable, so this may change rapidly over the coming weeks.
If you are trying to debug a Godot 4 C# project with Visual Studio Code, you can do so with the following launch.json configuration. Note that Visual Studio and Visual Studio Code are two entirely different IDE's. Just place the snippet below in a file at .vscode/launch.json in your Godot project:
{
"version": "0.2.0",
"configurations": [
// For these launch configurations to work, you need to setup a GODOT4
// environment variable. On mac or linux, this can be done by adding
// the following to your .zshrc, .bashrc, or .bash_profile file:
// export GODOT4="/Applications/Godot.app/Contents/MacOS/Godot"
{
"name": "Play",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${env:GODOT4}",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
},
}
}
Make sure you have a GODOT4 environment variable that points to your Godot4 executable.
You will also need to place the snippet below in your .vscode/tasks.json file, since the launch configuration above depends on it to make sure that dotnet build is run before debugging.
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build"
],
"problemMatcher": "$msCompile",
"presentation": {
"echo": true,
"reveal": "silent",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false
}
}
]
}
If you are looking for Godot 3 launch.json configurations, you can find those here.
I'm using VS Code with the vscode-solution-explorer to develop a .NET solution.
For debugging, I've configured my .vscode/launch.json file to run a build solution task and to execute a specific C# project (.csproj file).
My problem is: this .NET solution uses the Microservices approach, so I have ~50 Web API projects and each time I need to debug a specific API, I need to open the .vscode/launch.json file and replace the project name in 4 different places.
What I would like to do is the same that I do in Visual Studio: I right-click in the project and select "Set as StartUp project", so every time I press F5 it will run this selected project.
My launch.json looks likes this:
{
"version": "0.2.0",
"configurations": [
{
"name": "MyProject",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/MyProject/bin/Debug/netcoreapp3.0/MyProject.dll",
"args": [],
"cwd": "${workspaceFolder}/MyProject.csproj",
}
]
}
You can create multiple configurations in launch.json file.
Check this post: How do I designate a startup project in VS Code?
Hope this helps.
I have a problem trying to debug applications written in .NET Core in Visual Studio Code. Here is the setup:
I'm using a virtual machine running Debian 9 (with the default GUI). I've installed .Net Core SDK 2.1, and Visual Studio Code 1.30.0. Installed the extensions for C# 1.17.1. I've created simple project:
class MyProgram
{
static void Main(string[] args)
{
Console.WriteLine("Hello You Angel!");
ProcessStartInfo startInfo = new ProcessStartInfo() { FileName = "/bin/bash", Arguments = "-c nautilus /home/", };
Process proc = new Process() { StartInfo = startInfo, };
proc.Start();
}
}
If I run the program, in executes, and produces the correct output.
In the debug window I pressed the gear button to edit the launch.jason file
Here it is what it looks like:
{
"version": "0.2.1",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/HelloWorld/bin/Debug/netcoreapp2.1/HelloWorld.dll",
"args": [],
"cwd": "${workspaceFolder}/HelloWorld",
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
"console": "integratedTerminal",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"externalConsole": false,
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
,]
}
I've put a breakpoint in the project:
and when I hit the green triangle button, the breakpoint it not hit. Actually I think that non of the code i executed at all.
Is there something I'm missing to get this app it debugging mode?
Please help!
I was having the same issue on a different setup. Running windows 10 using VSCode and dotnet sdk 2.2.
I found a few answers browsing through gissues Here.
And This one I think fixed my problem
I also noticed to make sure I was selecting the correct "c:/projectdir/bin/debug/projectname.dll" when asked to attach the debugger to a process.
After that VSCode successfully hit my breakpoint.
I hope this helps.
1) In terminal go to your project and write
dotnet restore
dotnet clean
dotnet build
2) Check paths of "program" and "cwd" in your configurations (launch.json).
In case anyone hits this problem when they have 'converted' a Class Library project to a Console Application here are the symptoms and cause that I found:
I had mistakenly created a Class Library when I actually wanted a Console Application. I've made this same mistake in .NET Framework projects before and so thought I'll just convert it, no problem. So I altered the Output Type and gave it a Startup Object. The project ran but breakpoints were not hit.
It took me a while to find out why; it was because I'd created the original Class Library project as a .NET Standard project. When I created a new project (same code) as .NET Core (rather than .NET standard) the breakpoints were hit.
Quite interesting that you can actually switch a .NET standard Class Library project to Console Application, as it appears you can't create that setup through the UI.
I switched my project file from netcoreapp3.0 to netcoreapp2.2 and everything build fine but my breakpoints did not hit. After deleting the bin and obj directories, I got an error that the executable dll could not be found. Turned out I had to also change my launch.json file.
In .vscode/launch.json make sure to check your program folder and executable exists.
VSCode Version: 1.8.0
OS Version: Win10 x64
Steps to Reproduce:
Create a new .net core cli app using "dotnet new"
Open the folder using VS code
Add two lines of code in Program.cs
string a = Console.ReadLine();
Console.WriteLine(a);
Switch to VS code debug window and start debugging, Debug Console window shows, and displays the first "Hello, World." output, and stops on the line of Console.ReadLine(), enter anything in the Debug Console and press Enter will be given err message of "Unable to perform this action because the process is running."
The question is how and where to enter text for Console.ReadLine() to accept during debugging, if I open a new cmd.exe and do a "dotnet run" it works fine, but in Visual Studio Code Debug Console it's not working.
To read input whilst debugging, you can use the console property in your configurations in launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"program": "${workspaceFolder}/bin/Debug/net5.0/your-project-name.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"console": "integratedTerminal"
}
]
}
You can either use "externalTerminal" or "integratedTerminal". The "internalConsole" doesn't appear to be working.
I use the integratedTerminal setting, as the terminal is inside VSCode itself. You will now be able to read input with Console.ReadLine();
Note: Also, internalConsole doesn't work, and it is by design. The reason this is, is because internalConsole uses the Debug Console tab to show the output of the Console.WriteLine. Since the input box in the Debug Console is used to run expression on the current stack, there's no place to pass in input that will go to Console.ReadLine. That's the reason you'll have to use something like integratedTerminal.
The screenshot below shows that the VSCode team knows this -
i am pretty new to c#-visual studio debugger...
try setting a breakpoint before your
Console.Readline()
and debug it by stepping through your code F10 (not F11).
it should stop at
Console.Readline()
and wait for your input.
I use visual studio code and plugin for C# version 1.10.0-beta1.
When I try turn of debug, I get error:
launch: launch.json must be configured. Change 'program' to the path
to the executable file that you would like to debug.
I use ubuntu 17.04
My settings:
{
"window.menuBarVisibility": "toggle",
"csharp.fallbackDebuggerLinuxRuntimeId": "ubuntu.16.10-x64",
"omnisharp.useMono": true,
}
My configuration launch.json
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/<target-framework>/<project-name.dll>",
"args": [],
"cwd": "${workspaceRoot}",
"stopAtEntry": false,
"console": "internalConsole"
}
What should I write in: "program": ?
First, make sure you have built your program. Then, go to the root directory of your program and find your target-framework and project-name under Debug folder.
For example, you have built a hello world program named console1 and your .netcore version is 1.1.0, you will change "program":
"${workspaceRoot}/bin/Debug//"
to "program":
"${workspaceRoot}/bin/Debug/netcoreapp1.1/console1.dll".
And you can start your debugging now if you have installed the dotnet core debugger.