dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.84k stars 666 forks source link

Cannot debug VS Code brought from Visual Studio #3793

Open alexberd opened 4 years ago

alexberd commented 4 years ago

The above project is a working Visual Studio template for Autodesk Revit plugins and I am trying to make it work with Visual Studio Code using Omnisharp.

RevitAddin - Visual Studio Code.zip

Project runs "dotnet build" command without error messages. Project runs debugging in Visual Studio where after build, configuration fires up the "Autodesk\Revit 2018\Revit.exe" application where the plugin is loaded to be debug. It seems that Visual Studio Code cannot properly understand how to fire up "Autodesk\Revit 2018\Revit.exe" application. Do we need any modification in the following configuration?

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <StartAction>Program</StartAction>
    <StartProgram>$(ProgramW6432)\Autodesk\Revit 2018\Revit.exe</StartProgram>
  </PropertyGroup>

The generated "launch.json" file is the following:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Launch (console)",
            "type": "coreclr",
            "request": "launch",
            "WARNING01": "*********************************************************************************",
            "WARNING02": "The C# extension was unable to automatically decode projects in the current",
            "WARNING03": "workspace to create a runnable launch.json file. A template launch.json file has",
            "WARNING04": "been created as a placeholder.",
            "WARNING05": "",
            "WARNING06": "If OmniSharp is currently unable to load your project, you can attempt to resolve",
            "WARNING07": "this by restoring any missing project dependencies (example: run 'dotnet restore')",
            "WARNING08": "and by fixing any reported errors from building the projects in your workspace.",
            "WARNING09": "If this allows OmniSharp to now load your project then --",
            "WARNING10": "  * Delete this file",
            "WARNING11": "  * Open the Visual Studio Code command palette (View->Command Palette)",
            "WARNING12": "  * run the command: '.NET: Generate Assets for Build and Debug'.",
            "WARNING13": "",
            "WARNING14": "If your project requires a more complex launch configuration, you may wish to delete",
            "WARNING15": "this configuration and pick a different template using the 'Add Configuration...'",
            "WARNING16": "button at the bottom of this file.",
            "WARNING17": "*********************************************************************************",
            "preLaunchTask": "build",
            "program": "${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll",
            "args": [],
            "cwd": "${workspaceFolder}",
            "console": "internalConsole",
            "stopAtEntry": false
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}

Any advice will be really appreciated. Many thanks, Alex

JoeRobich commented 4 years ago

@alexberd From looking at the generated launch.json, it seems there were problems loading your project.

Can you share the OmniSharp Log from the Output pane?

Also, does running the Run Build Task in VS Code build your project correctly?

-Joey

alexberd commented 4 years ago

Hi @JoeRobich and @cartermp, I am quite new to the omnisharp project and I am not sure how to set the launch.json and tasks.json files. Could you please advise how to create those files for the above project? (https://github.com/OmniSharp/omnisharp-roslyn/files/4647590/RevitAddin.-.Visual.Studio.Code.zip)

Any help would be really appreciated.

Project builds perfectly with .Net but not in VSCode. The current launch.json has automatically been created by VSCode but it does not seem right. The same for the tasks.json.

Below are the configurations I tried so far and the errors from the debug console. One of the messages says "Failed to run as a self-contained app". However my app is not self-contained, but a plugin for another application (Revit.exe). Is there any way I can define the execution to be done by Revit?

launch.json:

 "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        },

        {
            "logging": {
                "engineLogging": true
            },
            "name": ".NET Core Launch (console)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "${workspaceFolder}/bin/Debug/RevitAddin - Visual Studio Code.dll",
            "args": [],
            "cwd": "${workspaceFolder}",
            "console": "internalConsole",
            "stopAtEntry": false
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}

tasks.json:

"version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "shell",
            "args": [
                "build",
                // Ask dotnet build to generate full paths for file names.
                "/property:GenerateFullPaths=true",
                // Do not generate summary otherwise it leads to duplicate errors in Problems panel
                "/consoleloggerparameters:NoSummary"
            ],
            "group": "build",
            "presentation": {
                "reveal": "silent"
            },
            "problemMatcher": "$msCompile"
        }
    ]
}

