ASP.NET Core Snippets for Visual Studio Code


Image result for visual studio code logoI’m currently creating a new course on how to use Visual Studio Code with ASP.NET Core. While I rely on yeoman for project scaffolding and some file scaffolding, I wanted to get some of the snippets I’ve grown used to having in the full Visual Studio.

I found a project called ASP.NET Core Snippets to my excitement, but it only had snippets for some of the main files in your project. Not action snippets or razor snippets. So at 4am last night I wrote a Visual Studio Code extension to add some of these snippets.

So far, it only has a handful of snippets that my 4am brain knew I wanted:

C# Snippets:

mvc6-action: Creates an MVC6 Action that returns a view.
mvc6-get: Creates an MVC6 Action that Implements a basic GET.
mvc6-post: Creates an MVC6 Action that Implements a basic POST.
mvc6-put: Creates an MVC6 Action that Implements a basic PUT.
mvc6-delete: Creates an MVC6 Action that Implements a basic DELETE.
mvc6-controller: Creates an MVC6 Controller for views.
mvc6-apicontroller: Creates an MVC6 Controller for an API that implements all four basic verbs.
ef-dbcontext: Creates an Entity Framework Core DbContext class.

Razor Snippets:

razor-inject: Generates an @inject block.
razor-environment: Generates an environment block.
razor-raw: Generates an @Html.Raw block.

You can get the snippet from the marketplace here:

http://shawnw.me/aspnetcoresnippets

or by installing them directly in Visual Studio Core:

install

I’d love anyone that has snippets that would be helpful or knows a snippet they’d like me to build. Fork the repo and send me a pull-request, or just add an issue to the github repo:

http://github.com/shawnwildermuth/aspnetcore-snippets




Application Name WilderBlog Environment Name Production
Application Ver 1.1.0.0 Runtime Framework .NETCoreApp,Version=v1.1
App Path D:\home\site\wwwroot Runtime Version .NET Core 4.6.25211.01
Operating System Microsoft Windows 6.2.9200 Runtime Arch X86