linux - 尝试在 Ubuntu 20.04 上的 VSCode 中运行 Hello World 项目时出现 Omnisharp 问题
问题描述
我正在尝试让 .Net 和 VSCode 在 Ubuntu 20.04 上运行。“dotnet run”命令确实可以正常运行程序,但是在 VSCode 中运行它会给我以下错误:
Starting OmniSharp server at 7/7/2020, 6:28:24 PM
Target: /home/ivlatin2012/Projects/HelloDotnetCore
OmniSharp server started with Mono 6.8.0.
Path: /home/ivlatin2012/.vscode/extensions/ms-dotnettools.csharp-1.22.1/.omnisharp/1.35.3/omnisharp/OmniSharp.exe
PID: 14939
System.TypeLoadException: Could not load type of field 'McMaster.Extensions.CommandLineUtils.CommandLineApplication:_validationErrorHandler' (36) due to: Could not load file or assembly 'System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
at OmniSharp.Stdio.StdioCommandLineApplication..ctor () [0x00000] in <11f4106bfdfd41759d0a0dc35f30dcd7>:0
at OmniSharp.Stdio.Driver.Program+<>c__DisplayClass0_0.<Main>b__0 () [0x00006] in <be19315b4efc4538b70abd1dc15c63a1>:0
at OmniSharp.HostHelpers.Start (System.Func`1[TResult] action) [0x0001c] in <a3beccf5923c417282767eebc9bf25e1>:0
我正在运行的 Program.cs 文件真的不多
using System;
namespace HelloDotnetCore
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
launch.json 文件如下所示:
{
// 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 Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
},
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/<target-framework>/<project-name.dll>",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"console": "internalConsole"
}
],
]
}
.csproj 文件如下所示
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
</Project>
任何帮助将非常感激。在过去的几年里,我一直远离任何 .Net,并且对 .Net Core 完全陌生。这是我正在尝试学习的 Pluralsight 课程的一部分,但已经被 VSCode 和 Omnisharp 卡住了。
解决方案
推荐阅读
- python - 为什么在熊猫中创建数据透视表时十进制不起作用?
- python - 对多个数组中的值求和的更有效方法
- javascript - 我在哪里可以找到 JavaScript 中 test() 方法的文档?
- recommender-systems - 为我的网站使用 DLRM/facebook 的推荐系统
- c# - 异步任务的 SemaphoreSlim 问题
- react-native - react-native-maps - 移动地图时标记不会消失
- r - 如何每天读取一个数据框,每天产生,和上一个比较对比
- python - 如何在 Python Scrapy 上获取文本
- kotlin - atomic kotlin Course 检查练习中的问题找不到参数的方法 compile() [org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.20]
- angular - 带有int参数的角度发布方法?