How do I get the correct F # Type provider permission folder when referencing assemblies via #load?

I am writing a type provider that allows the user to provide him with a config file. I am using the internal TP config object to identify ResolutionFolder

which I am using to get the fully programmed path to the config file. Fine.

However, when working with scripts, I use Paket script load scripts to load in my dependencies. The file path looks like this: -

.paket
   |--.load
   |     |-- net452
   |           |-- main.group.fsx
   |--src
       |-- myscript.fsx
       |-- config.json

      

myscript.fsx

contains my script code. config.json

contains the configuration for the type provider instance that I will create in the script.

Internally, myscript.fsx

I call #load "..\.paket\.load\net452\main.group.fsx"

to load in all dependencies (including my TP itself) which works great.

HOWEVER

When I then try to initialize the type provider further in the script: -

type MyTPInstance = MyTp<myConfig = "config.json">

      

I am getting an error that my TP catches and shows: -

The type provider reported an error: Unable to locate config file
"C:\Users\Isaac\Source\Repos\myRepo\.paket\load\net452\config.json"

      

In other words, it looks like, since I was referencing my TP build from a script living in a different folder, this is the folder that FSI uses as the permission folder, and NOT the folder for the script that is being executed. I can prove this is a problem because if I copy the content main.group.fsx

in myscript.fsx

directly and (fixing the path to my packages of course) everything works fine.

How can I fix this? How did other people get around this?

+3


source to share


1 answer


I think I've never gotten around to getting relative path right, in any of the type providers I've linked to. If anyone else can figure it out, that would be awesome.

Sooner or later I started using [<Literal>]

and __SOURCE_DIRECTORY__

to provide an absolute path for the type provider:

[<Literal>]
let MyConfig = __SOURCE_DIRECTORY__ + "/config.json"
type MyTPInstance = MyTp<myConfig = MyConfig>

      



This has improved slightly since const

recently:

type MyTPInstance = MyTp<myConfig = const(__SOURCE_DIRECTORY__ + "/config.json")>

      

It's still pretty ugly, but at least it works reliably.

+6


source







All Articles