This is a small project to convert Visual Studio's Code Snippets (XML .snippet files) to:
- VS Code Code Snippets
- Rider Live Templates (experimental)
This tool is available as a .NET Global Tool that is easily installable as a command line utility using the .NET Core SDK 2.1 or later.
This tool can take individual Visual Studio snippets, a folder full of .snippet
files, or an entire folder hierarchy and create or update a single .code-snippet
file with each of the the snippets added from Visual Studio into a VS Code snippet file.
Note that Rider support is limited to C#,VB.NET and HTML snippets only. Other language templates are stored in a completely different format and are currently not supported. If there's interest in that we might consider adding it later - for now this isn't supported.
The easiest way to use this tool is to install the .NET Global Tool from NuGet.
To install use:
dotnet tool install --global dotnet-snippetconverter
Requires:
.NET Core 2.1 SDK or later
Once installed you should able to run:
snippetconverter
from the Terminal and get the usage Help screen.
Alternately, you can clone the project and run it out of the .\SnippetConverter
folder with:
dotnet run
Or, after compiling in the .\SnippetConverter\bin\release\netcore2.2\publish
folder use:
snippetconverter
Visual Studio Snippet Converter
-------------------------------
© Rick Strahl, West Wind Technologies
Syntax:
-------
SnippetConverter <sourceFileOrDirectory> -o <outputFile>
--mode --prefix --recurse --display
Commands:
---------
HELP || /? This help display
Options:
--------
sourceFileOrDirectory Either an individual snippet file, or a source folder
Optional special start syntax using `~` to point at User Code Snippets folder:
~ - Visual Studio User Code Snippets folder (latest version installed)
~2017 - Visual Studio User Code Snippets folder (specific VS version 2019-2012)
-o <outputFile> Output file where VS Code snippets are generated into (ignored by Rider)
Optional special start syntax using `~` to point at User Code Snippets folder:
%APPDATA%\Code\User\snippets\ww-my-codesnippets.code-snippets
~\ww-my-codesnippets.code-snippets
if omitted generates `~\exported-visualstudio.code-snippets`
-m,--mode vs-vscode (default)
vs-rider experimental - (C#,VB.NET,html only)
-d display the target file in Explorer
-r if specifying a source folder recurses into child folders
-p,--prefix snippet prefix generate for all snippets exported
Example: `ww-` on a snippet called `ifempty` produces `ww-ifempty`
Examples:
---------
# vs-vscode: Individual Visual Studio Snippet
SnippetConverter "~2017\Visual C#\My Code Snippets\proIPC.snippet"
-o "~\ww-csharp.code-snippets" -d
# vs-vscode: All snippets in a folder user VS Snippets and in recursive child folers
SnippetConverter "~2017\Visual C#\My Code Snippets" -o "~\ww-csharp.code-snippets" -r -d
# vs-vscode: All the user VS Snippets and in recursive child folders
SnippetConverter ~2017\ -o "~\ww-all.code-snippets" -r -d
# vs-vscode: All defaults: Latest version of VS, all snippets export to ~\visualstudio-export.code-snippets
SnippetConverter ~ -r -d --prefix ww-
# vs-rider: Individual VS Snippet
SnippetConverter "~2017\proIPC.snippet" -m vs-rider -d
# vs-rider: All VS Snippets in a folder
SnippetConverter "~2017\Visual C#\My Code Snippets" -m vs-rider -d
This is a rough project I created to just get the job of converting my CSharp, HTML and JavaScript templates between environments. I make no guarantees that it'll move all types of snippets nor that it will capture all features of the snippets. Visual Studio Code export works very well for all types that I've tried (moving my entire snippets folder of 130+ snippets). Rider will require selectively using supported .NET Languages and HTML.
Your mileage may vary!
The SnippetConverter library is licensed under the MIT License and there's no charge to use, integrate or modify the code for this project. You are free to use it in personal, commercial, government and any other type of application.
All source code is copyright West Wind Technologies, regardless of changes made to them. Any source code modifications must leave the original copyright code headers intact.
IN NO EVENT SHALL THE AUTHOR, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THIS PROGRAM AND DOCUMENTATION, BE LIABLE FOR ANY COMMERCIAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM INCLUDING, BUT NOT LIMITED TO, LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR LOSSES SUSTAINED BY THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS, EVEN IF YOU OR OTHER PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.