dotnet / interactive

.NET Interactive combines the power of .NET with many other languages to create notebooks, REPLs, and embedded coding experiences. Share code, explore data, write, and learn across your apps in ways you couldn't before.
MIT License
2.8k stars 373 forks source link

Error CS0006: Metadata file 'nuget: <...>' could not be found when loading a C# script (*.csx) referencing nuget package #2431

Open Oblomoff opened 1 year ago

Oblomoff commented 1 year ago

Description

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

Environment

brettfo commented 1 year ago

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.

ronnieoverby commented 2 months ago

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.

image

jonsequitur commented 3 weeks ago

It looks like you have a space before the #r line. Removing that space should solve it.