Wednesday, May 06, 2015

Debug a Visual Studio solution in Visual Studio Code on OSX

In my previous post I showed how to compile a .NET solution with Visual Studio Code with Mono on a Mac. This post shows how to set up debugging with Visual Studio Code with Mono on a Mac.

After the solution is build set a breakpoint in de code go to the 'Debug'-panel and press the green play-button in top. It will create a file named launch.json. This file is configured for node, but with some minor adjustments it can work for mono as well.

{
  "version": "0.1.0",
  "configurations": [
    {
      // Name of configuration;
      "name": "Hello",
      // Type of configuration.
      "type": "mono",
      // Workspace relative or absolute path to the program.
      "program": "bin/Debug/Hello.exe",
      // Automatically stop program after launch.
      "stopOnEntry": true,
      // Command line arguments passed to the program.
      "args": [],
      // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
      "cwd": ".",
      // Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
      "runtimeExecutable": null,
      // Environment variables passed to the program.
      "env": { }
    }, 
    {
      "name": "Attach",
      "type": "mono",
      // TCP/IP address. Default is "localhost".
      "address": "localhost",
      // Port to attach to.
      "port": 5858
    }
  ]
}

Save the file and you are ready to go!

12 comments:

Stas Korotaev said...

Hi, this doesn't work for me for some reason and says
launch: program '/Users/stals/Unity2D/dodgeBall/Temp/bin/Debug/dodgeBall.exe' does not exist

(why .exe? on osx?)

I put Temp before the bin/Debug part because this folder is not at the root of the project, as I can see yours is. Is it maybe because I still use Unity 4.6?

(ProductName is also set to the "dodgeBall")

Frank said...

Hi Stas. You have to build te solution (with xbuild settings: see Compile) before debugging. Also make sure the path (relative or absolute) exists.

Stas Korotaev said...

Yes, I built it but no .exe appears in the bin/Debug folder - only

Assembly-CSharp-Editor.dll
Assembly-CSharp-Editor.dll.mdb
Assembly-CSharp-firstpass.dll
Assembly-CSharp-firstpass.dll.mdb
Assembly-CSharp.dll
Assembly-CSharp.dll.mdb
ICSharpCode.NRefactory.dll
Mono.Cecil.dll
nunit.framework.dll
Unity.DataContract.dll
UnityEditor.dll
UnityEditor.Graphs.dll
UnityEngine.dll
Vectrosity.dll

are there.

I checked the path - '/Users/stals/Unity2D/dodgeBall/Temp/bin/Debug/ and it exists.

Here is a compilation log:

XBuild Engine Version 12.0
Mono, Version 4.0.1.0
Copyright (C) 2005-2013 Various Mono authors
Build started 5/17/2015 5:16:37 PM.
__________________________________________________
Project "/Users/stals/Unity2D/dodgeBall/dodgeBall.sln" (default target(s)):
Target ValidateSolutionConfiguration:
Building solution configuration "Debug|Any CPU".
Target Build:
Project "/Users/stals/Unity2D/dodgeBall/Assembly-CSharp-firstpass.csproj" (default target(s)):
Target PrepareForBuild:
Configuration: Debug Platform: AnyCPU
Target GenerateSatelliteAssemblies:
No input files were specified for target GenerateSatelliteAssemblies, skipping.
Target CoreCompile:
Skipping target "CoreCompile" because its outputs are up-to-date.
Done building project "/Users/stals/Unity2D/dodgeBall/Assembly-CSharp-firstpass.csproj".
Project "/Users/stals/Unity2D/dodgeBall/Assembly-CSharp.csproj" (default target(s)):
Target PrepareForBuild:
Configuration: Debug Platform: AnyCPU
Target GenerateSatelliteAssemblies:
No input files were specified for target GenerateSatelliteAssemblies, skipping.
Target CoreCompile:
Skipping target "CoreCompile" because its outputs are up-to-date.
Done building project "/Users/stals/Unity2D/dodgeBall/Assembly-CSharp.csproj".
Project "/Users/stals/Unity2D/dodgeBall/Assembly-CSharp-Editor.csproj" (default target(s)):
Target PrepareForBuild:
Configuration: Debug Platform: AnyCPU
Target GenerateSatelliteAssemblies:
No input files were specified for target GenerateSatelliteAssemblies, skipping.
Target CoreCompile:
Skipping target "CoreCompile" because its outputs are up-to-date.
Done building project "/Users/stals/Unity2D/dodgeBall/Assembly-CSharp-Editor.csproj".
Done building project "/Users/stals/Unity2D/dodgeBall/dodgeBall.sln".
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:01.0387740