DEBUG CONSOLE:

-> (C) {"command":"initialize","arguments":{"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"coreclr","pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true,"supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"locale":"en-us","supportsProgressReporting":true},"type":"request","seq":1}
-> (C) {"command":"launch","arguments":{"logging":{"engineLogging":false},"name":".NET Core Launch (console)","type":"coreclr","request":"launch","preLaunchTask":"build","program":"C:\\Users\\RevitAddin - Visual Studio Code\\RevitAddin - Visual Studio Code/bin/Debug/RevitAddin - Visual Studio Code.dll","args":[],"cwd":"C:\\Users\\RevitAddin - Visual Studio Code\\RevitAddin - Visual Studio Code","console":"internalConsole","stopAtEntry":false,"internalConsoleOptions":"openOnSessionStart","__sessionId":"01802ee3-2768-40db-98ee-021bccb0cc2c"},"type":"request","seq":2}
<- (E) {"seq":3,"type":"event","event":"output","body":{"category":"console","output":"-------------------------------------------------------------------\nYou may only use the Microsoft .NET Core Debugger (vsdbg) with\nVisual Studio Code, Visual Studio or Visual Studio for Mac software\nto help you develop and test your applications.\n-------------------------------------------------------------------\n"}}
-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------
<- (R) {"seq":4,"type":"response","request_seq":2,"success":true,"command":"launch"}
<- (E) {"seq":5,"type":"event","event":"initialized","body":{}}
-> (C) {"command":"setBreakpoints","arguments":{"source":{"name":"Command.cs","path":"c:\\RevitAddin - Visual Studio Code\\RevitAddin - Visual Studio Code\\Command.cs","checksums":[{"algorithm":"SHA1","checksum":"eb55cb848d71bc37c589a57b91fd48b39c765094"},{"algorithm":"SHA256","checksum":"03a45b125f9b7ed2e2f54ba6a54cc0450c32a0cde230048213b4cc29e7d02fb9"},{"algorithm":"SHA1","checksum":"c015394dfb59b30544b96cce9f71d9a96ea66b4a"},{"algorithm":"SHA256","checksum":"6ec8502a1eefeb6cc801d05f670df834b1146132ba1925ea440133550a8792a2"}]},"lines":[22],"breakpoints":[{"line":22}],"sourceModified":false},"type":"request","seq":3}
<- (R) {"seq":6,"type":"response","request_seq":3,"success":true,"command":"setBreakpoints","message":"","body":{"breakpoints":[{"id":1,"verified":false,"message":"The breakpoint is pending and will be resolved when debugging starts.","line":22}]}}
-> (C) {"command":"setExceptionBreakpoints","arguments":{"filters":["user-unhandled"]},"type":"request","seq":4}
<- (R) {"seq":7,"type":"response","request_seq":4,"success":true,"command":"setExceptionBreakpoints"}
-> (C) {"command":"configurationDone","type":"request","seq":5}
<- (E) {"seq":8,"type":"event","event":"output","body":{"category":"telemetry","output":"VS/Diagnostics/Debugger/vsdbg/ProcessCreate","data":{"VS.Diagnostics.Debugger.vsdbg.OSFamily":"Windows","VS.Diagnostics.Debugger.vsdbg.Version":"16.6.20415.1 commit:0184bb70e1ed40656c0dfa53125805036207007b","VS.Diagnostics.Debugger.vsdbg.WindowsVersion":"10.0.18362"}}}
<- (E) {"seq":9,"type":"event","event":"process","body":{"name":"C:\\Users\\RevitAddin - Visual Studio Code\\RevitAddin - Visual Studio Code\\bin\\Debug\\RevitAddin - Visual Studio Code.dll","systemProcessId":41600,"isLocalProcess":true,"startMethod":"launch"}}
<- (E) {"seq":10,"type":"event","event":"output","body":{"category":"telemetry","output":"VS/Diagnostics/Debugger/vsdbg/Launch","data":{"VS.Diagnostics.Debugger.vsdbg.OSFamily":"Windows","VS.Diagnostics.Debugger.vsdbg.Version":"16.6.20415.1 commit:0184bb70e1ed40656c0dfa53125805036207007b","VS.Diagnostics.Debugger.vsdbg.VisualizerFileUsed":false,"VS.Diagnostics.Debugger.vsdbg.WindowsVersion":"10.0.18362","VS.Diagnostics.Debugger.vsdbg.Launch.Duration":203,"VS.Diagnostics.Debugger.vsdbg.TargetType":"Live","VS.Diagnostics.Debugger.vsdbg.AdapterId":"coreclr","VS.Diagnostics.Debugger.vsdbg.SourceFileMappings":0}}}
<- (R) {"seq":11,"type":"response","request_seq":5,"success":true,"command":"configurationDone"}
<- (E) {"seq":12,"type":"event","event":"breakpoint","body":{"reason":"changed","breakpoint":{"id":1,"verified":false,"message":"No symbols have been loaded for this document.","line":22}}}
-> (C) {"command":"threads","type":"request","seq":6}
<- (R) {"seq":13,"type":"response","request_seq":6,"success":true,"command":"threads","message":"","body":{"threads":[]}}
<- (E) {"seq":14,"type":"event","event":"output","body":{"category":"stdout","output":"A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\\Users\\RevitAddin - Visual Studio Code\\RevitAddin - Visual Studio Code\\bin\\Debug\\'.\r\n"}}
A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Users\RevitAddin - Visual Studio Code\RevitAddin - Visual Studio Code\bin\Debug\'.
<- (E) {"seq":15,"type":"event","event":"output","body":{"category":"stdout","output":"Failed to run as a self-contained app. If this should be a framework-dependent app, add the C:\\Users\\RevitAddin - Visual Studio Code\\RevitAddin - Visual Studio Code\\bin\\Debug\\RevitAddin - Visual Studio Code.runtimeconfig.json file specifying the appropriate framework.\r\n"}}
Failed to run as a self-contained app. If this should be a framework-dependent app, add the C:\Users\RevitAddin - Visual Studio Code\RevitAddin - Visual Studio Code\bin\Debug\RevitAddin - Visual Studio Code.runtimeconfig.json file specifying the appropriate framework.
<- (E) {"seq":16,"type":"event","event":"output","body":{"category":"stderr","output":"The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core.\n"}}
The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core.
<- (E) {"seq":17,"type":"event","event":"output","body":{"category":"console","output":"The program '[41600] RevitAddin - Visual Studio Code.dll' has exited with code -2147450749 (0x80008083).\n"}}
The program '[41600] RevitAddin - Visual Studio Code.dll' has exited with code -2147450749 (0x80008083).
<- (E) {"seq":18,"type":"event","event":"exited","body":{"exitCode":-2147450749}}
<- (E) {"seq":19,"type":"event","event":"terminated","body":{}}
-> (C) {"command":"disconnect","arguments":{"restart":false},"type":"request","seq":7}
<- (E) {"seq":20,"type":"event","event":"output","body":{"category":"telemetry","output":"VS/Diagnostics/Debugger/vsdbg/DebugCompleted","data":{"VS.Diagnostics.Debugger.vsdbg.OSFamily":"Windows","VS.Diagnostics.Debugger.vsdbg.Version":"16.6.20415.1 commit:0184bb70e1ed40656c0dfa53125805036207007b","VS.Diagnostics.Debugger.vsdbg.WindowsVersion":"10.0.18362","VS.Diagnostics.Debugger.vsdbg.DebugCompleted.BreakCounter":0,"VS.Diagnostics.Debugger.vsdbg.AdapterId":"coreclr"}}}
<- (R) {"seq":21,"type":"response","request_seq":7,"success":true,"command":"disconnect"}
the-exodus commented 4 years ago

The library 'hostpolicy.dll' required to execute the application was not found in 'C:\\Users\\RevitAddin - Visual Studio Code\\RevitAddin - Visual Studio Code\\bin\\Debug\\'.\r\n"}}

Did you forget to copy a referenced assembly to the output-folder, or did you set the CWD to the wrong one?