Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a quick implementation, adding "Open with Code" option to Windows 11 explorer's context menu #139640

Closed
wants to merge 1 commit into from

Conversation

strear
Copy link

@strear strear commented Dec 22, 2021

This PR fixes #127365

The added code follows the IExplorerCommand + app identity method recommended by Windows Blog, which is the minimal code necessary to implement this feature, and has not been integrated into the Inno Setup script. I hope that these codes can be used as an inspiration, and the VS Code developers would find out a sensible way to achieve this feature.

Screenshot 2021-12-22 230721

Screenshot 2021-12-22 230859

The added codes are located at /build/win32/shell-extension-win11, including an action handler, a minimal sparse package manifest, build script and setup script.

Because these are not integrated into Inno Setup, a manual build process is needed:

Assume that VS2019 with desktop development workload is installed in the working environment. build.cmd can make the sparse package and .dll library file for handling menu actions, which are needed by Windows. It also self-issues a test certificate to sign the sparse package. (This maybe needs to be implemented in a more formal way.)

By executing build.cmd 3 files will be put in the /build/...-win11/Release directory, namely menuhandler.dll, Key.cer and code-sparse.appx. The certificate issuance and signature process will prompt to enter a password for 3 times, just enter the same password.

Copy these 3 files with setup.ps1 to anywhere inside an VS Code installation, and execute setup.ps1 with administrator privileges. After restarting explorer.exe, you can see the option of "Open by Code" in context menus of files and directories.

The menu action is handled by C++ code implementing the COM interface, while currently for older versions of Windows this is achieved by the installer to directly write into registry. So the COM implemention directly reads the keys from registry to present the icon and determine the executable file path, to keep it simple and stupid. Perhaps this approach needs further improvement.

Localization has not been implemented yet, but by reading the registry, it should be easy.

@ghost
Copy link

ghost commented Dec 22, 2021

CLA assistant check
All CLA requirements met.

@joaomoreno joaomoreno added this to the Backlog milestone Jan 3, 2022
@joaomoreno joaomoreno added install-update VS Code installation and upgrade system issues windows VS Code on Windows issues labels Jan 3, 2022
@JustinGrote
Copy link
Contributor

@joaomoreno can you approve the CI workflow please?

@joaomoreno
Copy link
Member

@sbatten @deepak1556 I wonder if all of this is really necessary.

@JustinGrote
Copy link
Contributor

@joaomoreno seeing as noone else has stepped up to add the functionality, so windows 11 users have lost the ability to right click "open with code" without dropping to the classic menu, then yes, it is.

@rgwood
Copy link

rgwood commented Jan 18, 2022

@joaomoreno Unfortunately sparse packages really are "insanely complicated".

It might help to get someone from the Windows team (@andrewleader, @AdamBraden?) to review the PR and confirm the best way to implement this.

@isidorn
Copy link
Contributor

isidorn commented Jan 19, 2022

@strear thank you for this PR.

While we acknowledge that this fixes the issue it would introduce a dependency on native code which we would like to avoid. The Windows team has confirmed to us that native code is required here and that adding "Open with Code" is no longer supported using the registry keys.

Though we are exploring alternative approaches to this which could potentially reduce the complexity. We will have more details in the next couple of weeks. I will keep you posted here. Thank you!

@asklar
Copy link
Member

asklar commented Mar 17, 2022

any updates @isidorn ?

@DanRotaru
Copy link

This PR fixes #127365

The added code follows the IExplorerCommand + app identity method recommended by Windows Blog, which is the minimal code necessary to implement this feature, and has not been integrated into the Inno Setup script. I hope that these codes can be used as an inspiration, and the VS Code developers would find out a sensible way to achieve this feature.

Screenshot 2021-12-22 230721

Screenshot 2021-12-22 230859

The added codes are located at /build/win32/shell-extension-win11, including an action handler, a minimal sparse package manifest, build script and setup script.

Because these are not integrated into Inno Setup, a manual build process is needed:

Assume that VS2019 with desktop development workload is installed in the working environment. build.cmd can make the sparse package and .dll library file for handling menu actions, which are needed by Windows. It also self-issues a test certificate to sign the sparse package. (This maybe needs to be implemented in a more formal way.)

By executing build.cmd 3 files will be put in the /build/...-win11/Release directory, namely menuhandler.dll, Key.cer and code-sparse.appx. The certificate issuance and signature process will prompt to enter a password for 3 times, just enter the same password.

Copy these 3 files with setup.ps1 to anywhere inside an VS Code installation, and execute setup.ps1 with administrator privileges. After restarting explorer.exe, you can see the option of "Open by Code" in context menus of files and directories.

The menu action is handled by C++ code implementing the COM interface, while currently for older versions of Windows this is achieved by the installer to directly write into registry. So the COM implemention directly reads the keys from registry to present the icon and determine the executable file path, to keep it simple and stupid. Perhaps this approach needs further improvement.

