Open weitzhandler opened 4 years ago
I'm having this issue as well. Any update?
@weitzhandler It seems, C# Interactive doesn't support referencing packages from Nuget. You have to download an assembly and only after that reference it.
But you can use dotnet script, which supports referencing packages. To lean more about it you can read article Hitchhiker’s Guide to the C# scripting
doesn't completely solve, but you can use F# for this : https://docs.microsoft.com/en-us/dotnet/fsharp/tutorials/fsharp-interactive/
#r "nuget: Newtonsoft.Json"
open Newtonsoft.Json
let data = {| Name = "Don Syme"; Occupation = "F# Creator" |}
JsonConvert.SerializeObject(data)
This would be a very welcome addition
Would be great, a work around is to find the package in your .NuGet folder
#r "C:\Users\Chad\.nuget\packages\fakerdotnet\1.0.7\lib\netstandard2.0\FakerDotNet.dll"
FakerDotNet.Faker.MichaelScott.Quote()
Which, of course, means you have to manually download that package first. Not very convenient.
+1 this would be very convenient, and its weird not to have it as F# console has it per @jkone27's previous comment.
I'm learning C# and wanted to play around with C# interactively like I did with NodeJS. I started to try and use other libraries but I can't figure out how to bring in other libraries. I tried using #r C:\path\system.net.http.4.3.4.nupkg"
but I get an error (2,1): error CS0009: Metadata file 'C:\path\system.net.http.4.3.4.nupkg' could not be opened -- PE image doesn't contain managed metadata.
The ability to use get nuget packages would be nice.
@ajklotz you can try F# for this purpose, works much better and has the same .NET APIs and nuget package support, basic synthax is quite easy plus you have ADTs like in Rust, for easy domain modeling instead of inheritance.
it's already installed with dotnet-sdk ---> dotnet fsi your-script.fsx, or open in vscode with ionide or in visual studio after adding F# support
i think also this might work better for you
#r "nuget: System.Net.Http"
open System.Net.Http
let x = new HttpClient()
here is when running it
you can execute interactively line by line by selecting and pressing alt/option + ENTER, when i execute the last line, i get all the pretty html from google home page as value of it
, which is the last evaluated value of interactive section in F#.
a bit "out of topic", but you can also try this one out if you want to see some F# type provider magic ;) https://fsprojects.github.io/FSharp.Data/
#r "nuget:FSharp.Data"
open FSharp.Data
open System.Linq
// you don't have this in C# not any other language, rust has macros but this is a bit simpler in my view
type MyJsonType = JsonProvider<"""{ "hello" : "compile time value or sample value" }""">
let result = MyJsonType.Parse("""{ "hello" : "prod value" }""") // parses a http url or a new json
let str = result.Hello
let betterThanLinq =
[ 1 ; 2 ; 3 ]
|> Seq.map (fun x -> x + 1)
|> Seq.sum
let canStillUseLinq =
[
1
2
3
].Select(fun x -> x + 1)
.Sum()
open FSharp.Data
type MyCsvType = CsvProvider<"Country;Nr\r\nItaly;200\r\nNetherlands;30", ";">
let csv = MyCsvType.Parse("Belgium;500")
for r in csv.Rows do
printfn $"the country is: {r.Country} had {r.Nr} icecreams last year."
type MyHtmlTable = HtmlProvider<"https://vincentarelbundock.github.io/Rdatasets/datasets.html">
let test = MyHtmlTable.GetSample()
for row in test.Tables.Table2.Rows do
printfn $"%s{row.Package} %s{row.Item}"
Version Used:
3.5.0-beta4-20153-05
Steps to Reproduce:
Microsoft.Data.SqlClient
to project> #r "nuget: Microsoft.Data.SqlClient"
Expected Behavior:
Package should be added
Actual Behavior:
Getting error: