visual-studio - 如何在 WSL2 和其他应用程序中打开 Visual Studio?

标签 visual-studio ubuntu windows-subsystem-for-linux

我已经在 wsl2 上安装了 ubuntu 18.04。我知道使用命令“代码”。您可以打开 VS Code,但我想知道是否有适用于所有应用程序的命令,您可以从 wsl2 终端打开它们,例如 Visual Studio 的命令?

最佳答案

默认情况下,WSL 启用了“Interop”,这允许您从 WSL 中运行/启动任何 Windows 可执行文件。同样默认情况下,WSL 将 Windows 路径附加到您的 WSL 路径(也在 /etc/wsl.confg 的同一 Interop 部分中控制)。

因此只要 Windows 应用程序在路径中,appname.exe 就会工作。例如,notepad.exe 将启动记事本。

VSCode 不需要 .exe 的原因是因为 Windows 版本提供了一个 shell 脚本(code),旨在与 WSL 一起使用。

对于不在路径上的应用程序,您可以编辑 WSL 路径(例如,在您的 .bashrc 中)或提供完整路径,例如:

/mnt/c/Program\ Files/Windows\ Photo\ Viewer/ImagingDevices.exe

请注意,您需要考虑 Linux/POSIX 路径与 Windows 等效路径之间的差异。例如:

notepad.exe ~/test.txt

... 不会工作,因为记事本不会理解 Linux 路径。 WSL 提供了 wslpath 命令来转换路径:

notepad.exe $(wslpath -w ~/test.txt)

notepad.exe '\\wsl$\Ubuntu\home\username\test.txt'

请注意:这是一个不好的例子,只是为了便于理解。不要使用 notepad.exe 编辑 Linux 文件,因为记事本会添加 Linux 应用程序无法正确处理的 CRLF(DOS 行结尾)。

关于visual-studio - 如何在 WSL2 和其他应用程序中打开 Visual Studio?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66567982/

相关文章:

python - 如何在 Visual Studio IronPython 项目中配置导入路径

c# - WPF 中的 Shapes 是否有单击事件和 Children

ruby-on-rails - rbenv 不能在 ubuntu 上使用 rbenv 和 ruby​​-build 工作吗?

r - doRedis 在 Ubuntu Linux、R 和 RStudio 中出现奇怪的套接字连接错误

windows-subsystem-for-linux - WSL 停止工作并出现错误 : 0x80070003

c - 在带有数学库的 Windows 上的 Ubuntu Bash 上出现 gcc 问题

css - @supports 不会在 Visual Studio LESS 文件中转换

c# - VS代码右键菜单新建类c#

linux - 在循环内运行脚本 - 回显文件名

c++ - 无法在 vs2017 的 linux 子系统上包含 header