在F#项目中使用C#库? [英] Using C# library in an F# project?

查看:229
本文介绍了在F#项目中使用C#库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚接触F#,但是我真的很想学习它.我知道Python,我知道C#.事实上,我有一个自己创建的C#库;它是Rdio API(我已将其命名为RdioSharp)的包装,可以成功地将其引入另一个C#项目并调用它,使用它,获取数据...它可以正常工作.

I'm fresh to F#, but I really want to learn it. I know Python, I know C#. As a matter of fact, I've got a C# library that I've made myself; it's an wrapper for the Rdio API (I've named it RdioSharp) that I can successfully bring into another C# project and call it, use it, get data... it works.

我想开始在F#项目中使用这个C#库,但是它不能正常工作.这里简要介绍了C#代码的外观.

I want to get started toying around with this C# library in an F# project, but it's not working right. Here's a brief snipped of what the C# code looks like.

namespace RdioSharp {
    public class RdioManager {
        public RdioManager() { }
    }
}

我在我的FSharpTest项目中添加了对该DLL的引用,我拉出了一个.fsx文件,并且我尝试了下面的每一行(再次注意,我确实不知道我在做什么).

I've added the reference to the DLL in my FSharpTest project, I've pulled up a .fsx file, and I've tried the following, each line below (again, keep in mind, I really have no idea what I'm doing).

open RdioSharp
open RdioSharp.dll
#r "RdioSharp.dll"
#r "C:\Path\To\Library\RdioSharp.dll"

我不知道这一点.我知道如何使用系统F#库,但是如何在F#中引用C#库?是否有可能?这是足够的信息吗?

I can't figure this one out. I know how to use system F# libraries, but how do I reference a C# library in F#? Is it possible? Is this enough information to go on?

我见过

I've seen this and this (which gets even closer to my problem) but those folks all know more about F# than I do, and they're way ahead of my problem.

在交互式窗口中,按#r "RdioSharp.dll";;时,出现这个可爱的错误.

In the interactive window, when punching in #r "RdioSharp.dll";; , I get this lovely error.

error FS0084: Assembly reference 'RdioSharp.dll' was not found or is invalid

推荐答案

如果F#环境可以找到Rdiosharp.dll的位置,则以下代码有效.通常不行!因此它不起作用,并告诉您错误FS0084:找不到程序集引用'RdioSharp.dll'或无效".

The following code works if F# environment can find the location of Rdiosharp.dll. Usually not! So it does not work and tells you that "error FS0084: Assembly reference 'RdioSharp.dll' was not found or is invalid".

#r "RdioSharp.dll"

您可以提供该dll的确切路径,如下所示:

You can provide the exact path of this dll as in:

#r @"c:\temp\RdioSharp.dll"

或者您可以将其文件夹添加到搜索路径中:

or you can add its folder into search-path:

#I @"c:\temp"

这篇关于在F#项目中使用C#库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