Frank said...

Please make sure the solution file (.sln) contains a project which has an output assembly with the name dodgeBall.exe

Станислав Коротаев said...

How do I fix it if it doesn't?

Frank said...

Add the project to the solution file (in xml). You can also use Xamarin Studio to manage the entire solution.

William said...

How do I add the project to the solution file? I have the same problem. Thanks.

Frank said...

Wiliam, the solution file is normally managed by Visual Studio (not Code) or Xamarin Studio. I do not know why you have a solution with a missing project. However you can open the .sln file and add the project like:
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hello", "Hello.csproj", "{67DBE01C-352B-4DCD-82AF-FDC77E0789E2}"
EndProject

The second guid has to be the 'ProjectGuid' from the .csproj file to are referring.
I can not guarantee this will work. Therefor I advise you to use VS or Xamarin to manage the solution to keep all references and project configurations in place.

William said...

Actually I already have something like that:

Project("{03C737DE-B9ED-03AE-122E-29348AC7C90D}") = "bait", "Assembly-CSharp-firstpass.csproj", "{2C1AFA77-F93C-09CB-1127-C906E94AE00D}"
EndProject
Project("{03C737DE-B9ED-03AE-122E-29348AC7C90D}") = "bait", "Assembly-CSharp.csproj", "{1D2C46F2-28B1-BD0E-18B8-BDC445F3406C}"
EndProject
Project("{03C737DE-B9ED-03AE-122E-29348AC7C90D}") = "bait", "Assembly-CSharp-Editor.csproj", "{296AAD6F-6D08-4C9A-C828-69F0247D1B00}"
EndProject

But I do not see anywhere where it specifies a *.exe as the output. What did you mean by this?

Yu Zhang said...

The same problem.The *.exe not be found.Below is my .sln content.
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2008

Project("{A7C0DB72-6AA2-4FEF-5A89-E6E6D87070EC}") = "New Unity Project1", "Assembly-CSharp-vs.csproj", "{9121AA46-79A0-683F-A2FC-9861F5AE6610}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9121AA46-79A0-683F-A2FC-9861F5AE6610}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9121AA46-79A0-683F-A2FC-9861F5AE6610}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9121AA46-79A0-683F-A2FC-9861F5AE6610}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9121AA46-79A0-683F-A2FC-9861F5AE6610}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = Assembly-CSharp.csproj
Policies = $0
$0.TextStylePolicy = $1
$1.inheritsSet = null
$1.scope = text/x-csharp
$0.CSharpFormattingPolicy = $2
$2.inheritsSet = Mono
$2.inheritsScope = text/x-csharp
$2.scope = text/x-csharp
$0.TextStylePolicy = $3
$3.FileWidth = 120
$3.TabWidth = 4
$3.IndentWidth = 4
$3.EolMarker = Unix
$3.inheritsSet = Mono
$3.inheritsScope = text/plain
$3.scope = text/plain
EndGlobalSection

EndGlobal

Yu Zhang said...

My tasks.json'content is
{
"command" : "xbuild",
"args": ["New Unity Project1.sln"]
}

for IT the said...

I have read your blog its very attractive and impressive. I like it your blog.

Dot Net Training in Chennai Dot Net Training in Chennai .Net Online Training .Net Online Training Dot Net Training in Chennai Dot Net Training in Chennai


Dot Net Online Training Dot Net Online Training LINQ Online Training LINQ Online Training ASP.NET Online Training ASP.NET Online Training