Difference between revisions of "Visual Studio Code"

From ArchWiki
Jump to navigation Jump to search
(创建中文 Visual Studio Code页面)
(→‎Unable to move items to trash: Default trash is now "gio")
 
(33 intermediate revisions by 21 users not shown)
Line 1: Line 1:
[[Category:Development]]
 
 
[[Category:Text editors]]
 
[[Category:Text editors]]
 
[[ja:Visual Studio Code]]
 
[[ja:Visual Studio Code]]
 
[[zh-hans:Visual Studio Code]]
 
[[zh-hans:Visual Studio Code]]
'''Visual Studio Code''' ('''VSCode''') is a cross-platform, free and open-source (licensed under the MIT License) text editor developed by Microsoft and written in JavaScript and TypeScript. It is built on the Electron framework and is extensible using extensions, which can be browsed from within the text editor itself (via its extension gallery) or from https://marketplace.visualstudio.com/VSCode. While open-source, a proprietary build (licensed under an End-User License Agreement) provided by Microsoft is available and used as the basis for the {{AUR|visual-studio-code}} AUR package.  
+
[https://code.visualstudio.com/ Visual Studio Code] is a cross-platform, free and open-source (licensed under the MIT License) text editor developed by Microsoft and written in JavaScript and TypeScript. It is built on the Electron framework and is extensible using extensions, which can be browsed [https://marketplace.visualstudio.com/VSCode on the web] or from within the text editor itself. While the project is open-source, a proprietary build (licensed under an End-User License Agreement) is also provided by Microsoft. For an explanation of the mixed licensing, see [https://github.com/Microsoft/vscode/issues/60#issuecomment-161792005 this GitHub comment].
  
 
== Installation ==
 
== Installation ==
 
The following packages provide VSCode:
 
The following packages provide VSCode:
  
* {{AUR|visual-studio-code}}
+
* {{Pkg|code}} (open-source release)
* {{AUR|visual-studio-code-oss}}
+
* {{AUR|visual-studio-code-bin}} (Microsoft-branded release)
* {{AUR|visual-studio-code-git}}
+
* {{AUR|visual-studio-code-insiders}} (Microsoft-branded release, updated daily)
* ''code-oss'' from the unofficial [[Unofficial user repositories#pkgbuild-current|pkgbuild-current]]{{Broken section link}} repository. Further details can be found in its README [https://github.com/fusion809/PKGBUILDs/blob/master/README.md here]. {{Note|Bugs regarding binary packages from the ''pkgbuild-current'' repository can be reported on [https://github.com/fusion809/PKGBUILDs/issues GitHub]. Bugs regarding Visual Studio Code itself should be reported upstream.}}
+
* {{AUR|code-git}} (in-development open-source version)
 +
* {{AUR|vscodium-bin}} (another open-source version with a community-driven default configuration)
  
===Debugging C#===
+
The Microsoft [https://github.com/microsoft/ptvsd ptvsd] (Python Tools for Visual Studio Debug) server/module is available at {{AUR|python-ptvsd}}.
If you want to debug C# code install {{AUR|icu55}} otherwise you will end up with a 'Debug adapter process has terminated unexpectedly' error
 
  
 
== Usage ==
 
== Usage ==
  
Run {{ic|code}}.  
+
Run {{ic|code}} to start the application (or {{ic|code-git}} when using {{AUR|code-git}}).
  
 
If for any reason you wish to launch multiple instances of Visual Studio Code, the {{ic|-n}} flag can be used.
 
If for any reason you wish to launch multiple instances of Visual Studio Code, the {{ic|-n}} flag can be used.
Line 24: Line 23:
 
==Configuration==
 
==Configuration==
  
Visual Studio Code settings are stored in {{ic|~/.config/Code/User/settings.json}}.
+
{{Pkg|code}} stores settings in {{ic|~/.config/Code - OSS/User/settings.json}}.
 +
 
 +
{{AUR|visual-studio-code-bin}} stores settings in {{ic|~/.config/Code/User/settings.json}}.
  
 
===Integrated Terminal===
 
===Integrated Terminal===
Line 51: Line 52:
 
"terminal.external.linuxExec": "gnome-terminal"
 
"terminal.external.linuxExec": "gnome-terminal"
 
}}
 
}}
 +
 +
== Troubleshooting ==
 +
 +
=== Global menu not working in KDE/Plasma ===
 +
 +
Visual Studio Code uses DBus to pass the menu to Plasma, try installing {{Pkg|libdbusmenu-glib}}
 +
 +
=== Unable to move items to trash ===
 +
 +
