interactive
interactive copied to clipboard
Error CS0006: Metadata file 'nuget: <...>' could not be found when loading a C# script (*.csx) referencing nuget package
Description
- I have a notebook file (*.ipynb or *.dib)
- I have a C# script file (*.csx) referencing nuget package
- The notebook loads that file
- I get an error CS0006: Metadata file 'nuget: <...>' could not be found"
F# scripts are loaded fine
Example
See example project: NotebooksBug.zip
script.csx
#r "nuget: MathNet.Numerics, 5.0.0"
using System;
string Hello() => "Hello from C# script!";
notebook.ipynb
#r "nuget: MathNet.Numerics, 5.0.0"
#load "script.csx"
Hello()
c:\Users\...\NotebooksBug\script.csx(1,1): error CS0006: Metadata file 'nuget: MathNet.Numerics, 5.0.0' could not be found
.NET Interactive
- Version: 1.0.355206+4dcedd96b3252430822b3cf1591e7f4031b0df56
- Library version: 1.0.0-beta.22552.6+4dcedd96b3252430822b3cf1591e7f4031b0df56
- Build date: 2022-11-03T04:46:59.8757048Z
Environment
- OS: Windows 11
- Browser: Edge
- Frontend: Visual Studio Code
This is a subtle difference between the C# Script, F# Script, and notebook dialect. F# directly allows "#r "nuget:..."
, as does the notebook, but from a pure .csx
viewpoint, that's not allowed as a part of the language.
#load ...
isn't handled by .NET Interactive, it's instead passed directly to C# as a compiler directive.
If the gesture was instead #!import ...
this should work as is.
So... how do you work around this? I installed .NET 8 SDK and VS Code in a fresh windows 11 sandbox and get this error.
It looks like you have a space before the #r
line. Removing that space should solve it.