ieviev / fflat

F# native script compiler
GNU Affero General Public License v3.0
106 stars 3 forks source link

Error when nuget references specify versions #3

Closed amongonz closed 10 months ago

amongonz commented 11 months ago

Running fflat on any file with nuget references results in a module name collision. I can reproduce it with the following script, which runs normally with dotnet fsi:

#i "nuget: https://api.nuget.org/v3/index.json"
#r "nuget: FSharp.Data, 6.3.0"

type Foo = FSharp.Data.JsonProvider<"""{"what": 2}""">
printfn $"{Foo.GetSample().What}"

Compiling with flat results in the following error: C:\Users\amonp\.packagemanagement\nuget\Cache\577123c29bf7fd0c760d023ec7d7d71c4b44e455f2fe2617d791013c0f3c5477.fsx (1,1)-(1,1) typecheck error Two modules named '577123c29bf7fd0c760d023ec7d7d71c4b44e455f2fe2617d791013c0f3c5477' occur in two parts of this assembly

Reproduced with fflat 1.0.44 installed with .NET SDK 7.0.402 on Windows 10.

ieviev commented 11 months ago

script naming collisions is kind of a complex issue because load scripts get inlined by the tooling and fsx scripts with transitive imports don't work in dotnet fsi either.

i'll look into this when i have more time, there are two workarounds for now.

  1. replacing

    #i "nuget: https://api.nuget.org/v3/index.json"
    #r "nuget: FSharp.Data, 6.3.0"

    with just

    #r "nuget: FSharp.Data"

    should work fine.

  2. alternatively if you need the specific version, then using the contents of the fsx file in the error directly would work too

packagerefs

#r @"/home/ian/.nuget/packages/fsharp.data/6.3.0/lib/netstandard2.0/FSharp.Data.dll"
#r @"/home/ian/.nuget/packages/fsharp.data.csv.core/6.3.0/lib/netstandard2.0/FSharp.Data.Csv.Core.dll"
#r @"/home/ian/.nuget/packages/fsharp.data.html.core/6.3.0/lib/netstandard2.0/FSharp.Data.Html.Core.dll"
#r @"/home/ian/.nuget/packages/fsharp.data.http/6.3.0/lib/netstandard2.0/FSharp.Data.Http.dll"
#r @"/home/ian/.nuget/packages/fsharp.data.json.core/6.3.0/lib/netstandard2.0/FSharp.Data.Json.Core.dll"
#r @"/home/ian/.nuget/packages/fsharp.data.runtime.utilities/6.3.0/lib/netstandard2.0/FSharp.Data.Runtime.Utilities.dll"
#r @"/home/ian/.nuget/packages/fsharp.data.worldbank.core/6.3.0/lib/netstandard2.0/FSharp.Data.WorldBank.Core.dll"
#r @"/home/ian/.nuget/packages/fsharp.data.xml.core/6.3.0/lib/netstandard2.0/FSharp.Data.Xml.Core.dll"

type Foo = FSharp.Data.JsonProvider<"""{"what": 2}""">
printfn $"{Foo.GetSample().What}"
amongonz commented 11 months ago

Oh, you're right! Pinning the version is what triggers the error; that'll do as a workaround to check out fflat, thanks.

ieviev commented 10 months ago

nuget versions now supported in 0.0.46