SSG.NET: Turn ASP.NET Core MVC Applications into Static Sites

July 12, 2023 by Khalid Abuhakmeh

Static site generation can be one of the most effective ways to deploy content to users. When you generate web pages at compile-time, you pay the cost of expensive operations once and outside of the standard HTTP request pipeline, as opposed to the traditional server-client model, which may execute expensive back-end operations on every request. The benefits can positively impact SEO page rankings, user experience, and hosting costs. Sounds great, right?

Wouldn't it be even better to combine the strengths of the ASP.NET Core ecosystem with the performance of static site generators? What if you could use common patterns in ASP.NET Core MVC to provide a quick onboarding to static-site Nirvana? Well, we have the .NET OSS package just for you. We're happy to introduce you to SSG.NET, a .NET global tool that can process an existing ASP.NET Core MVC application and generate static assets you can host almost anywhere.

Let's see how to get started with the library and explore the blog template provided by the tool author, Camilo Terevinto.

Getting Started

To begin using SSG.NET, you must install the tool into your tools global directory.

dotnet tool install --global TerevintoSoftware.StaticSiteGenerator.Tool

You may also install SSG.NET to your ASP.NET Core MVC's solution directory using the tool-manifest template as part of the .NET CLI tooling.

Once you've installed the tool, you can run the following command at the root of your solution directory to start the static site generation process. Be sure to change the inputs to match your solution.

ssg --project ./src/MySite --output ./site
--route-casing KebabCase --use-localization true --assembly bin/Release/net6.0/MySite.dll

It's important to note that SSG.NET executes only the view portion of your ASP.NET Core MVC applications. The limitations mean that the logic found in Controllers, Models, or Middleware is not part of the transformation process. Also, the library does not currently support Razor Pages as of writing this post.

SSG.NET's Blog Template

If you'd like to explore SSG.NET as a platform for blogging, the project has been kind enough to provide a starter template. To get started, you can clone the Blog template repository. Once you've cloned the repository, you can add new entries to the blog by adding new Markdown files to the Posts directory and a corresponding .cshtml file under the /Views/Posts directory.

From here, you can share your latest .NET blog posts on your favorite static site hosts like Windows Azure, Amazon Web Services, GitHub, or Netlify.

Conclusion

SSG.NET is a straightforward and familiar introduction to static site generation for the .NET Community. If you've felt overwhelmed by them in the past, SSG.NET is a great way to reuse your existing ASP.NET Core MVC skills to produce efficient and performant web pages without the steep learning curve.

The SSG.NET project is also looking for folks to help and contribute to the existing project. If you're interested in helping maintainer Camilo Terevinto, please head to the SSG.NET GitHub repository.