右键单击文件夹后,“使用Visual Studio Code打开”选项未出现

170

我在Windows 7机器上刚刚安装了Visual Studio Code 1.1.1。当我右键单击文件夹时,没有出现“使用Code打开”选项。

输入图像描述


2
请编辑此帖子,以便提出一个问题。目前无法确定哪些答案正确回答了(假定的)问题,因此无法决定要点赞哪个答案。 - Nate T
28个回答

194

源自在Windows文件夹上右击并使用Visual Studio Code打开

  • Create file vsCodeOpenFolder.reg with this content (If you didn't choose the default installation path then you need to adjust the paths in this file):

     Windows Registry Editor Version 5.00
     ; Open files
     [HKEY_CLASSES_ROOT\*\shell\Open with VS Code]
     @="Edit with VS Code"
     "Icon"="C:\\Program Files (x86)\\Microsoft VS Code\\Code.exe,0"
     [HKEY_CLASSES_ROOT\*\shell\Open with VS Code\command]
     @="\"C:\\Program Files (x86)\\Microsoft VS Code\\Code.exe\" \"%1\""
     ; This will make it appear when you right click ON a folder
     ; The "Icon" line can be removed if you don't want the icon to appear
     [HKEY_CLASSES_ROOT\Directory\shell\vscode]
     @="Open Folder as VS Code Project"
     "Icon"="\"C:\\Program Files (x86)\\Microsoft VS Code\\Code.exe\",0"
     [HKEY_CLASSES_ROOT\Directory\shell\vscode\command]
     @="\"C:\\Program Files (x86)\\Microsoft VS Code\\Code.exe\" \"%1\""
     ; This will make it appear when you right click INSIDE a folder
     ; The "Icon" line can be removed if you don't want the icon to appear
     [HKEY_CLASSES_ROOT\Directory\Background\shell\vscode]
     @="Open Folder as VS Code Project"
     "Icon"="\"C:\\Program Files (x86)\\Microsoft VS Code\\Code.exe\",0"
     [HKEY_CLASSES_ROOT\Directory\Background\shell\vscode\command]
     @="\"C:\\Program Files (x86)\\Microsoft VS Code\\Code.exe\" \"%V\""
    
  • Double click it to create the registry entries.

  • If the "Open with Code" doesn't appear in the Explorer's context menu then you should restart your system.

  • If you're running the 64-bit or Insiders version of VS Code, change the path accordingly. ie. C:\\Users\\[user_name]\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe


4
我从未能在用户账户下使这个工作。但是对于管理员账户来说它是有效的。 - CalvinDale
7
我们如何在需要时删除这个选项? - AmiNadimi
4
现在有了64位的代码,只需将所有出现的"(x86)"替换为""即可。换句话说,将"Program Files (x86)"更改为"Program Files"。 - Michael Plautz
2
对于那些将其用于其他用途的人:上下文菜单“HKEY_CLASSES_ROOT\Directory\shell\vscode”和“HKEY_CLASSES_ROOT\Directory\Background\shell\vscode”的区别在于您是单击某个目录还是单击“无内容”(在win资源管理器中,您始终处于某个目录中)。 - Cadoiz
2
即使给定的源代码声明“重新安装VS Code更容易”,这些选项也在安装过程中。 - eddow
显示剩余5条评论

138

在安装(或重新安装)时,请特别检查所有复选框,尤其是:

将“使用 Code 打开”操作添加到 Windows 资源管理器文件上下文菜单
将“使用 Code 打开”操作添加到 Windows 资源管理器目录上下文菜单

安装 VS Code


10
已重新安装并确保勾选选项 - 对我来说已修复。 - Chris Moutray
@ar 如果您以管理员用户身份登录,则此方法可以正常工作。如果您不在管理员组中,则无法使用(基于安全原因的良好实践)。 - simonl
21
好的事情是你可以直接覆盖安装,无需先卸载! - Kamran Kia
很不幸的是,我的工作场所通过软件中心部署了VSCode,所以设置已经为我选择好了。 - Sildoreth
1
我重新激活了一个11年前的Stack Exchange账户,只是为了给这个帖子点赞。 - undefined

41

以下是Cockney Rhyming Jedi提供的适用于64位Visual Studio Code版本的文件版本:

Windows Registry Editor Version 5.00
; Open files
[HKEY_CURRENT_USER\Software\Classes\*\shell\Open with VS Code]
@="Edit with VS Code"
"Icon"="C:\\Program Files\\Microsoft VS Code\\Code.exe,0"
[HKEY_CURRENT_USER\Software\Classes\*\shell\Open with VS Code\command]
@="\"C:\\Program Files\\Microsoft VS Code\\Code.exe\" \"%1\""
; This will make it appear when you right click ON a folder
; The "Icon" line can be removed if you don't want the icon to appear
[HKEY_CURRENT_USER\Software\Classes\Directory\shell\vscode]
@="Open Folder as VS Code Project"
"Icon"="\"C:\\Program Files\\Microsoft VS Code\\Code.exe\",0"
[HKEY_CURRENT_USER\Software\Classes\Directory\shell\vscode\command]
@="\"C:\\Program Files\\Microsoft VS Code\\Code.exe\" \"%1\""
; This will make it appear when you right click INSIDE a folder
; The "Icon" line can be removed if you don't want the icon to appear
[HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\vscode]
@="Open Folder as VS Code Project"
"Icon"="\"C:\\Program Files\\Microsoft VS Code\\Code.exe\",0"
[HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\vscode\command]
@="\"C:\\Program Files\\Microsoft VS Code\\Code.exe\" \"%V\""

显然,集成的更新程序有时会删除此补丁,因此我必须在升级VS代码后重新应用它。 - Thomas Urban
1
使用这个版本后,我确实得到了新选项“将文件夹作为VS Code项目打开”,但没有简单的“在VS Code中打开”。我在这里做错了什么? - JonSnow
2
@JonSnow,你可以简单地更改@=后面的文本为任何你喜欢的内容。你可以将@="Open Folder as VS Code Project"改为@="使用JonSnow的编辑器打开"...哈哈 - askids
1
我注意到这个版本更新了HKEY_CURRENT_USER,而不是Wosi的答案中的HKEY_CLASSES_ROOT。这是否意味着使用这个版本,你可以在机器上进行注册表更改而无需成为本地管理员组的成员? - undefined
1
@SimonElms 我会这样假设的。这个根密钥及其线程是当前用户可写的。 - undefined

37

在我的情况下,我只需重新运行vscode设置并将所有复选框标记为已选中即可解决问题。在此输入图片描述


3
这正是推荐的做法。 - Yousha Arif
1
是的,不要使用Regedit解决方案,这个只需要大约1分钟就可以完成。 - Ben Power

27
如果您已经安装了VSCode,并且想要“使用代码打开”选项,只需从官方网站这里下载VSCode!安装程序运行时勾选“使用代码打开”选项,它将更新现有的VSCode安装,并加入“使用代码打开”选项。

1
这个选项应该是最佳答案! - Sebastian Johansson
我认为重新安装VSCode是最好的答案。添加注册表数据可能出错了。 - Yohanim

26

我想补充一下,很多人喜欢使用注册表方法,因为他们担心会丢失所有的设置。只需重新下载(如果您还没有下载文件),并重新安装即可。在重新安装时,请勾选

Add "Open with Code" action to Windows Explorer file context menu
Add "Open with Code" action to Windows Explorer directory context menu

正如其他答案中已经提到的那样,您的设置将保持不变。实际上,当它启动时,它会以您的工作目录启动,就好像您从未卸载过它一样。


我已经尝试了好几个月,但这从未让我成功,因为此选项被勾选后,它仍然没有将这些选项添加到“我的”上下文菜单中,只有在安装时我需要切换到管理员用户的上下文菜单。你忽略了问题的关键点。此外,我认为去修补注册表的人并没有考虑卸载某些软件可能会隐式地删除其设置。 - Thomas Urban
1
我不是很理解你的评论,但为了进一步阐述我的答案,我想说的是,也许有人想选择在注册表中调整设置,因为他们可能认为,在重新安装后卸载VS代码将恢复其自定义设置到默认值。我的答案是保证,如果您卸载并重新安装程序,您的设置仍将保持不变。 - Alf Moh
1
你甚至不需要卸载。只需下载安装程序,运行它,它就会在现有的安装之上进行安装。我认为人们害怕的是卸载。我几分钟前刚刚这样做了,它可以正常工作;所有设置和插件都完好无损。 - MSOACC

23

我的VSCode安装在这里:

C:\Users\saber\AppData\Local\Programs\Microsoft VS Code\code.exe

应该用你的电脑用户名替换SABER

在此输入图片描述

所以这个脚本大致是这样的:

将这个内容保存为*.reg文件

然后运行它:

Windows Registry Editor Version 5.00

; Open files
[HKEY_CLASSES_ROOT\*\shell\Open with VS Code]
@="Edit with VS Code"
"Icon"="C:\\Users\\saber\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe,0"
[HKEY_CLASSES_ROOT\*\shell\Open with VS Code\command]
@="\"C:\\Users\\saber\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\" \"%1\""
; This will make it appear when you right click ON a folder
; The "Icon" line can be removed if you don't want the icon to appear
[HKEY_CLASSES_ROOT\Directory\shell\vscode]
@="Open Folder as VS Code Project"
"Icon"="\"C:\\Users\\saber\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\",0"
[HKEY_CLASSES_ROOT\Directory\shell\vscode\command]
@="\"C:\\Users\\saber\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\" \"%1\""
; This will make it appear when you right click INSIDE a folder
; The "Icon" line can be removed if you don't want the icon to appear
[HKEY_CLASSES_ROOT\Directory\Background\shell\vscode]
@="Open Folder as VS Code Project"
"Icon"="\"C:\\Users\\saber\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\",0"
[HKEY_CLASSES_ROOT\Directory\Background\shell\vscode\command]
@="\"C:\\Users\\saber\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\" \"%V\""

将Visual Studio Code添加到Windows右键菜单中

\\saber\\替换为\\YOUR_PC_USER_NAME\\


请将此文件中的"saber"替换为您的文件夹名称 - saber tabatabaee yazdi
1
这是 VS Code 的安装路径,当你从 Microsoft 商店安装时。 - Mujeeb Shaikh

18

这些设置通常是针对VS Code每个用户单独存储的。

要为新用户设置:重新运行安装程序。


16

注意:以下内容适用于32位版本,64位版本请参考Cepharum的回答。

稍作修改以允许非管理员在其上下文菜单中获得功能:

  • Create file vsCodeOpenFolder.reg with this content (If you didn't chose the default installation path then you need to adjust the paths in this file):

    Windows Registry Editor Version 5.00
    ; Open files
    [HKEY_CURRENT_USER\Software\Classes\*\shell\Open with VS Code]
    @="Edit with VS Code"
    "Icon"="C:\\Program Files (x86)\\Microsoft VS Code\\Code.exe,0"
    [HKEY_CURRENT_USER\Software\Classes\*\shell\Open with VS Code\command]
    @="\"C:\\Program Files (x86)\\Microsoft VS Code\\Code.exe\" \"%1\""
    ; This will make it appear when you right click ON a folder
    ; The "Icon" line can be removed if you don't want the icon to appear
    [HKEY_CURRENT_USER\Software\Classes\Directory\shell\vscode]
    @="Open Folder as VS Code Project"
    "Icon"="\"C:\\Program Files (x86)\\Microsoft VS Code\\Code.exe\",0"
    [HKEY_CURRENT_USER\Software\Classes\Directory\shell\vscode\command]
    @="\"C:\\Program Files (x86)\\Microsoft VS Code\\Code.exe\" \"%1\""
    ; This will make it appear when you right click INSIDE a folder
    ; The "Icon" line can be removed if you don't want the icon to appear
    [HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\vscode]
    @="Open Folder as VS Code Project"
    "Icon"="\"C:\\Program Files (x86)\\Microsoft VS Code\\Code.exe\",0
    [HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\vscode\command]
    @="\"C:\\Program Files (x86)\\Microsoft VS Code\\Code.exe\" \"%V\""
    
  • Double click it to create the registry entries

  • If the "Open with Code" doesn't appear in the Explorer's context menu then you should restart your system.
基本上,我已经用HKEY_CURRENT_USER\Software\Classes替换了HKEY_CLASSES_ROOT。

1
感谢这个修复。很高兴看到我不是唯一一个尽可能少使用管理员权限的人。 - Thomas Urban

12

使用标准(非管理员)用户帐户时,上述所有注册表条目均不适用于我。

然后我将所有键都插入了 HKEY_LOCAL_MACHINE,然后它起作用了!

Windows Registry Editor Version 5.00

; when you right click a file
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\VSCode]
@="Open with Code"
"Icon"="C:\\Program Files\\Microsoft VS Code\\Code.exe,0"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\VSCode\command]
@="\"C:\\Program Files\\Microsoft VS Code\\Code.exe\" \"%1\""

; when you right click a folder
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\VSCode]
@="Open Folder in Code"
"Icon"="C:\\Program Files\\Microsoft VS Code\\Code.exe,0"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\VSCode\command]
@="\"C:\\Program Files\\Microsoft VS Code\\Code.exe\" \"%1\""

; when you right click a folder while holding shift
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\VSCode]
@="Open Folder in Code"
"Icon"="C:\\Program Files\\Microsoft VS Code\\Code.exe,0"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\VSCode\command]
@="\"C:\\Program Files\\Microsoft VS Code\\Code.exe\" \"%V\""

; when you right click the background, not on a particular file or folder.
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\LibraryFolder\Background\shell\VSCode]
@="Open Folder in Code"
"Icon"="C:\\Program Files\\Microsoft VS Code\\Code.exe,0"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\LibraryFolder\Background\shell\VSCode\command]
@="\"C:\\Program Files\\Microsoft VS Code\\Code.exe\" \"%V\""

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接