{"id":21853000,"url":"https://github.com/madskristensen/protocolhandlersample","last_synced_at":"2025-09-02T10:34:42.869Z","repository":{"id":66333501,"uuid":"123636843","full_name":"madskristensen/ProtocolHandlerSample","owner":"madskristensen","description":"A Visual Studio sample","archived":false,"fork":false,"pushed_at":"2018-04-10T19:45:06.000Z","size":41,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-17T08:44:08.234Z","etag":null,"topics":["protocol-handler","visual-studio","visual-studio-extension","vsix"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/madskristensen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"madskristensen"}},"created_at":"2018-03-02T22:19:17.000Z","updated_at":"2025-01-29T14:01:19.000Z","dependencies_parsed_at":"2023-02-20T19:46:03.669Z","dependency_job_id":null,"html_url":"https://github.com/madskristensen/ProtocolHandlerSample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/madskristensen/ProtocolHandlerSample","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madskristensen%2FProtocolHandlerSample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madskristensen%2FProtocolHandlerSample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madskristensen%2FProtocolHandlerSample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madskristensen%2FProtocolHandlerSample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/madskristensen","download_url":"https://codeload.github.com/madskristensen/ProtocolHandlerSample/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madskristensen%2FProtocolHandlerSample/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273271706,"owners_count":25075966,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-02T02:00:09.530Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["protocol-handler","visual-studio","visual-studio-extension","vsix"],"created_at":"2024-11-28T01:19:33.514Z","updated_at":"2025-09-02T10:34:42.812Z","avatar_url":"https://github.com/madskristensen.png","language":"C#","funding_links":["https://github.com/sponsors/madskristensen"],"categories":[],"sub_categories":[],"readme":"# Protocol handler sample\n\n[![Build status](https://ci.appveyor.com/api/projects/status/qq6vg6wi2ixshcr2?svg=true)](https://ci.appveyor.com/project/madskristensen/protocolhandlersample)\n\n**Applies to Visual Studio 2017.6 and newer**\n\nThis sample shows how to associate a URI protocol with Visual Studio and handle the passed in URI. For instance, a link with a custom protocol (*such as vsph://anything/I/want*) will open Visual Studio and pass the URI to the extension.\n\n## Specify minimum supported version\nSince protocol handler support is new in Visual Studio 2017 Update 6, we need to specify that our extension requires that version or newer. We do that in the .vsixmanifest file like so:\n\n```xml\n\u003cInstallationTarget Id=\"Microsoft.VisualStudio.Community\" Version=\"[15.0.27413, 16.0)\" /\u003e\n```\n\n*15.0.27413* is the full version string of Visual Studio 2017 Update 6.\n\nSee the full sample [.vsixmanifest file](src/source.extension.vsixmanifest).\n\n## Register the protocol\nThe first thing we should do is to specify the protocol in our extension to let the Visual Studio extension installer register it with Windows. We do that by adding a .json file to our extension and set its Build Action property to *ContentManifest*.\n\n![Property Grid](art/property-grid.png)\n\nThe content of the .json file should look like this. Replace any instance of *vsph* with your own protocol name.\n\n```json\n{\n  \"$schema\": \"http://json.schemastore.org/vsix-manifestinjection\",\n  \"urlAssociations\": [\n    {\n      \"protocol\": \"vsph\",\n      \"displayName\": \"Visual Studio Protocol Handler Sample\",\n      \"progId\": \"VisualStudio.vsph.[InstanceId]\",\n      \"defaultProgramRegistrationPath\": \"Software\\\\Microsoft\\\\VisualStudio_[InstanceId]\\\\Capabilities\"\n    }\n  ],\n  \"progIds\": [\n    {\n      \"id\": \"VisualStudio.vsph.[InstanceId]\",\n      \"displayName\": \"Visual Studio Protocol Handler Sample\",\n      \"path\": \"[InstallDir]\\\\Common7\\\\IDE\\\\devenv.exe\",\n      \"arguments\": \"/MySwitch\",\n      \"defaultIconPath\": \"[InstallDir]\\\\Common7\\\\IDE\\\\devenv.exe\"\n    }\n  ]\n}\n```\n\nNotice that the *#/progIds/arguments* property is set to **/MySwitch**. This means that Visual Studio will be started with a that command line argument and the URL will be added to that like so: `devenv.exe /MySwitch vsph://anything/I/want`\n\n\u003e Please note that for this to work, the extension must be a per-machine extension. Set this in the .vsixmanifest by specifying `\u003cInstallation AllUsers=\"true\"\u003e`.\n\n## Intercept the URI\nNow we need our package class to load automatically when Visual Studio was started by the protocol handler. We do that by adding an attribute to the Package/AsyncPackage class:\n\n```c#\n[ProvideAppCommandLine(\"MySwitch\", typeof(ProtocolPackage), Arguments = \"1\", DemandLoad = 1)]\npublic sealed class ProtocolPackage : AsyncPackage\n{\n    ...\n}\n```\n\nWith the `ProvideAppCommandLine` attribute in place, the package is automatically initialized when the `/MySwitch` command line argument was passed to `devenv.exe`.\n\nWe can then access the URI from the Package.InitializeAsync method:\n\n```c#\nprotected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress\u003cServiceProgressData\u003e progress)\n{\n    await JoinableTaskFactory.SwitchToMainThreadAsync();\n\n    var cmdline = await GetServiceAsync(typeof(SVsAppCommandLine)) as IVsAppCommandLine;\n\n    ErrorHandler.ThrowOnFailure(cmdline.GetOption(\"MySwitch\", out int isPresent, out string optionValue));\n\n    if (isPresent == 1)\n    {\n        // If opened from a URL, then \"optionValue\" is the URL string itself\n        System.Windows.Forms.MessageBox.Show(optionValue);\n    }\n}\n```\n\nSee the full sample [package class](src/ProtocolPackage.cs).\n\nAnd that's it. We now have an extension that can take action on custom protocol URIs. To test it out, [install this sample extension](http://vsixgallery.com/extension/88018116-8e87-4113-a1c0-db510a2aace0/) and then click [this link](https://tinyurl.com/vsph-sample).\n\n## Further reading\n\n- [Adding command line switches](https://docs.microsoft.com/en-us/visualstudio/extensibility/adding-command-line-switches)\n- [VS 2017 version numbers and release dates](https://docs.microsoft.com/en-us/visualstudio/install/visual-studio-build-numbers-and-release-dates)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmadskristensen%2Fprotocolhandlersample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmadskristensen%2Fprotocolhandlersample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmadskristensen%2Fprotocolhandlersample/lists"}