dotnet-script 0.11 out – with inline Nuget support

Β· 558 words Β· 3 minutes to read

Yesterday I released, thanks to the great help of Bernhard - version 0.11 of dotnet-script, the C# script runner for .NET Core.

It is the biggest release yet - with the highlight feature being the ability to use inline Nuget packages.

Here is the overview of what’s in there.

Inline Nuget packages πŸ”—

dotnet-script now supports inline #r directives for Nuget packages. This can be used in the following way:

#r "nuget:Automapper,5.1.1"

using Automapper; 
// just start consuming the nuget package

It is the recommended way of referencing Nuget packages in the future.

project.json references are still supported but should be avoided. Remember, that when using them, you will need to make sure you use the version of dotnet CLI that is capable of restoring them (that is, non-csproj version of dotnet CLI). You can force a specific version of dotnet CLI in a given location using global.json file.

The new inline Nuget packages are also already supported on the tooling side by OmniSharp, which will recognize such reference correctly in order to provide intellisense and other language services. Make sure to get the latest preview of C# extension for Visual Studio Code. Because this feature is in preview in OmniSharp, you will then need to add the following entry to your omnisharp.json:

{
    "Script": {
        "enableScriptNuGetReferences": true
    }
}

Stand alone execution support πŸ”—

Instead of having to install from Nuget as .NET CLI tool, you can now download a stand alone instance of dotnet-script as ZIP and use directly from the release page. Once the distro is unzipped, you can find the entry point files: dotnet-script.cmd and dotnet-script.sh inside, which can be added to the PATH.

Once the dotnet-script folder is available the PATH, .NET CLI automatically recognizes it, and you can use the elegant dotnet script {filename.csx} command format.

Vastly improved debugging experience πŸ”—

Thanks to the move to Roslyn 2.3.1, debugging is much more dependable.
The debugger configuration is also much simplified. Here is the new launch.json configuration needed to debug:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Script Debug",
            "type": "coreclr",
            "request": "launch",
            "program": "dotnet",
            "args": [
              "exec", 
              "{PATH_TO}\\dotnet-script.dll", // from the ZIP attached to this release
              "${file}"
            ],
            "cwd": "${workspaceRoot}",
            "stopAtEntry": true
        },
        {
            "name": ".NET Script Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}

Note that by using ${file} placeholder debugger automatically starts for the current file - no need to hardcode the name of the CSX in the launch.json.

You can also add a debugger break in your script and always attach to a paused script, since PDB symbols are now being emitted for each script execution.

Upgrade to NET Core App 1.1 πŸ”—

The scripts now execute (and consume their inline Nuget dependencies) in the context of NET Core App 1.1.

Bug Fixes πŸ”—

  • correctly set the working directory path when resolving #r and #load directives. Additionally, fixed bugs related to #load and #r resolution when running scripts using relative path
  • improved handling of platform-specific dependencies
  • suppress bogus compiler warnings (i.e. CS1701)
  • do not lock file upon running the script
  • use CommandLineScriptGlobals instead of InteractiveScriptGlobals as the globals (“host”) type in the script execution context
  • correctly infer encoding for the source files when debugging
  • aligned internal script runner dependency versions and several other small build/development related fixes

Contribute πŸ”—

If you want to contribute - please visit the Github repo! Thanks!

About


Hi! I'm Filip W., a cloud architect from ZΓΌrich πŸ‡¨πŸ‡­. I like Toronto Maple Leafs πŸ‡¨πŸ‡¦, Rancid and quantum computing. Oh, and I love the Lowlands 🏴󠁧󠁒󠁳󠁣󠁴󠁿.

You can find me on Github, on Mastodon and on Bluesky.

My Introduction to Quantum Computing with Q# and QDK book
Microsoft MVP