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 at Converge 360.

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube