对 Visual Studio Code 使用的 C# 版本感到困惑 [英] Confused by the version of C# used by Visual Studio Code

查看:19
本文介绍了对 Visual Studio Code 使用的 C# 版本感到困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 10 (1809) 上安装了最新版本的 Visual Studio Code (1.39.2).我还安装了 OmniSharp C# 扩展(扩展标识符 ms-vscode.csharp,版本 1.21.5).

I have the latest version of Visual Studio Code (1.39.2) on Windows 10 (1809). I also installed the OmniSharp C# extension (extension identifier ms-vscode.csharp, version 1.21.5).

当我从集成终端运行命令 csc -langversion:? 时,我得到:

When I run the command csc -langversion:? from the integrated terminal, I get:

Microsoft (R) Visual C# 编译器版本 4.7.3190.0
对于 C# 5
警告 CS2008:未指定源文件
错误 CS1617:无效的选项'?对于/langversion;必须是 ISO-1、ISO-2、3、4、5 或默认

Microsoft (R) Visual C# Compiler version 4.7.3190.0
for C# 5
warning CS2008: No source files specified
error CS1617: Invalid option '?' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default

但是当我从 VS Code 之外的 Windows 命令行运行 csc.exe 时,指定完整路径如下:

But when I run csc.exe from a Windows command line outside of VS Code, specifying a full path like so:

C:\Users\myaccount\.vscode\extensions\ms-vscode.csharp-1.21.5\
    .omnisharp\1.34.5\.msbuild\Current\Bin\Roslyn\csc.exe -langversion:?

我明白了:

支持的语言版本:
默认
1
2
3
4
5
6
7.0(默认)
7.1
7.2
7.3(最新)
最新

Supported language versions:
default
1
2
3
4
5
6
7.0 (default)
7.1
7.2
7.3 (latest)
latest

我知道 VS Code 的终端可能会选择不同版本的 csc.exe,但是为什么会出现差异,以及如何配置 VS Code 以便我可以使用最新的 C# 编译器?

I understand that VS Code's terminal may be picking up a different version of csc.exe, but why the discrepancy, and how do I configure VS Code so that I can use the latest C# compiler?

我想真正让我困惑的是为什么 VS Code 没有使用安装在它自己的目录结构下的 csc.exe(即在 .vscode\extensions\ms-vscode.csharp-1.21.5...).

I guess what really perplexes me is why VS Code is not using the csc.exe that is installed under its very own directory structure (i.e. under .vscode\extensions\ms-vscode.csharp-1.21.5...).

推荐答案

当您运行 csc -langversion:? 时,无论通过 PATH 找到哪个版本的编译器正在运行环境变量.但是,当您运行 ~\.vscode\extensions\ms-vscode.csharp-1.21.5\.omnisharp\1.34.5\.msbuild\Current\Bin\Roslyn\csc.exe -langversion:? csharp 扩展正在使用的编译器版本正在运行.这些将与 csc.exe 的副本/版本不同.

When you run csc -langversion:?, whichever version of the compiler is found via the PATH environment variable is being is being run. However, when you run ~\.vscode\extensions\ms-vscode.csharp-1.21.5\.omnisharp\1.34.5\.msbuild\Current\Bin\Roslyn\csc.exe -langversion:? the version of the compiler that the csharp extension is using is being run. These will not be the same copy/version of csc.exe.

VS Code 中的终端(CMD 或 Powershell)不是这些的特殊版本,它们没有设置任何额外的环境变量,因此无论哪种方式您都应该看到相同的结果.

The terminal in VS Code (either CMD or Powershell) are not special versions of these, they don't have any extra environment variables set, so you should see the same results either way.

要纠正差异,请将最新版本的编译器安装到您的系统上,或更新您的 PATH 设置以包含 ~\.vscode\extensions\ms-vscode.csharp-1.21.5\.omnisharp\1.34.5\.msbuild\Current\Bin\Roslyn\csc.exe 的任何其他版本之前.

To remedy the discrepancy either, install the latest version of the compiler on to your system, or update your PATH settings to include ~\.vscode\extensions\ms-vscode.csharp-1.21.5\.omnisharp\1.34.5\.msbuild\Current\Bin\Roslyn\ before any other version of csc.exe.

完成此操作后,重新启动 VS Code 和 windows 命令行,结果应该相同.

Once you've done this, relaunch both VS Code and the windows command line and the results should be identical.

这篇关于对 Visual Studio Code 使用的 C# 版本感到困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