How do you debug C# in Visual Studio Code on Windows?
I have an aspnet core project set up, I can build and edit it in VS Code and it works great.
I've installed the C# Omnisharp extension as per all of the getting started guides show and it's really easy to get going, except for one hugely important thing...
How do you actually debug it on Windows? Every article / blog post that I've come across only shows C# debugging with OSX or Linux.
Debugging with Mono doesn't work, I get the following:
Mono Debug is not supported on this platform (Win32NT).
And you can't install the Mono-Debugger extension on Windows - only OSX and Linux. Which makes sense, but what are the steps to do this with Windows?
I must be missing something really easy - how do I set up C# debugging with Visual Studio Code on Windows?
I've stumbled upon it myself and found the answer in instalation guide of debugger:
https://marketplace.visualstudio.com/items?itemName=Unity.unity-debug
You should check whether you have launch.json file already. If so, delete it and after clicking a cogwheel on top of debug view, select Unity Editor from dropdown.
There is also a VSCode Unity plugin, which may overwrite the file every time you start the game in the editor. To disable this uncheck the "Edit/Preferences/VSCode/Always Write Launch File" checkbox
Related
I have developed an application for hololens with Unity that uses the Hololens' depth camera. I built it with il2cpp scripting backend and it runs well on the Hololens when I launch it from Visual Studio 2017 (community). But I want to be able to debug the app (and have the output in visual studio console) while it is running on the Hololens (because I need the camera frame to be received to see how it works).
Moreover, I want to be able to set breakpoints in my .cs scripts files in my #UWP script parts.
I have been searching for a long time on Microsoft documentation and didn't find the specific answers I was looking for.
The Unity - Manual and also Microsoft - Managed Debugging with Unity IL2CPP is your friend! Check the section Debugging in the Player
In short:
In the player settings enable the capabilities PrivateNetworkClientServer, InternetClientServer
In the build settings enable Development Build, ScriptDebugging and Wait For Managed Debugger.
Build your project to a solution. Open the solution in VisualStudio.
With the HL connected run it on Device. (As debug from VisualStudio or by deploying and starting it on the device itself). Alternatively via WiFi enter the IP of the HoloLens .. just takes a bit longer to deploy of course
Wait for the pop-up.
Open any script by double click from Unity in a second VisualStudio instance (so the project's c# solution is loaded)
Here you also set the breakpoints
Go to Debug-> Attach Unity Debugger
select the HoloLens and attach the debugger
on the HL close the pop-up
You can now set breakpoints and debug c# code as usual while the HoloLens is actually running the Il2CPP solution.
I found the answer to my problem!
In order to debug c# code directly running on the Hololens, I did as follow:
In Unity :
Build Setting -> Player settings -> Other settings -> Scripting backend = .NET
Build Settings :
Build configuration Debug
check Copy reference
check Unity c# project
check development build
Then you can build
In Visual Studio 2017
Debug - x86 - Device (or remote machine)
If needed : In Solution Explorer -> For each solution -> alt+Enter -> Under Build tab check Allow unsafe code
Then you can set your break points where ever you want !
Hope this helps
Just adding a note in here, if anyone should drop by: The accepted answer is not seen as a solution going forward from 2019 as .NET backend is deprecated: See ths approach for debugging:
https://learn.microsoft.com/en-us/archive/blogs/appconsult/how-to-debug-unity-projects-with-il2cpp-backends-on-the-hololens
I'm using Visual Studio Code, as a code editor for Unity 5.
Visual Studio Code updated itself, after that I found that my C# IntelliSense seems to be broken. It doesn't show suggestions for my classes, it shows only c# syntax suggestions. I've checked all the settings, and logs so everything seems to be correct. There is right workspace settings, OmniSharp is running an no errors in Log. I've tried uninstall/install VSCode but no luck. I can't understand what is the problem, and I need your help.
Any solutions? Screenshots are below.
It may have to do with the C# Omnisharp plugin.
Support for .csproj projects has been temporarily disabled on OS X and Linux. This will impact anyone doing .csproj development on OS X or Linux (e.g. Unity, Xamarin, etc.). Rest assured that this will be restored in the near future. However, for now, you can use the Legacy C# Support extension.
https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp
The shop where I work is currently using VB6 for development using controls and libraries. Someone once showed me how to use Visual Studio to be able to debug this code by simply creating a console application in C# and then changing a few options. He showed me this in VS2010, but I am now using 2015. When I go into the project properties and go to the Debug tab, the option for "Enable unmanaged debugging" is not there. Did Microsoft remove this option? I have searched the web quite a bit, but have had no luck finding a solution.
Also, for kicks, I also have 2010 installed on my machine. The option is available there, however when I attempt to run and debug I get a LoaderLock failure. After researching it I found that I have to disable the exception in Visual Studio. However, it would appear that my exceptions are locked down and I cannot change them as they are all greyed out. I am an administrator on the machine I am using, but I am unsure of where or what I need to change to enable me to change the exception settings.
Any recommendations on either issue would be greatly appreciated. It's not a show stopper for me, but a HUGE inconvenience.
Im playing with the new Visual Studio Code on Windows 8.1 and create a new project template with the yo and i could see it running on my browser, but im not able to debug it, i set a break point in some action and it doesnt hit. On the debug option of vsCode it asks for attach a debug, but i cant find how to do it.
At the VsCode website theres a paragraph saying:
Debugging
Visual Studio Code and ASP.NET 5 are in preview and at this time debugging is not supported on OS X and Linux. Rest assured, we are working hard to bring these experiences to you in the near future.
Is there something that im missing here?
Thanks.
Visual Studio Code Preview does not support ASP.Net 5 debugging now. It only supports debugging Mono applications.
https://code.visualstudio.com/Docs/FAQ#_debugging
I have .net application (GUI as well as PowerShell) built against 4.5. My OS is server 2012. When I attach my application to 2013 visual studio, the debugger is not working sometimes. Its not evaluating expression or showing locals (and also watch window/immediate window nothing works - its as if the project is build with release). But I have build with 'Debug' configuration. And as mentioned same thing works when I simply attach with VS 2012 ( yes, I have 2k13 and 2k12 SXS)
Please note that if I attach the same process with the same settings (managed debugging), to Visual Studio 2012 it always works.
I made sure the symbols are loaded (by checking modules tab in visual studio + debug + windows), break points are hit.
Any thoughts on what might be the issue? All the updates are up-to-date as well.
Its kind of annoying to launch vs 2012 just to debug, when I am using VS 2k13 IDE for development.
Regards!
If you are facing the same issue, please look at http://weblog.west-wind.com/posts/2013/Nov/21/Visual-Studio-2013-Could-not-evaluate-Expression-Debugger-Abnormality for details.
Here is the answer which solved for me:
I have set the flag "use managed compatibility mode" in Tools | Options | Debugger | General.
For details, take a look at the link as he explained it nicely as a story :)
Am happy it worked, otherwise I just had to load project in vs 2k12 just to debug it which is annoying.
EDIT on 12th June 2014
I have updated my dev environments with visual studio 2013 update 2 (http://www.microsoft.com/en-us/download/details.aspx?id=42666) (as per Maria's suggestion below) and removed "using managed compatibility mode". I will be testing my apps (ps cmdlets, gui, services) and update you in couple of weeks if the debugger is ok for me.
EDIT on 26th June 2014
I have tested my apps and luckily for me everything is working nicely :). Even the debugger is doing pretty good job with new async/await model. So, see if you can upgrade to 'update 2' - hopefully this works in your environment too?. Thanks to Maria and debugger's team!
Regards.
I deleted all my breakpoints and then it started working, with Visual Studio 2013 Update 1. This was one of the suggestions from the blog post mentioned by Dreamer.
We have released a fix for the issue you are describing in Update 2 CTP 2 of Visual Studio -
Please let me know if that doesn't resolve your issue!
Thanks!
Maria - Visual Studio Debugger
Please note that while the accepted answer probably will fix the problem for now, it's best to be aware of the drawbacks of this solution. Making this change will make VS 2013 use the older style debugger for all you projects. It is a global setting. There are other ways to locally change this for a single project. Please read here for more info on this:
http://blogs.msdn.com/b/visualstudioalm/archive/2013/10/16/switching-to-managed-compatibility-mode-in-visual-studio-2013.aspx
We have a custom expression evaluator and our own language and this warning message to change the settings always appears even after I change the project settings to those specified in the blog.
<DebugEngines>{351668CC-8477-4fbf-BFE3-5F1006E4DB1F}</DebugEngines>
Is there something else?
Our clients are using VS2013 pro. I've turned off all the "Enable the Visual Studio hosting process" for all our projects and also added the property to our clients projects. I still see the warning each time I attack to w3wp.exe.
IMPORTANT NOTE: If your project is using the Visual Studio hosting process (the default for many project types), you must disable the hosting process for this fix to correctly change the debug mode. To disable the hosting process go to the Debug pane on the project properties page, and uncheck "Enable the Visual Studio hosting process"
You can resolve this error by applying below points
Sol 1:
1) Restart visual studio and re-open your project.
2) Open your project bin directory and delete DLL of that code where your debugger is not working properly.
3) Then again add DLL reference in the bin directory.
4) Remove all breakpoints.
5) Build project.
6) attach with one w3wp.exe process in attach to process window
7) Enjoy your problem has been resolved.
If above solution is not working then you can try solution that has been provided on bellow link
http://weblog.west-wind.com/posts/2013/Nov/21/Visual-Studio-2013-Could-not-evaluate-Expression-Debugger-Abnormality
I had a similar problem debugging where this error occurred from a return from creating a class. The class initialized fine (using "new classname()") but then it gave the "cannot evaluate expression" error on the return. Though it worked on previous visual studio versions, running on VS 2017 it crapped out.
After a lot of head banging, it turned out that private variables in the class, especially things like arraylists and other classes, needed to be declared with initial values, even if set to null.
Once that was done, everything worked, even though the solution "appeared" to have nothing to do with the problem and gave no apparent clue of where the problem occurred.
We had this problem with PostSharp extension version 5.0.32 with VS2013 Update 5.
Our workaround was downgrade PostSharp extension to version 4.3.19 or disable it.
Set AutoEventWireup="true" on aspx header file. This will turn debug mode on.