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

  • Hands On: New VS Code Insiders Build Creates Web Page from Image in Seconds

    New Vision support with GitHub Copilot in the latest Visual Studio Code Insiders build takes a user-supplied mockup image and creates a web page from it in seconds, handling all the HTML and CSS.

  • Naive Bayes Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the naive Bayes regression technique, where the goal is to predict a single numeric value. Compared to other machine learning regression techniques, naive Bayes regression is usually less accurate, but is simple, easy to implement and customize, works on both large and small datasets, is highly interpretable, and doesn't require tuning any hyperparameters.

  • VS Code Copilot Previews New GPT-4o AI Code Completion Model

    The 4o upgrade includes additional training on more than 275,000 high-quality public repositories in over 30 popular programming languages, said Microsoft-owned GitHub, which created the original "AI pair programmer" years ago.

  • Microsoft's Rust Embrace Continues with Azure SDK Beta

    "Rust's strong type system and ownership model help prevent common programming errors such as null pointer dereferencing and buffer overflows, leading to more secure and stable code."

  • Xcode IDE from Microsoft Archrival Apple Gets Copilot AI

    Just after expanding the reach of its Copilot AI coding assistant to the open-source Eclipse IDE, Microsoft showcased how it's going even further, providing details about a preview version for the Xcode IDE from archrival Apple.

Subscribe on YouTube

Upcoming Training Events