This week we released version 1.4 of dotnet-script. The latest release introduces support for .NET 7.0 and C# 11 and is available, as usually, through Github releases and on Nuget. You will need to have at least the .NET SDK 7.0.100 installed.
Installation π
The installation command is the same as always β you can get ahold of dotnet-script by running the dotnet tool installation:
dotnet tool install dotnet-script -g
For existing users, the update command is relevant:
dotnet tool update dotnet-script -g
If, after the upgrade, you are running into troubles with existing scripting due to script caching issues, make sure to try running the script with with -βno-cache flag.
As of this release, dotnet-script is no longer distributed via Chocolatey.
Microsoft.NET.Sdk.Web support and other features π
A nice new feature in 1.4 is that you can now specify Microsoft.NET.Sdk.Web in your script, which gives you access to all the regular web features of ASP.NET Core. Because of that, you can use dotnet-script to, for example, run a web server.
The SDK is specified using a custom #r “sdk:⦔ directive.
#r "sdk:Microsoft.NET.Sdk.Web"
using Microsoft.AspNetCore.Builder;
var a = WebApplication.Create();
a.MapGet("/", () => "Hello world");
a.Run();
In terms of other changes, dotnet-script no longer uses Newtonsoft.Json, which means there will no longer be collisions between its own version and the version you might have wanted to use in your script, which was one of the most complained about bugs. A bunch of other packages that previously suffered from the same problem were also addressed.
The generated VS Code assets no longer stop at entry automatically (only at breakpoints), which was confusing and created an illusion of a “deadlock” when debugging.
Language server support π
The accompanying language server features in OmniSharp have also been updated accordingly, however, they have not been released yet. Because of that, the easiest way to ensure you do not lose intellisense and other editor features is to set:
"omnisharp.path":"latest"
in your VS Code settings. This will download the latest available pre-release build of OmniSharp. This will no longer be needed after the next release of OmniSharp and the C# Extension for VS Code.