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


Subscribe on YouTube