Search code examples
c#scriptingnugetroslyn

Referring to NuGet packages from csx script


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?


Solution

  • 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