VSCode中的DotNet Core 3.0编译问题

时间:2019-10-06 12:55:47

标签: c# .net-core visual-studio-code vscode-debugger

我是DotnetCore和MS编程的新手。随着MS的新推动,使其更加不依赖于平台,我对我有兴趣尝试一下,看看它是否能按承诺的方式工作。就是说,我什至在从VSCode在Windows上的DotNetCore上获取helloworld程序工作时遇到了问题。在我的命令提示符和Visual Studio 2019(Mac的VS Studio for mac)上,一切似乎都正常运行。 Windows 10中的VSCode似乎有很大的压力,如果可以的话,我将不胜感激

我收到的错误是“找不到类型为coreclr的调试适配器”。无论我做什么,都会遇到此错误。 1.安装的Dotnet core 3.0 2.设置MSBuildSDKsPath env变量,该变量指向C:\ Program Files \ dotnet \ sdk \ 3.0.100 \ Sdks 3.多次重启机器

没有任何效果。这是示例代码以及我的launch.json。

using System;

namespace OOPExample
{
    public struct Dimensions {
        public double Length { get; }
        public double Width { get; }

        public Dimensions(double length, double width) {
            Length = length;
            Width= width;
        }

        public double Diagonal => Math.Sqrt(Length * Length + Width * Width);
    }

    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine($"Hello World - {new Dimensions(10.0, 15.0).Diagonal}");
        }
    }
}

这是我的launch.json

{
   // Use IntelliSense to find out which attributes exist for C# debugging
   // Use hover for the description of the existing attributes
   // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
   "version": "0.2.0",
   "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}/bin/Debug/netcoreapp3.0/OOPExample.dll",
            "args": [],
            "cwd": "${workspaceFolder}",
            // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
            "console": "internalConsole",
            "stopAtEntry": false
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}

当我执行dotnet build并从命令提示符运行dotnet时,一切都很好

dotnet构建:

C:\Users\Krishnan\Projects\DotNet\OOPExample> dotnet build
Microsoft (R) Build Engine version 16.3.0+0f4c62fea for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 12.86 ms for C:\Users\Krishnan\Projects\DotNet\OOPExample\OOPExample.csproj.
  OOPExample -> C:\Users\Krishnan\Projects\DotNet\OOPExample\bin\Debug\netcoreapp3.0\OOPExample.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.77

dotnet运行:

PS C:\Users\Krishnan\Projects\DotNet\OOPExample> dotnet run
Hello World - 18.027756377319946

enter image description here

如果您想知道我是如何创建这个项目的,那无非就是一个简单的 dotnet新控制台命令。所以没有幻想

5 个答案:

答案 0 :(得分:2)

首先,确保已为vs-code安装了官方的Microsoft C#扩展。 那么,如果仍然无法运行,那么您的for i in displayListCourseFilter.indices { for j in displayListCourseFilter[i].content.indices { var item = displayListCourseFilter[i].content[j] if pId == item.parentID { item.selectAll = "true" item.isSelected = "true" displayListCourseFilter[i].content[j] = item } } } 文件就会出现问题。

答案 1 :(得分:2)

也许这可以帮助有此问题的人:在过去的一周中,我两次解决了该错误。

首次卸载/重新安装OmniSharp C#扩展名。

第二次,将VSCode更新为最新版本。

我还没有弄清楚这两个问题是否相关,但是我在OmniSharp或VSC发行说明中没有看到关于它的任何内容。

答案 2 :(得分:1)

当我尝试开始调试时出现以下错误消息。

“找不到类型'coreclr'的调试适配器”。

如果也出现以下错误消息,例如我的情况,我建议您也考虑单击“开发人员工具”,因为我认为您很有可能会得到一个很好的提示在那里。

“扩展主机意外终止”。 Extension_host_terminated_unexpectedly

在上述消息的框中,单击“开发人员工具”,然后看到一些包含字符串“ kite”的错误消息,使我猜测,就我而言,这些错误消息可能来自我很久以前安装的扩展程序“ kite”。禁用此扩展并重新启动VS Code后,两个错误消息均未再次出现。 (现在我不确定重启是否必不可少。)我并不是说扩展风筝很麻烦。在您的情况下,问题可能出在其他扩展程序或扩展程序之外。我是说“开发人员工具”可能是暗示的金矿。

我还有另外一个喜讯。后来,即使启用了该扩展名“ kite”,这些错误消息也没有出现。我可以在不放弃此扩展的情况下开始调试。

答案 3 :(得分:0)

我收到 OPs 错误消息,但仅在开发容器中使用带有“.NET Core Launch (web)”配置的运行和调试时:

<块引用>

找不到调试类型“coreclr”的调试适配器描述符(扩展可能无法激活)

我注意到在 VS Code 的输出选项卡中,在 C# 控制台上,以下附加输出:

Installing C# dependencies...
Platform: linux, x86_64, name=ubuntu, version=20.04

Downloading package 'OmniSharp for Linux (x64)'
Retrying from 'https://roslynomnisharp.blob.core.windows.net/releases/1.37.8/omnisharp-linux-x64-1.37.8.zip'
Failed at stage: downloadPackage
Error: Failed to establish a socket connection to proxies: ["PROXY 127.0.0.1:8118"]

Dev Container 似乎从主机获取 HTTP_PROXYHTTPS_PROXY 环境变量,但作为访客容器,其 127.0.0.1 地址与主机计算机的 127.0.0.1 地址不同.

我通过 Windows-Pause > Advanced System Settings > Advanced > Environment Variables... > 使用从 ipconfig /all 返回的主机的“公共”IP 地址修复了这个问题,例如:

随后关闭并重新打开 VS Code,现在运行和调试在开发容器中按预期工作。

答案 4 :(得分:0)

我遇到了同样的问题,我只是从 dotnet 卸载了 Omnisharp 和所有扩展,关闭了 VSCode,然后重新打开了它,然后再次安装了所有内容(包 Omnisharp)。现在按预期工作。

只是为了让我注册我的 SO 是 Linux Ubuntu 20.04。