News

Tool Converts Visual Studio IDE Code Snippets for VS Code Editor

Developer Rick Strahl, tired of the cumbersome process of converting his many Visual Studio IDE code snippets into formats that can be used in the Visual Studio Code editor and the JetBrains Rider IDE, has created a tool to automate the process.

This week he announced the Visual Studio Snippet Converter, available as a .NET Global SDK Tool (console app) that can be installed with NuGet, with source code available on GitHub for anyone who might find the tool useful.

Strahl is a Web-centric developer living in Maui, Hawaii, where he runs West Wind Technologies, specializing in ASP.NET, C#, HTML5, JavaScript and AngularJs. Working primarily in Visual Studio, he has collected more than 130 code snippets over the years with the IDE's handy Code Snippets Manager (Tools > Code Snippets Manager).

"I have quite a few C# code snippets, but even more I use the HTML snippets for things like my Bootstrap customized snippets, snippets for complex HTML controls and the like," he said in a blog post Monday (Jan. 14). "There are few others for JavaScript, XAML and even some PowerShell ones."

Visual Studio Snippet Converter
[Click on image for larger view.] Visual Studio Snippet Converter (source: West Wind Technologies).

However, as he found himself increasingly using VS Code and JetBrains Rider in combination with Visual Studio IDE, he found the process of converting his precious snippets for use in those editors to be too time-consuming -- even if better than the alternative approach of looking up the code on a documentation site and tweaking it for his specific projects.

"In fact, I missed this stuff so much that sometimes I'd just fire up Visual Studio with an HTML editor open, just to expand HTML snippets I need, and then paste them back into VS Code or Rider," he said. "Tedious, but still faster than manually copying code from a Doc site and then manually customizing these longer blocks of text with the appropriate insertions added. It sure would be a lot nicer to do this directly in each respective environment."

And that's just what his tool -- built over a couple weekends -- does, though it works better for VS-to-VS Code conversions, with VS-to-JetBrains Rider providing limited functionality.

Although Strahl describes his project as "hacky," providing several caveats ("use at your own risk") and detailing specific workflow requirements to make conversions work properly, he concludes it works well enough for his needs.

"For Visual Studio Code exports all of my snippets actually export and work without issues," he said. "For Rider, my C# and HTML snippets export and that works as well, but other types (like JavaScript, CSS) will cause errors. I'm aware but I can live with that for a personal tool. If there's enough interest I can get those bits moved as well but it basically requires another completely separate converter."

A quick Web search reveals all kinds of resources for creating code snippets in all three of the above-mentioned IDEs, but nothing for a code snippet converter, so Strahl may be serving a unique niche.

Whether the project picks up steam and attracts more community involvement is an open question. "For now," Strahl said, "this is good enough for me, but I'm curious to see if I'm one of the few people who cares enough about Code Snippets to go through this exercise."

About the Author

David Ramel is an editor and writer for Converge360.

comments powered by Disqus

Featured

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

  • What's New for Python, Java in Visual Studio Code

    Microsoft announced March 2024 updates to its Python and Java extensions for Visual Studio Code, the open source-based, cross-platform code editor that has repeatedly been named the No. 1 tool in major development surveys.

Subscribe on YouTube