I've blogged about ServiceStack before. It's an extraordinary open source project - an ecosystem of its own even - that is designed to be an alternative to the WCF, ASP.NET MVC, and ASP.NET Web API frameworks. I enjoy it so much I even helped write its tagline "Thoughtfully architected, obscenely fast, thoroughly enjoyable web services for all"
ServiceStack is an easy drop-in that simplifies creating Web Services in any ASP.NET Web App, but also in Self Hosting Console Apps, Windows Services and even Windows and OSX Desktop Apps - supporting both .NET Framework and .NET Core. The easiest way to get started is to create a new project from a ServiceStack VS.NET Template.
ServiceStack has released a new and amazing project that is absolutely audacious in its scope and elegant in its integration with the open source .NET Core ecosystem - #Script (pronounced "sharp script.")
Scripts IN your app!
There are a number of .NET projects that simulate REPL's or allow basic scripting, like "dotnet script" as an example or ScriptCS but I'm deeply impressed with #Script. To start with, #Script is somewhat better suited for scripting than Razor and it doesn't require precompilation. #Script is appropriate for live documents or Email Templates for example.
Here's a basic example of embedding a ScriptContext in your app:
var context = new ScriptContext().Init();
var output = context.EvaluateScript("Time is now: {{ now | dateFormat('HH:mm:ss') }}");
Where ServiceStack's #Script really shines is its use of .NET Core Global Tools. They've nabbed two global tool names - web and app (sassy!) and allow one to create SharpApps. From their site:
Sharp Apps leverages #Script to develop entire content-rich, data-driven websites without needing to write any C#, compile projects or manually refresh pages - resulting in the easiest and fastest way to develop Web Apps in .NET!
The web tool is cross platform and the app global tool is great for Windows as it supports .NET Core Windows Desktop Apps.
Your app IS a script!
You can write interactive SharpScripts or SharpApps that uses Chromium as a host.
You can literally run a "desktop" app self contained from a GitHub Gist!
Sharp Apps can also be published to Gists where they can be run on-the-fly without installation, they're always up-to-date, have tiny footprints are fast to download and launch that can also run locally, off-line and cross-platform across Windows, macOS and Linux OS's.
There's also a "gallery" that maps short names to existing examples. So run "app open
" to get a list, then "app open name
" to run one. You can just "app open blog
" and you're running a quick local blog.
Easy to develop and run
The global tools make SharpApp a complete dev and runtime experience because you can just run "app" in the source folder and as you make code changes the hot-reloader updates the site as you Ctrl-S (save) a file!
If you've got .NET Core SDK installed (it's super quick) then just grab the local tool here (app on Windows and web anywhere else):
dotnet tool install --global app
And if you have a existing .NET Core web app you can launch it and run it in a Chromium Embedded Framework (CEF) browser with "app foo.dll
" Check out this example on how to make and run a .NET Core app on the Windows Desktop with #Script.
Then you can make a shortcut and add it to to the desktop with
app shortcut Acme.dll
Slick!
Code in #Script is done in markdown ```code
blocks, while in Razor it's @{ } but it does use mustache template style. Go try out some of their Starter Projects!
#Script and SharpApps is an extraordinary addition to the .NET Core ecosystem and I'm just touching the surface. Do check out their site at https://sharpscript.net.
What do you think?
Sponsor: Develop Xamarin applications without difficulty with the latest JetBrains Rider: Xcode integration, JetBrains Xamarin SDK, and manage the required SDKs for Android development, all right from the IDE. Get it today!
© 2019 Scott Hanselman. All rights reserved.