I am trying to write a C# interactive script (.csx) that needs to use a NuGet package, but I must be overlooking something fundamental because I can't get it to work.
I tried adding a project.json
that refers to the package, and it gets installed into the global packages dir when I nuget restore
, but it seems the #r
directive does not look there. I failed to find a relevant documentation on how the #r
directive work (most docs seem to deal with the similar but different project called ScriptCS).
How do you write a csx script that references NuGet packages?
Visual Studio (csproj > Properties > Package > Tick "Generate NuGet Package on Build". Then Build the solution) dotnet CLI (in command prompt in project folder: dotnet build , then dotnet pack commands) NuGet CLI (in command prompt in project folder: dotnet build , then nuget pack command)
Developer file written in Visual C# Script, a C# API developed by Microsoft under the codename The Roslyn Project; used for developing components in C# that can run on-demand as scripts with the Roslyn framework. The Roslyn program that runs CSX files as scripts is named rcsi.exe.
In Visual Studio, select Tools, and then select Options. Select NuGet Package Manager, and then select Package Sources. Enter the feed's Name and Source URL, and then select the green (+) sign to add a new package source. If you enabled upstream sources in your feed, clear the nuget.org checkbox.
Dotnet Script has support for referencing Nuget packages in CSX files:
#r "nuget: AutoMapper, 6.1.0"
https://discoverdot.net/projects/dotnet-script#nuget-packages-1
Very simple from Visual studio UI:
Manage NuGet Packages
Browse or Installed
tab and click the nuget.org
URLScript and Interactive
tab, then simply click the copy button and paste it in your CSI in Visual studio or *.csx fileIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With