简体   繁体   中英

Giving relative path of project in F#

I am trying to incorporate F# SQLProvider into my project. And for now I can successfully access the Postgresql database. But there is something called resolution path. That I need to give. Now, the question is path will be different for deployed application and application I am developing on my local machine. So, how can I give relative path to my dll.

Right now I am using below path

[<LiteralAttribute>]
let resolutionFolder = @"D:\<myprojectdirectory>\<projectname>\packages\Npgsql.2.2.2\lib\net45"

So, is it possible to convert to something like

[<LiteralAttribute>]
let resolutionFolder = @"..\sqlprovider\packages\Npgsql.2.2.2\lib\net45"

Now, in Azure site I don't which path it will be. So, above path is not fix. But if I can give relative path that will be better solution I guess.

Let me know if any further details are required.

It would seem like you could use conditional preprocessor directives to help you here.

[<Literal>]
let resolutionFolder =
#if DEBUG
    @"D:\<myprojectdirectory>\<projectname>\packages\Npgsql.2.2.2\lib\net45"
#else
    @"..\sqlprovider\packages\Npgsql.2.2.2\lib\net45"
#endif

When you define your SqlDataProvider type, you provide the connection string and resolution path. This is required at design time so that it can generate the types you need. Eg:

type sql = SqlDataProvider<
              "<design-time connection string>",
              DatabaseVendor = Common.DatabaseProviderTypes.SQLITE,
              ResolutionPath = "<design-time path>">

When you use the sql type, you call the sql.GetDataContext function. This function has overloads, one of which allows you to provide the connection string and the resolution path as strings. These values will override what was provided when the type was defined.

let ctx = sql.GetDataContext("<RealConnectionString>", "<RealResolutionPath>")

Because these strings to GetDataContext are not needed at design time, you can source them from a configuration file, or an Environment variable, etc. You can then have settings for development vs settings for production.

I'm not sure where your resolution path will need to point in Azure, but by using something like an environment variable it should be simple to update as needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM