├── .editorconfig ├── .gitattributes ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── OpenInVsCode.sln ├── README.md ├── appveyor.yml ├── art ├── context-menu.png └── options.png └── src ├── Commands └── OpenVsCodeCommand.cs ├── Helpers ├── Logger.cs └── ProjectHelpers.cs ├── OpenInVsCode.csproj ├── Options.cs ├── Properties └── AssemblyInfo.cs ├── Resources └── Icon.png ├── VSCommands.cs ├── VSCommands.vsct ├── VSPackage.cs ├── source.extension.cs ├── source.extension.ico └── source.extension.vsixmanifest /.editorconfig: -------------------------------------------------------------------------------- 1 | # Top-most EditorConfig file 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | end_of_line = crlf 7 | indent_size = 4 8 | 9 | [*.json] 10 | indent_style = space 11 | indent_size = 2 -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | packages 2 | node_modules.7z 3 | template-report.xml 4 | 5 | # User files 6 | *.suo 7 | *.user 8 | *.sln.docstates 9 | .vs/ 10 | 11 | # Build results 12 | 13 | [Dd]ebug/ 14 | [Rr]elease/ 15 | x64/ 16 | [Bb]in/ 17 | [Oo]bj/ 18 | 19 | # MSTest test Results 20 | [Tt]est[Rr]esult*/ 21 | [Bb]uild[Ll]og.* 22 | 23 | # NCrunch 24 | *.ncrunchsolution 25 | *.ncrunchproject 26 | _NCrunch_WebCompiler -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Looking to contribute something? **Here's how you can help.** 4 | 5 | Please take a moment to review this document in order to make the contribution 6 | process easy and effective for everyone involved. 7 | 8 | Following these guidelines helps to communicate that you respect the time of 9 | the developers managing and developing this open source project. In return, 10 | they should reciprocate that respect in addressing your issue or assessing 11 | patches and features. 12 | 13 | 14 | ## Using the issue tracker 15 | 16 | The issue tracker is the preferred channel for [bug reports](#bug-reports), 17 | [features requests](#feature-requests) and 18 | [submitting pull requests](#pull-requests), but please respect the 19 | following restrictions: 20 | 21 | * Please **do not** use the issue tracker for personal support requests. Stack 22 | Overflow is a better place to get help. 23 | 24 | * Please **do not** derail or troll issues. Keep the discussion on topic and 25 | respect the opinions of others. 26 | 27 | * Please **do not** open issues or pull requests which *belongs to* third party 28 | components. 29 | 30 | 31 | ## Bug reports 32 | 33 | A bug is a _demonstrable problem_ that is caused by the code in the repository. 34 | Good bug reports are extremely helpful, so thanks! 35 | 36 | Guidelines for bug reports: 37 | 38 | 1. **Use the GitHub issue search** — check if the issue has already been 39 | reported. 40 | 41 | 2. **Check if the issue has been fixed** — try to reproduce it using the 42 | latest `master` or development branch in the repository. 43 | 44 | 3. **Isolate the problem** — ideally create an 45 | [SSCCE](http://www.sscce.org/) and a live example. 46 | Uploading the project on cloud storage (OneDrive, DropBox, et el.) 47 | or creating a sample GitHub repository is also helpful. 48 | 49 | 50 | A good bug report shouldn't leave others needing to chase you up for more 51 | information. Please try to be as detailed as possible in your report. What is 52 | your environment? What steps will reproduce the issue? What browser(s) and OS 53 | experience the problem? Do other browsers show the bug differently? What 54 | would you expect to be the outcome? All these details will help people to fix 55 | any potential bugs. 56 | 57 | Example: 58 | 59 | > Short and descriptive example bug report title 60 | > 61 | > A summary of the issue and the Visual Studio, browser, OS environments 62 | > in which it occurs. If suitable, include the steps required to reproduce the bug. 63 | > 64 | > 1. This is the first step 65 | > 2. This is the second step 66 | > 3. Further steps, etc. 67 | > 68 | > `` - a link to the project/file uploaded on cloud storage or other publicly accessible medium. 69 | > 70 | > Any other information you want to share that is relevant to the issue being 71 | > reported. This might include the lines of code that you have identified as 72 | > causing the bug, and potential solutions (and your opinions on their 73 | > merits). 74 | 75 | 76 | ## Feature requests 77 | 78 | Feature requests are welcome. But take a moment to find out whether your idea 79 | fits with the scope and aims of the project. It's up to *you* to make a strong 80 | case to convince the project's developers of the merits of this feature. Please 81 | provide as much detail and context as possible. 82 | 83 | 84 | ## Pull requests 85 | 86 | Good pull requests, patches, improvements and new features are a fantastic 87 | help. They should remain focused in scope and avoid containing unrelated 88 | commits. 89 | 90 | **Please ask first** before embarking on any significant pull request (e.g. 91 | implementing features, refactoring code, porting to a different language), 92 | otherwise you risk spending a lot of time working on something that the 93 | project's developers might not want to merge into the project. 94 | 95 | Please adhere to the [coding guidelines](#code-guidelines) used throughout the 96 | project (indentation, accurate comments, etc.) and any other requirements 97 | (such as test coverage). 98 | 99 | Adhering to the following process is the best way to get your work 100 | included in the project: 101 | 102 | 1. [Fork](http://help.github.com/fork-a-repo/) the project, clone your fork, 103 | and configure the remotes: 104 | 105 | ```bash 106 | # Clone your fork of the repo into the current directory 107 | git clone https://github.com//.git 108 | # Navigate to the newly cloned directory 109 | cd 110 | # Assign the original repo to a remote called "upstream" 111 | git remote add upstream https://github.com/madskristensen/.git 112 | ``` 113 | 114 | 2. If you cloned a while ago, get the latest changes from upstream: 115 | 116 | ```bash 117 | git checkout master 118 | git pull upstream master 119 | ``` 120 | 121 | 3. Create a new topic branch (off the main project development branch) to 122 | contain your feature, change, or fix: 123 | 124 | ```bash 125 | git checkout -b 126 | ``` 127 | 128 | 4. Commit your changes in logical chunks. Please adhere to these [git commit 129 | message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) 130 | or your code is unlikely be merged into the main project. Use Git's 131 | [interactive rebase](https://help.github.com/articles/interactive-rebase) 132 | feature to tidy up your commits before making them public. Also, prepend name of the feature 133 | to the commit message. For instance: "SCSS: Fixes compiler results for IFileListener.\nFixes `#123`" 134 | 135 | 5. Locally merge (or rebase) the upstream development branch into your topic branch: 136 | 137 | ```bash 138 | git pull [--rebase] upstream master 139 | ``` 140 | 141 | 6. Push your topic branch up to your fork: 142 | 143 | ```bash 144 | git push origin 145 | ``` 146 | 147 | 7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/) 148 | with a clear title and description against the `master` branch. 149 | 150 | 151 | ## Code guidelines 152 | 153 | - Always use proper indentation. 154 | - In Visual Studio under `Tools > Options > Text Editor > C# > Advanced`, make sure 155 | `Place 'System' directives first when sorting usings` option is enabled (checked). 156 | - Before committing, organize usings for each updated C# source file. Either you can 157 | right-click editor and select `Organize Usings > Remove and sort` OR use extension 158 | like [BatchFormat](https://marketplace.visualstudio.com/items?itemName=vs-publisher-147549.BatchFormat). 159 | - Before committing, run Code Analysis in `Debug` configuration and follow the guidelines 160 | to fix CA issues. Code Analysis commits can be made separately. 161 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2015 Mads Kristensen 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /OpenInVsCode.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26815.3 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenInVsCode", "src\OpenInVsCode.csproj", "{4B9DC4DD-B2D2-41E3-B33E-804F6F712049}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E8040FFF-3992-4875-93BE-720F36F5B5B4}" 9 | ProjectSection(SolutionItems) = preProject 10 | appveyor.yml = appveyor.yml 11 | README.md = README.md 12 | EndProjectSection 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {4B9DC4DD-B2D2-41E3-B33E-804F6F712049}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {4B9DC4DD-B2D2-41E3-B33E-804F6F712049}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {4B9DC4DD-B2D2-41E3-B33E-804F6F712049}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {4B9DC4DD-B2D2-41E3-B33E-804F6F712049}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {34AC03DE-ABC1-42E6-A117-23A41826EBF9} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Open in Visual Studio Code 2 | A Visual Studio extension that adds a menu command that 3 | lets you open any solution, project, folder or file in 4 | Visual Studio Code. 5 | 6 | [![Build status](https://ci.appveyor.com/api/projects/status/hdd4uqjdqpq0f6lf?svg=true)](https://ci.appveyor.com/project/madskristensen/openinvscode) 7 | 8 | Download the extension at the 9 | [VS Gallery](https://marketplace.visualstudio.com/items?itemName=MadsKristensen.OpeninVisualStudioCode) 10 | or get the 11 | [nightly build](http://vsixgallery.com/extension/e99dde0e-e023-410d-bc5d-3f76db71e3f0/) 12 | 13 | ------------------------------------ 14 | 15 | This extension is for those times where you have a project 16 | open in Visual Studio and you want to be able to quickly 17 | open it in Visual Studio Code. 18 | 19 | ## Prerequisite 20 | In order to use this extension, you must have Visual 21 | Studio 2015/2017/2019 as well as Visual Studio Code installed. 22 | 23 | You can 24 | [download Visual Studio Code](https://code.visualstudio.com/) 25 | for free. 26 | 27 | ## Solution Explorer 28 | You can open any solution, project, folder or file in 29 | Visual Studio Code by simply right-clicking it in Solution 30 | Explorer and select 31 | **Open in Visual Studio Code**. 32 | 33 | ![Context menu](art/context-menu.png) 34 | 35 | ## Open current file 36 | You can also open the current file in Visual Studio Code 37 | by clicking onto **Extensions->Open in Visual Studio Code**. 38 | 39 | ![grafik](https://user-images.githubusercontent.com/11379989/207499990-873f7d4a-4ca5-47b6-9264-7d39b33937b3.png) 40 | 41 | The default key binding is `Ctrl+Shift+Y`. 42 | 43 | 44 | ## Path to Code.exe 45 | If you installed Visual Studio Code at a non-default location, 46 | a prompt will ask for the path to _Code.exe_. 47 | 48 | You can always change the location in 49 | **Tools -> Options -> Web -> Open In Visual Studio Code**. 50 | 51 | ![Options](art/options.png) 52 | 53 | ## License 54 | [Apache 2.0](LICENSE) 55 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | os: Visual Studio 2019 2 | 3 | install: 4 | - ps: (new-object Net.WebClient).DownloadString("https://raw.github.com/madskristensen/ExtensionScripts/master/AppVeyor/vsix.ps1") | iex 5 | 6 | before_build: 7 | - ps: Vsix-IncrementVsixVersion | Vsix-UpdateBuildVersion 8 | - ps: Vsix-TokenReplacement src\source.extension.cs 'Version = "([0-9\\.]+)"' 'Version = "{version}"' 9 | 10 | build_script: 11 | - nuget restore -Verbosity quiet 12 | - msbuild /p:configuration=Release /p:DeployExtension=false /p:ZipPackageCompressionLevel=normal /v:m 13 | 14 | after_test: 15 | - ps: Vsix-PushArtifacts | Vsix-PublishToGallery -------------------------------------------------------------------------------- /art/context-menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madskristensen/OpenInVsCode/50b63229c6a89ffdbb79f4ba8e2ae5df6d06cfec/art/context-menu.png -------------------------------------------------------------------------------- /art/options.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madskristensen/OpenInVsCode/50b63229c6a89ffdbb79f4ba8e2ae5df6d06cfec/art/options.png -------------------------------------------------------------------------------- /src/Commands/OpenVsCodeCommand.cs: -------------------------------------------------------------------------------- 1 | using EnvDTE; 2 | using EnvDTE80; 3 | using Microsoft.VisualStudio.Shell; 4 | using System; 5 | using System.ComponentModel.Design; 6 | using System.IO; 7 | using System.Windows.Forms; 8 | using Microsoft.Win32; 9 | using Microsoft; 10 | 11 | namespace OpenInVsCode 12 | { 13 | internal sealed class OpenVsCodeCommand 14 | { 15 | private readonly Package _package; 16 | private readonly Options _options; 17 | 18 | private OpenVsCodeCommand(Package package, Options options) 19 | { 20 | _package = package; 21 | _options = options; 22 | 23 | var commandService = (OleMenuCommandService)ServiceProvider.GetService(typeof(IMenuCommandService)); 24 | 25 | if (commandService != null) 26 | { 27 | var menuCommandID = new CommandID(PackageGuids.guidOpenInVsCmdSet, PackageIds.OpenInVs); 28 | var menuItem = new MenuCommand(OpenFolderInVs, menuCommandID); 29 | commandService.AddCommand(menuItem); 30 | 31 | var currentCommandID = new CommandID(PackageGuids.guidOpenCurrentInVsCmdSet, PackageIds.OpenCurrentInVs); 32 | var currentItem = new MenuCommand(OpenCurrentFileInVs, currentCommandID); 33 | commandService.AddCommand(currentItem); 34 | } 35 | } 36 | 37 | public static OpenVsCodeCommand Instance { get; private set; } 38 | 39 | private IServiceProvider ServiceProvider 40 | { 41 | get { return _package; } 42 | } 43 | 44 | public static void Initialize(Package package, Options options) 45 | { 46 | Instance = new OpenVsCodeCommand(package, options); 47 | } 48 | 49 | private void OpenCurrentFileInVs(object sender, EventArgs e) 50 | { 51 | try 52 | { 53 | var dte = (DTE2) ServiceProvider.GetService(typeof(DTE)); 54 | Assumes.Present(dte); 55 | 56 | var activeDocument = dte.ActiveDocument; 57 | 58 | if (activeDocument != null) 59 | { 60 | var path = activeDocument.FullName; 61 | 62 | if (!string.IsNullOrEmpty(path)) 63 | { 64 | int line = 0; 65 | int column = 0; 66 | 67 | if (activeDocument.Selection is TextSelection selection) 68 | { 69 | line = selection.ActivePoint.Line; 70 | // note: 71 | // LineCharOffset not DisplayColumn 72 | // as it described `code -h`: -g --goto 73 | column = selection.ActivePoint.LineCharOffset; 74 | } 75 | 76 | OpenVsCode(path, line, column); 77 | } 78 | else 79 | { 80 | MessageBox.Show("Couldn't resolve the folder"); 81 | } 82 | } 83 | else 84 | { 85 | MessageBox.Show("Couldn't find active document"); 86 | } 87 | } 88 | catch (Exception ex) 89 | { 90 | Logger.Log(ex); 91 | } 92 | } 93 | 94 | private void OpenFolderInVs(object sender, EventArgs e) 95 | { 96 | try 97 | { 98 | var dte = (DTE2)ServiceProvider.GetService(typeof(DTE)); 99 | Assumes.Present(dte); 100 | 101 | string path = ProjectHelpers.GetSelectedPath(dte, _options.OpenSolutionProjectAsRegularFile); 102 | 103 | if (!string.IsNullOrEmpty(path)) 104 | { 105 | int line = 0; 106 | int column = 0; 107 | 108 | if (dte.ActiveDocument?.Selection is TextSelection selection) 109 | { 110 | line = selection.ActivePoint.Line; 111 | column = selection.ActivePoint.LineCharOffset; 112 | } 113 | 114 | OpenVsCode(path, line, column); 115 | } 116 | else 117 | { 118 | MessageBox.Show("Couldn't resolve the folder"); 119 | } 120 | } 121 | catch (Exception ex) 122 | { 123 | Logger.Log(ex); 124 | } 125 | } 126 | 127 | private void OpenVsCode(string path, int line = 0, int column = 0) 128 | { 129 | EnsurePathExist(); 130 | bool isDirectory = Directory.Exists(path); 131 | 132 | var args = isDirectory 133 | ? "." 134 | : line > 0 135 | ? column > 0 136 | ? $"-g \"{path}:{line}:{column}\"" 137 | : $"-g \"{path}:{line}\"" 138 | : $"\"{path}\""; 139 | if (!string.IsNullOrEmpty(_options.CommandLineArguments)) 140 | { 141 | args = $"{args} {_options.CommandLineArguments}"; 142 | } 143 | 144 | var start = new System.Diagnostics.ProcessStartInfo() 145 | { 146 | FileName = $"\"{_options.PathToExe}\"", 147 | Arguments = args, 148 | CreateNoWindow = true, 149 | UseShellExecute = false, 150 | WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden, 151 | }; 152 | 153 | if (isDirectory) 154 | { 155 | start.WorkingDirectory = path; 156 | } 157 | 158 | using (System.Diagnostics.Process.Start(start)) 159 | { 160 | 161 | } 162 | } 163 | 164 | private void EnsurePathExist() 165 | { 166 | if (File.Exists(_options.PathToExe)) 167 | return; 168 | 169 | if (!string.IsNullOrEmpty(VsCodeDetect.InRegistry())) 170 | { 171 | SaveOptions(_options, VsCodeDetect.InRegistry()); 172 | } 173 | else if (!string.IsNullOrEmpty(VsCodeDetect.InEnvVarPath())) 174 | { 175 | SaveOptions(_options, VsCodeDetect.InEnvVarPath()); 176 | } 177 | else if (!string.IsNullOrEmpty(VsCodeDetect.InLocalAppData())) 178 | { 179 | SaveOptions(_options, VsCodeDetect.InLocalAppData()); 180 | } 181 | else 182 | { 183 | var box = MessageBox.Show( 184 | "I can't find Visual Studio Code (Code.exe). Would you like to help me find it?", Vsix.Name, 185 | MessageBoxButtons.YesNo, MessageBoxIcon.Question); 186 | 187 | if (box == DialogResult.No) 188 | return; 189 | 190 | var dialog = new OpenFileDialog 191 | { 192 | DefaultExt = ".exe", 193 | FileName = "Code.exe", 194 | InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), 195 | CheckFileExists = true 196 | }; 197 | 198 | var result = dialog.ShowDialog(); 199 | 200 | if (result == DialogResult.OK) 201 | { 202 | SaveOptions(_options, dialog.FileName); 203 | } 204 | } 205 | } 206 | 207 | private void SaveOptions(Options options, string path) 208 | { 209 | options.PathToExe = path; 210 | options.SaveSettingsToStorage(); 211 | } 212 | 213 | } 214 | 215 | internal static class VsCodeDetect 216 | { 217 | internal static string InRegistry() 218 | { 219 | var key = Registry.CurrentUser; 220 | var name = "Icon"; 221 | try 222 | { 223 | var subKey = key.OpenSubKey(@"SOFTWARE\Classes\*\shell\VSCode\"); 224 | var value = subKey.GetValue(name).ToString(); 225 | if (File.Exists(value)) 226 | { 227 | return value; 228 | } 229 | 230 | return null; 231 | } 232 | catch 233 | { 234 | return null; 235 | } 236 | } 237 | 238 | internal static string InLocalAppData() 239 | { 240 | var localAppData = Environment.GetEnvironmentVariable("LOCALAPPDATA"); 241 | 242 | var codePartDir = @"Programs\Microsoft VS Code"; 243 | var codeDir = Path.Combine(localAppData, codePartDir); 244 | var drives = DriveInfo.GetDrives(); 245 | 246 | foreach (var drive in drives) 247 | { 248 | if (drive.DriveType == DriveType.Fixed) 249 | { 250 | var path = Path.Combine(drive.Name[0] + codeDir.Substring(1), "code.exe"); 251 | if (File.Exists(path)) 252 | { 253 | return path; 254 | } 255 | } 256 | } 257 | 258 | return null; 259 | } 260 | 261 | internal static string InEnvVarPath() 262 | { 263 | var envPath = Environment.GetEnvironmentVariable("Path"); 264 | var paths = envPath.Split(';'); 265 | var parentDir = "Microsoft VS Code"; 266 | foreach (var path in paths) 267 | { 268 | if (path.ToLower().Contains("code")) 269 | { 270 | var temp = Path.Combine(path.Substring(0, path.IndexOf(parentDir, StringComparison.InvariantCultureIgnoreCase)), 271 | parentDir, "code.exe"); 272 | if (File.Exists(temp)) 273 | { 274 | return temp; 275 | } 276 | } 277 | } 278 | return null; 279 | } 280 | } 281 | } 282 | -------------------------------------------------------------------------------- /src/Helpers/Logger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics.CodeAnalysis; 3 | 4 | using Microsoft; 5 | using Microsoft.VisualStudio.Shell; 6 | using Microsoft.VisualStudio.Shell.Interop; 7 | 8 | public static class Logger 9 | { 10 | private static IVsOutputWindowPane pane; 11 | private static IServiceProvider _provider; 12 | private static string _name; 13 | 14 | public static void Initialize(Package provider, string name) 15 | { 16 | _provider = provider; 17 | _name = name; 18 | } 19 | 20 | public static void Log(string message) 21 | { 22 | if (string.IsNullOrEmpty(message)) 23 | return; 24 | 25 | try 26 | { 27 | if (EnsurePane()) 28 | { 29 | pane.OutputString(DateTime.Now.ToString() + ": " + message + Environment.NewLine); 30 | } 31 | } 32 | catch (Exception ex) 33 | { 34 | System.Diagnostics.Debug.WriteLine(ex); 35 | } 36 | } 37 | 38 | public static void Log(Exception ex) 39 | { 40 | if (ex != null) 41 | { 42 | Log(ex.ToString()); 43 | } 44 | } 45 | 46 | private static bool EnsurePane() 47 | { 48 | if (pane == null) 49 | { 50 | Guid guid = Guid.NewGuid(); 51 | IVsOutputWindow output = (IVsOutputWindow)_provider.GetService(typeof(SVsOutputWindow)); 52 | Assumes.Present(output); 53 | 54 | output.CreatePane(ref guid, _name, 1, 1); 55 | output.GetPane(ref guid, out pane); 56 | } 57 | 58 | return pane != null; 59 | } 60 | } -------------------------------------------------------------------------------- /src/Helpers/ProjectHelpers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Windows.Forms; 5 | using EnvDTE; 6 | using EnvDTE80; 7 | 8 | namespace OpenInVsCode 9 | { 10 | internal static class ProjectHelpers 11 | { 12 | public static string GetSelectedPath(DTE2 dte, bool openSolutionProjectAsRegularFile) 13 | { 14 | var items = (Array)dte.ToolWindows.SolutionExplorer.SelectedItems; 15 | var files = new List(); 16 | 17 | foreach (UIHierarchyItem selItem in items) 18 | { 19 | ProjectItem item = selItem.Object as ProjectItem; 20 | 21 | if (item != null) 22 | files.Add(item.GetFilePath()); 23 | 24 | Project proj = selItem.Object as Project; 25 | 26 | if (proj != null) 27 | return openSolutionProjectAsRegularFile ? $"\"{proj.FileName}\"" : proj.GetRootFolder(); 28 | 29 | Solution sol = selItem.Object as Solution; 30 | 31 | if (sol != null) 32 | return openSolutionProjectAsRegularFile ? $"\"{sol.FullName}\"" : Path.GetDirectoryName(sol.FileName); 33 | } 34 | 35 | return files.Count > 0 ? String.Join(" ", files) : null; 36 | } 37 | 38 | public static string GetFilePath(this ProjectItem item) 39 | { 40 | return $"\"{item.FileNames[1]}\""; // Indexing starts from 1 41 | } 42 | 43 | public static string GetRootFolder(this Project project) 44 | { 45 | if (string.IsNullOrEmpty(project.FullName)) 46 | return null; 47 | 48 | string fullPath; 49 | 50 | try 51 | { 52 | fullPath = project.Properties.Item("FullPath").Value as string; 53 | } 54 | catch (ArgumentException) 55 | { 56 | try 57 | { 58 | // MFC projects don't have FullPath, and there seems to be no way to query existence 59 | fullPath = project.Properties.Item("ProjectDirectory").Value as string; 60 | } 61 | catch (ArgumentException) 62 | { 63 | // Installer projects have a ProjectPath. 64 | fullPath = project.Properties.Item("ProjectPath").Value as string; 65 | } 66 | } 67 | 68 | if (string.IsNullOrEmpty(fullPath)) 69 | return File.Exists(project.FullName) ? Path.GetDirectoryName(project.FullName) : null; 70 | 71 | if (Directory.Exists(fullPath)) 72 | return fullPath; 73 | 74 | if (File.Exists(fullPath)) 75 | return Path.GetDirectoryName(fullPath); 76 | 77 | return null; 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/OpenInVsCode.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(VisualStudioVersion) 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | true 7 | Program 8 | $(DevEnvDir)\devenv.exe 9 | /rootsuffix Exp 10 | publish\ 11 | true 12 | Disk 13 | false 14 | Foreground 15 | 7 16 | Days 17 | false 18 | false 19 | true 20 | 0 21 | 1.0.0.%2a 22 | false 23 | false 24 | true 25 | 26 | 27 | 28 | 29 | 30 | 31 | Debug 32 | AnyCPU 33 | 2.0 34 | {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 35 | {4B9DC4DD-B2D2-41E3-B33E-804F6F712049} 36 | Library 37 | Properties 38 | OpenInVsCode 39 | OpenInVsCode 40 | v4.6 41 | true 42 | true 43 | true 44 | true 45 | false 46 | 47 | 48 | true 49 | full 50 | false 51 | bin\Debug\ 52 | DEBUG;TRACE 53 | prompt 54 | 4 55 | 56 | 57 | pdbonly 58 | true 59 | bin\Release\ 60 | TRACE 61 | prompt 62 | 4 63 | 64 | 65 | 66 | 67 | 68 | 69 | Component 70 | 71 | 72 | True 73 | True 74 | source.extension.vsixmanifest 75 | 76 | 77 | True 78 | True 79 | VSCommands.vsct 80 | 81 | 82 | 83 | 84 | 85 | 86 | Resources\LICENSE 87 | true 88 | 89 | 90 | Designer 91 | VsixManifestGenerator 92 | source.extension.cs 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | Menus.ctmenu 104 | VsctGenerator 105 | VSCommands.cs 106 | Designer 107 | 108 | 109 | 110 | 111 | true 112 | Always 113 | 114 | 115 | 116 | 117 | False 118 | Microsoft .NET Framework 4.5.1 %28x86 and x64%29 119 | true 120 | 121 | 122 | False 123 | .NET Framework 3.5 SP1 124 | false 125 | 126 | 127 | 128 | 129 | 130 | 17.0.1619-preview1 131 | runtime; build; native; contentfiles; analyzers; buildtransitive 132 | all 133 | 134 | 135 | 136 | 137 | 144 | -------------------------------------------------------------------------------- /src/Options.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.Shell; 2 | using System; 3 | using System.ComponentModel; 4 | using System.IO; 5 | using System.Windows.Forms; 6 | 7 | namespace OpenInVsCode 8 | { 9 | public class Options : DialogPage 10 | { 11 | [Category("General")] 12 | [DisplayName("Command line arguments")] 13 | [Description("Command line arguments to pass to code.exe")] 14 | public string CommandLineArguments { get; set; } 15 | 16 | [Category("General")] 17 | [DisplayName("Path to code.exe")] 18 | [Description("Specify the path to code.exe.")] 19 | public string PathToExe { get; set; } = Environment.ExpandEnvironmentVariables(@"%localappdata%\Programs\Microsoft VS Code\Code.exe"); 20 | 21 | [Category("General")] 22 | [DisplayName("Open solution/project as regular file")] 23 | [Description("When true, opens solutions/projects as regular files and does not load folder path into VS Code.")] 24 | public bool OpenSolutionProjectAsRegularFile { get; set; } 25 | 26 | protected override void OnApply(PageApplyEventArgs e) 27 | { 28 | if (!File.Exists(PathToExe)) 29 | { 30 | e.ApplyBehavior = ApplyKind.Cancel; 31 | MessageBox.Show($"The file \"{PathToExe}\" doesn't exist.", Vsix.Name, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); 32 | } 33 | 34 | base.OnApply(e); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | using OpenInVsCode; 4 | 5 | [assembly: AssemblyTitle(Vsix.Name)] 6 | [assembly: AssemblyDescription(Vsix.Description)] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: AssemblyCompany(Vsix.Author)] 9 | [assembly: AssemblyProduct(Vsix.Name)] 10 | [assembly: AssemblyCopyright("")] 11 | [assembly: AssemblyTrademark("")] 12 | [assembly: AssemblyCulture("")] 13 | [assembly: ComVisible(false)] 14 | 15 | [assembly: AssemblyVersion(Vsix.Version)] 16 | [assembly: AssemblyFileVersion(Vsix.Version)] 17 | -------------------------------------------------------------------------------- /src/Resources/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madskristensen/OpenInVsCode/50b63229c6a89ffdbb79f4ba8e2ae5df6d06cfec/src/Resources/Icon.png -------------------------------------------------------------------------------- /src/VSCommands.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This file was generated by VSIX Synchronizer 4 | // 5 | // ------------------------------------------------------------------------------ 6 | namespace OpenInVsCode 7 | { 8 | using System; 9 | 10 | /// 11 | /// Helper class that exposes all GUIDs used across VS Package. 12 | /// 13 | internal sealed partial class PackageGuids 14 | { 15 | public const string guidPackageString = "0a3cf9fa-2fe6-42dc-97df-a0f224cf5854"; 16 | public static Guid guidPackage = new Guid(guidPackageString); 17 | 18 | public const string guidOpenInVsCmdSetString = "cad3eff2-bd57-4dd4-9104-7b032daeba54"; 19 | public static Guid guidOpenInVsCmdSet = new Guid(guidOpenInVsCmdSetString); 20 | 21 | public const string guidOpenCurrentInVsCmdSetString = "869c35cb-008b-4863-9e28-4c3123b073a7"; 22 | public static Guid guidOpenCurrentInVsCmdSet = new Guid(guidOpenCurrentInVsCmdSetString); 23 | } 24 | /// 25 | /// Helper class that encapsulates all CommandIDs uses across VS Package. 26 | /// 27 | internal sealed partial class PackageIds 28 | { 29 | public const int OpenInVs = 0x0100; 30 | public const int OpenCurrentInVs = 0x0101; 31 | } 32 | } -------------------------------------------------------------------------------- /src/VSCommands.vsct: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 18 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/VSPackage.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.Shell; 2 | using System; 3 | using System.Runtime.InteropServices; 4 | using System.Threading; 5 | 6 | namespace OpenInVsCode 7 | { 8 | [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)] 9 | [InstalledProductRegistration("#110", "#112", Vsix.Version, IconResourceID = 400)] 10 | [ProvideMenuResource("Menus.ctmenu", 1)] 11 | [ProvideOptionPage(typeof(Options), "Web", Vsix.Name, 101, 102, true, new string[0], ProvidesLocalizedCategoryName = false)] 12 | [Guid(PackageGuids.guidPackageString)] 13 | public sealed class VSPackage : AsyncPackage 14 | { 15 | protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress progress) 16 | { 17 | await JoinableTaskFactory.SwitchToMainThreadAsync(); 18 | 19 | var options = (Options)GetDialogPage(typeof(Options)); 20 | 21 | Logger.Initialize(this, Vsix.Name); 22 | OpenVsCodeCommand.Initialize(this, options); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/source.extension.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This file was generated by VSIX Synchronizer 4 | // 5 | // ------------------------------------------------------------------------------ 6 | namespace OpenInVsCode 7 | { 8 | internal sealed partial class Vsix 9 | { 10 | public const string Id = "e99dde0e-e023-410d-bc5d-3f76db71e3f0"; 11 | public const string Name = "Open in Visual Studio Code"; 12 | public const string Description = @"Adds a menu command that lets you open any solution, project, folder and file in Visual Studio Code."; 13 | public const string Language = "en-US"; 14 | public const string Version = "1.4"; 15 | public const string Author = "Mads Kristensen"; 16 | public const string Tags = "vscode, code"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/source.extension.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madskristensen/OpenInVsCode/50b63229c6a89ffdbb79f4ba8e2ae5df6d06cfec/src/source.extension.ico -------------------------------------------------------------------------------- /src/source.extension.vsixmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Open in Visual Studio Code 6 | Adds a menu command that lets you open any solution, project, folder and file in Visual Studio Code. 7 | https://github.com/madskristensen/OpenInVsCode/ 8 | Resources\LICENSE 9 | Resources\Icon.png 10 | Resources\Icon.png 11 | vscode, code 12 | 13 | 14 | 15 | 16 | amd64 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | --------------------------------------------------------------------------------