dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.85k stars 669 forks source link

Extension will generate 'launch.json' to debug 'net46*' apps even though they can't be debugged #1365

Open chrmarti opened 7 years ago

chrmarti commented 7 years ago

From @RoboBurned on April 5, 2017 6:22

Steps to Reproduce:

  1. Create project.json based project project.json:
    {
    "version": "1.0.0-*",
    "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true
    },
    "dependencies": {
    "Microsoft.Extensions.Configuration": "*"
    },
    "frameworks": {
    "Net461": {}
    }
    }

    2 Write Hello world program.cs:

    
    using Microsoft.Extensions.Configuration;
    using System;

namespace ConsoleApplication { public class Program { public static void Main(string[] args) { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.Build(); Console.WriteLine("Hello World!"); } } }


2. Press F5 to debug

Actual results:
Application crashes with error in DEBUG CONSOLE
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.Configuration, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.
   at ConsoleApplication.Program.Main(String[] args)
The program '[22800] HelloWorld.exe' has exited with code -532462766 (0xe0434352).

If I run application by using dotnet run command application works as expected.

I suppose the issue with build process: After project is built I have the following file structure:
bin
bin\Debug
bin\Debug\net461
         HelloWorld.exe
         HelloWorld.pdb
bin\Debug\net461\win7-x64
         HelloWorld.exe
         HelloWorld.pdb
         Microsoft.Extensions.Configuration.dll
         System.Console.dll
         19 more DLLs....

Debug executes exe in net461 directory and fails because of unresolved dependences..

_Copied from original issue: Microsoft/vscode#23914_
gregg-miskelly commented 7 years ago

@RoboBurned what you are trying to do is never going to work as we don't support desktop framework debugging. You need to use Visual Studio for that.

Did you need to manually create your launch.json file? Or did you get this prompt? -

Info: Required assets to build and debug are missing from your project. Add them? Yes | Close

Support for Desktop framework (a.k.a. full framework) is tracked with https://github.com/OmniSharp/omnisharp-vscode/issues/813

RoboBurned commented 7 years ago

@gregg-miskelly I did not create launch.json and did not modified it manually. I see the prompt and pressed YES. My launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Launch (console)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "${workspaceRoot}\\bin\\Debug\\net461\\1.exe",
            "args": [],
            "cwd": "${workspaceRoot}",
            "console": "internalConsole",
            "stopAtEntry": false,
            "internalConsoleOptions": "openOnSessionStart"
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}
gregg-miskelly commented 7 years ago

@RoboBurned thanks. In this case we have a bug in our launch.json generation as we shouldn't be creating a launch.json for desktop framework apps.

DustinCampbell commented 7 years ago

Hmmm... did this regress or was it always a bug?

gregg-miskelly commented 7 years ago

I don't know.

WardenGnaw commented 7 years ago

https://github.com/OmniSharp/omnisharp-vscode/blob/master/src/assets.ts#L290

It seems like it never validates to see what frameworks is requested in project.json projects. containsDotNetCoreProjects() returns true since it found Net461.

DustinCampbell commented 7 years ago

That's what I was wondering. I suspect that I just assumed 'project.json' == '.NET Core' when I wrote the original asset generation code.

DustinCampbell commented 7 years ago

@gregg-miskelly, @WardenGnaw: Is this critical for 1.9, or is it OK to push to 1.10?

gregg-miskelly commented 7 years ago

I moved it.