fsprojects / FSharp.TypeProviders.SDK

The SDK for creating F# type providers
https://fsprojects.github.io/FSharp.TypeProviders.SDK/
MIT License
298 stars 94 forks source link

Design Time dependency resolution #217

Closed sergey-tihon closed 5 years ago

sergey-tihon commented 6 years ago

Description

I am trying to migrate SwaggerProvider to the new project format (for now targetting net45 only) and I cannot build test project with TP - https://github.com/fsprojects/SwaggerProvider/pull/110

The question is - what is the right strategy to resolve dependency for the design-time component? Historically we did it using custom assembly resolver on app domain

AppDomain.CurrentDomain.add_AssemblyResolve(fun source args ->
        SwaggerProvider.Internal.Configuration.resolveReferencedAssembly args.Name)

and code that able to find dependencies restored from NuGet https://github.com/fsprojects/SwaggerProvider/blob/master/src/SwaggerProvider.DesignTime/Configuration.fs

Seams that it is not enough using dotnet build. //cc @dsyme

Command line

It fails from the command line on macOS and Windows with the error (for more details https://ci.appveyor.com/project/sergey-tihon/swaggerprovider/build/0.0.1.585 )

/Users/sergey/github/SwaggerProvider/tests/SwaggerProvider.ProviderTests/Swagger.PetStore.Tests.fs(7,17): error FS3033: The type provider 'SwaggerProvider.SwaggerTypeProvider' reported anerror: Could not load file or assembly 'SwaggerProvider.Runtime, Version=0.10.0.0, Culture=neutral, PublicKeyToken=null'. Uncaught exception during type initialization. (Exception from HRESULT: 0x80131534) [/Users/sergey/github/SwaggerProvider/tests/SwaggerProvider.ProviderTests/SwaggerProvider.ProviderTests.fsproj]

VS 15.6.6

It shows TP error from time to time

win10_-_fall_creators

but intellisence may work even when TP report an error...

win10_-_fall_creators

Logs from custom assembly resolver

Root X:\SwaggerProvider\bin
Probing patterns [|"../../../Newtonsoft.Json*/lib/net45";
  "../../../../newtonsoft.json*/**/lib/net45"; "../../../YamlDotNet*/lib/net45";
  "../../../../yamldotnet*/**/lib/net45"|]
Found probing directories: ["X:\SwaggerProvider\bin"]
Didn't find library FSharp.Compiler.Private.resources
Assembly not found! FSharp.Compiler.Private.resources, Version=10.1.1.0, Culture=en-US, PublicKeyToken=b03f5f7f11d50a3a
Didn't find library FSharp.Compiler.Private.resources
Assembly not found! FSharp.Compiler.Private.resources, Version=10.1.1.0, Culture=en-US, PublicKeyToken=b03f5f7f11d50a3a
Didn't find library FSharp.Compiler.Private.resources
Assembly not found! FSharp.Compiler.Private.resources, Version=10.1.1.0, Culture=en, PublicKeyToken=b03f5f7f11d50a3a
Didn't find library FSharp.Compiler.Private.resources
Assembly not found! FSharp.Compiler.Private.resources, Version=10.1.1.0, Culture=en, PublicKeyToken=b03f5f7f11d50a3a

Rider 2018.1 EAP on Win

Same error in Rider but build works

win10_-_fall_creators

Logs from custom assembly resolver

Root X:\SwaggerProvider\bin
Probing patterns [|"../../../Newtonsoft.Json*/lib/net45";
  "../../../../newtonsoft.json*/**/lib/net45"; "../../../YamlDotNet*/lib/net45";
  "../../../../yamldotnet*/**/lib/net45"|]
Found probing directories: ["X:\SwaggerProvider\bin"]
Didn't find library FSharp.Compiler.Service.resources
Assembly not found! FSharp.Compiler.Service.resources, Version=19.0.1.0, Culture=en-US, PublicKeyToken=null
Didn't find library FSharp.Compiler.Service.resources
Assembly not found! FSharp.Compiler.Service.resources, Version=19.0.1.0, Culture=en-US, PublicKeyToken=null
Didn't find library FSharp.Compiler.Service.resources
Assembly not found! FSharp.Compiler.Service.resources, Version=19.0.1.0, Culture=en, PublicKeyToken=null
Didn't find library FSharp.Compiler.Service.resources
Assembly not found! FSharp.Compiler.Service.resources, Version=19.0.1.0, Culture=en, PublicKeyToken=null

Rider 2018.1 EAP on macOS

Rider can show intelligence & compile but it uses Mono msbuild

Use build tool: /Library/Frameworks/Mono.framework/Versions/Current/lib/mono/msbuild/15.0/bin/MSBuild.dll

swaggerprovider_testsanddocs____github_swaggerprovider__-_____tests_swaggerprovider_providertests_swagger_petstore_tests_fs

VS for Mac 7.4.2 (Build 12)

VS for Mac cannot show intellisence and cannot compile

visualstudio_and_swaggerprovider_providertests_ _swagger_petstore_tests_fs_ _visual_studio_enterprise_2017_for_mac

Logs from custom assembly resolver

Root /Users/sergey/github/SwaggerProvider/bin
Probing patterns [|"../../../Newtonsoft.Json*/lib/net45";
  "../../../../newtonsoft.json*/**/lib/net45"; "../../../YamlDotNet*/lib/net45";
  "../../../../yamldotnet*/**/lib/net45"|]
Found probing directories: ["/Users/sergey/github/SwaggerProvider/bin"]
Found assembly, checking version! (/Users/sergey/github/SwaggerProvider/bin/SwaggerProvider.Runtime.dll)
...version matches, returning!
Found assembly, checking version! (/Users/sergey/github/SwaggerProvider/bin/YamlDotNet.dll)
...version matches, returning!
Found assembly, checking version! (/Users/sergey/github/SwaggerProvider/bin/Newtonsoft.Json.dll)
...version matches, returning!
Didn't find library FSharp.Compiler.Private.resources
Assembly not found! FSharp.Compiler.Private.resources, Version=4.4.1.0, Culture=en-US, PublicKeyToken=f536804aa0eb945b
Didn't find library FSharp.Compiler.Private.resources
Assembly not found! FSharp.Compiler.Private.resources, Version=4.4.1.0, Culture=en, PublicKeyToken=f536804aa0eb945b

Repro steps

  1. Check out newproj branch

  2. Execute build.sh

Related information

dsyme commented 5 years ago

@sergey-tihon My understanding is that you should just use this in your TPDTC code:

    assembly.Location |> Path.GetDirectoryName |> this.RegisterProbingFolder

and ship all assemblies alongside the TPDTC component(s), similar to here: https://github.com/demetrixbio/FSharp.Data.Npgsql/blob/e0f32ac176f0afac1b22d38f2d07babf3cb46ab2/src/DesignTime/TypeProviderAssembly.fs#L32

sergey-tihon commented 5 years ago

Thank you, I close this is favor of #274 with more specific error and repro steps