Localization has not been implemented yet, but by reading the registry, it should be easy.

Can you record short video?

@phuze
Copy link

phuze commented Apr 1, 2022

strear, thank you for the time and effort you put into finding this solution. Great work!

Here are a set of more detailed instructions. Hope this helps.

  1. Clone this PR.
  2. If you haven't already, install Visual Studio 2019. Community edition is fine.
  3. Install the Desktop development with C++ package. For existing installs, search for "Installer" in Windows, then open the Visual Studio Installer. From there, look for the the "Modify" button.
  4. In Windows, search for and launch: "x64 Native Tools Command Prompt for VS 2019" in administrator mode.
  5. Navigate to the directory noted by the author, replacing your own relative path:
>   cd <relative_path>\vscode\build\win32\shell-extension-win11
  1. Then run the build script:
>   .\build.cmd
  1. You'll be prompt to enter a password 3 times -- pick whatever you'd like, just be sure to use the same password in each prompt.
  2. If you get an error like this: fatal error LNK1112: module machine type 'x86' conflicts with target machine type 'x64', you're not using the 64-bit command line. Go back to Step 4.
  3. Review the output, make sure you see no errors.

In my case, I had to copy the entire Release folder (to my local VS Code install directory), not just the individual files the author noted. I also needed to install the self-signed certificate it generates, as a trusted root certificate in Windows, otherwise you'll see an error similar to this:

Add-AppxPackage: Deployment failed with HRESULT: 0x80073CF0, Package could not be opened.
error 0x800B0109: The root certificate of the signature in the app package or bundle must be trusted.

To do that, just double-click the Key.cer, hit the "Install Certificate..." button, choose "Local Machine", and manually choose the "Trusted Root Certification Authorities" folder.

  1. Once you've copied the necessary files into your local VS Code installation directory, open up Powershell in administrator mode, and execute setup.ps1. VS Code is typically installed to C:\Users\<user>\AppData\Local\Programs\Microsoft VS Code
>   cd "C:\Users\<user>\AppData\Local\Programs\Microsoft VS Code"
>   .\setup.ps1

As long as you're not seeing any errors in console, you're probably good -- restart Windows.

image

NOTE: You should probably disable VS Code auto-updating if you want to use this customization. You can disable auto-updating in the settings menu -- find and disable Enable Windows Background Updates. Otherwise, this customization prevents updates from working correctly. If you want to update VS Code, you'll have to manually uninstall, download the latest version, and then repeat the same process again. If you do end up repeating the process, I recommend deleting the old code-signing certificate. You can find it by searching for certificates in Windows, then opening Manage computer certificates. Look under the same Trusted Root Certification Authorities folder, for a certificate issued to localhost -- the Intended Purposes column will say Code Signing, Lifetime Signing, and it will probably have an expiration date of 2099-12-31. If you're not 110% confident you know what you're deleting, DONT do it -- just leave it be.

@agentmerlot1412
Copy link

Why is this not being merged, it seems to have passed all checks...

@11lein
Copy link

11lein commented Apr 17, 2022

Why is this not being merged, it seems to have passed all checks...

because:

@strear thank you for this PR.

While we acknowledge that this fixes the issue it would introduce a dependency on native code which we would like to avoid. The Windows team has confirmed to us that native code is required here and that adding "Open with Code" is no longer supported using the registry keys.

Though we are exploring alternative approaches to this which could potentially reduce the complexity. We will have more details in the next couple of weeks. I will keep you posted here. Thank you!

basically, that means: VSCode uses OS functionality and does/will not implement these with a lot of dependencies.

But you can implement the PR by yourself the way @phuze has it described or you have to wait for the win11 team.

@danielfmo
Copy link

danielfmo commented May 16, 2022

Though we are exploring alternative approaches to this which could potentially reduce the complexity. We will have more details in the next couple of weeks. I will keep you posted here. Thank you!

@isidorn Thank you for your time looking into this, as some time went by, were you able to find more information on the subject?

@deepak1556
Copy link
Collaborator

Sorry for the delayed response in this thread, highlights below.

Firstly, @strear thanks for your initial work on this issue, it was helpful with leading the explorations and discussions to search for alternates that does not involve a sparse package. On the good news, there is a hint for a less complicated solution that might come from the windows team but there is no concrete timeline.

This iteration I have spent some time adopting the sparse package solution accommodating our different release flavors and architectures. Sparse package creation is now delegated to https://github.com/microsoft/vscode-explorer-command since this rarely requires changes and it is unnecessary to be part of every vscode CI run. On the other hand, this repository will be responsible for signing the package and installing it as part of our custom installer. We will finish up the iteration with testing the feature E2E and if testing goes well, it will then be made available with insiders next iteration.

I am going to close this PR as part of the above effort, and will ensure it is captured by the release notes.

@deepak1556 deepak1556 closed this May 30, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jul 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
install-update VS Code installation and upgrade system issues windows VS Code on Windows issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate with the Windows 11 Context Menu