By default, [https://electron.atom.io/ Electron] apps use {{ic|gio}} to delete files. Different trash implementations can be used by setting the {{ic|ELECTRON_TRASH}} [[environment variable]].
 +
 +
For example, for deleting files under [[Plasma]]:
 +
$ ELECTRON_TRASH=kioclient5 code
 +
 +
At the time of writing, Electron supports {{ic|kioclient5}}, {{ic|kioclient}}, {{ic|trash-cli}}, {{ic|gio}} (default) and {{ic|gvfs-trash}} (deprecated). More info is available at this [https://github.com/electron/electron/blob/master/docs/api/environment-variables.md#electron_trash-linux documentation page].
 +
 +
=== Unable to debug C# ===
 +
 +
If you want to debug C#[[.NET_Core|.NET]] (using the [http://www.omnisharp.net OmniSharp extension]) then you need to install the Microsoft branded release (from the AUR).  This is apparently because the .NET Core debugger is only licensed to be used with official Microsoft products - see https://github.com/OmniSharp/omnisharp-vscode/issues/1431#issuecomment-297578930
 +
 +
Using the the open-source package, debugging fails fairly quietly.  The debug console will just show the initial message and nothing more:
 +
{{bc|You may only use the Microsoft .NET Core Debugger (vsdbg) with
 +
Visual Studio Code, Visual Studio or Visual Studio for Mac software
 +
to help you develop and test your applications.}}
 +
 +
But in another way, you can use [https://github.com/Samsung/netcoredbg netcoredbg],{{AUR|netcoredbg}}
 +
 +
=== Unable to open .csproj with OmniSharp server, invalid Microsoft.Common.props location ===
 +
 +
You have to switch from mono to proper SDK version props.
 +
 +
{{hc|/opt/dotnet/sdk/{VERSION}/Sdks/Microsoft.NET.Sdk/Sdk/Sdk.props|
 +
$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props
 +
}}
 +
 +
Modify import to look like this:
 +
 +
{{hc|/opt/dotnet/sdk/{VERSION}/Sdks/Microsoft.NET.Sdk/Sdk/Sdk.props|
 +
/opt/dotnet/sdk/{VERSION}/Current/Microsoft.Common.props
 +
}}
 +
 +
=== Error from OmniSharp that MSBuild cannot be located ===
 +
 +
It's noted in the [https://github.com/OmniSharp/omnisharp-roslyn#introduction OmniSharp introduction] that Arch Linux users should install the {{AUR|msbuild-stable}} package.  Without it, you might get an error like:
 +
 +
{{hc|1=OmniSharp Log|2=
 +
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
 +
        Registered MSBuild instance: StandAlone 15.0 - "~/.vscode/extensions/ms-vscode.csharp-1.18.0/.omnisharp/1.32.11/omnisharp/msbuild/15.0/Bin"
 +
            MSBuildExtensionsPath = /usr/lib/mono/xbuild
 +
            BypassFrameworkInstallChecks = true
 +
            CscToolPath = ~/.vscode/extensions/ms-vscode.csharp-1.18.0/.omnisharp/1.32.11/omnisharp/msbuild/15.0/Bin/Roslyn
 +
            CscToolExe = csc.exe
 +
            MSBuildToolsPath = ~/.vscode/extensions/ms-vscode.csharp-1.18.0/.omnisharp/1.32.11/omnisharp/msbuild/15.0/Bin
 +
            TargetFrameworkRootPath = /usr/lib/mono/xbuild-frameworks
 +
System.TypeLoadException: Could not load type of field 'OmniSharp.MSBuild.ProjectManager:_queue' (13) due to: Could not load file or assembly 'System.Threading.Tasks.Dataflow, Version=4.5.24.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
 +
...}}
 +
 +
You might be able to build anyway (possibly depending whether you have {{Pkg|mono}} installed too)
 +
 +
=== Saving with "Retry as Sudo" does not work ===
 +
 +
This feature does not work in the {{Pkg|code}} package, because Microsoft does not support the way the Arch package is packaged (native instead of bundled Electron). See {{Bug|61516}} and the [https://github.com/Microsoft/vscode/issues/70403 upstream bug report] for more information.
 +
 +
The binary release {{AUR|visual-studio-code-bin}} does not have this issue, and the feature works there.

Latest revision as of 08:25, 8 October 2019

Visual Studio Code is a cross-platform, free and open-source (licensed under the MIT License) text editor developed by Microsoft and written in JavaScript and TypeScript. It is built on the Electron framework and is extensible using extensions, which can be browsed on the web or from within the text editor itself. While the project is open-source, a proprietary build (licensed under an End-User License Agreement) is also provided by Microsoft. For an explanation of the mixed licensing, see this GitHub comment.

Installation

The following packages provide VSCode:

The Microsoft ptvsd (Python Tools for Visual Studio Debug) server/module is available at python-ptvsdAUR.

Usage

Run code to start the application (or code-git when using code-gitAUR).

If for any reason you wish to launch multiple instances of Visual Studio Code, the -n flag can be used.

Configuration

code stores settings in ~/.config/Code - OSS/User/settings.json.

visual-studio-code-binAUR stores settings in ~/.config/Code/User/settings.json.

Integrated Terminal

View > Integrated Terminal or Ctrl + ` opens up an integrated terminal. By default, Bash is used with no additional arguments, although this can be changed. terminal.integrated.shell.linux sets the default shell to be used and terminal.integrated.shellArgs.linux sets the arguments to be passed to the shell.

Example:

~/.config/Code/User/settings.json
"terminal.integrated.shell.linux": "/usr/bin/fish",
"terminal.integrated.shellArgs.linux": ["-l","-d 3"]

External Terminal

If you are using Terminator as default terminal for Arch and you have an error on Visual Studio Code: Unable to launch debugger worker process (vsdbg) through the terminal. spawn truecolor ENOENT, you can change the terminal that will be used by Visual Studio to another terminal (eg gnome-terminal).

"terminal.external.linuxExec": "Yours alternative terminal" sets the default terminal to be used for exec debug.

Example:

~/.config/Code/User/settings.json
"terminal.external.linuxExec": "gnome-terminal"

Troubleshooting

Global menu not working in KDE/Plasma

Visual Studio Code uses DBus to pass the menu to Plasma, try installing libdbusmenu-glib

Unable to move items to trash

By default, Electron apps use gio to delete files. Different trash implementations can be used by setting the ELECTRON_TRASH environment variable.

For example, for deleting files under Plasma:

$ ELECTRON_TRASH=kioclient5 code

At the time of writing, Electron supports kioclient5, kioclient, trash-cli, gio (default) and gvfs-trash (deprecated). More info is available at this documentation page.

Unable to debug C#

If you want to debug C#.NET (using the OmniSharp extension) then you need to install the Microsoft branded release (from the AUR). This is apparently because the .NET Core debugger is only licensed to be used with official Microsoft products - see https://github.com/OmniSharp/omnisharp-vscode/issues/1431#issuecomment-297578930

Using the the open-source package, debugging fails fairly quietly. The debug console will just show the initial message and nothing more:

You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.

But in another way, you can use netcoredbg,netcoredbgAUR

Unable to open .csproj with OmniSharp server, invalid Microsoft.Common.props location

You have to switch from mono to proper SDK version props.

/opt/dotnet/sdk/{VERSION}/Sdks/Microsoft.NET.Sdk/Sdk/Sdk.props
$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props

Modify import to look like this:

/opt/dotnet/sdk/{VERSION}/Sdks/Microsoft.NET.Sdk/Sdk/Sdk.props
/opt/dotnet/sdk/{VERSION}/Current/Microsoft.Common.props

Error from OmniSharp that MSBuild cannot be located

It's noted in the OmniSharp introduction that Arch Linux users should install the msbuild-stableAUR package. Without it, you might get an error like:

OmniSharp Log
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: StandAlone 15.0 - "~/.vscode/extensions/ms-vscode.csharp-1.18.0/.omnisharp/1.32.11/omnisharp/msbuild/15.0/Bin"
            MSBuildExtensionsPath = /usr/lib/mono/xbuild
            BypassFrameworkInstallChecks = true
            CscToolPath = ~/.vscode/extensions/ms-vscode.csharp-1.18.0/.omnisharp/1.32.11/omnisharp/msbuild/15.0/Bin/Roslyn
            CscToolExe = csc.exe
            MSBuildToolsPath = ~/.vscode/extensions/ms-vscode.csharp-1.18.0/.omnisharp/1.32.11/omnisharp/msbuild/15.0/Bin
            TargetFrameworkRootPath = /usr/lib/mono/xbuild-frameworks
System.TypeLoadException: Could not load type of field 'OmniSharp.MSBuild.ProjectManager:_queue' (13) due to: Could not load file or assembly 'System.Threading.Tasks.Dataflow, Version=4.5.24.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
...

You might be able to build anyway (possibly depending whether you have mono installed too)

Saving with "Retry as Sudo" does not work

This feature does not work in the code package, because Microsoft does not support the way the Arch package is packaged (native instead of bundled Electron). See FS#61516 and the upstream bug report for more information.

The binary release visual-studio-code-binAUR does not have this issue, and the feature works there.