简体   繁体   English

在F#项目中使用C#库?

[英]Using C# library in an F# project?

I'm fresh to F#, but I really want to learn it. 我刚接触F#,但是我真的很想学习它。 I know Python, I know C#. 我知道Python,我知道C#。 As a matter of fact, I've got a C# library that I've made myself; 事实上,我有一个自己创建的C#库。 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. 它是Rdio API(我已将其命名为RdioSharp)的包装,可以成功地将其引入另一个C#项目并调用它,使用它,获取数据...它可以工作。

I want to get started toying around with this C# library in an F# project, but it's not working right. 我想开始在F#项目中使用这个C#库,但是它不能正常工作。 Here's a brief snipped of what the C# code looks like. 这里简要介绍了C#代码的外观。

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

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). 我在FSharpTest项目中添加了对DLL的引用,我拉出了.fsx文件,并且尝试了以下每一行(再次注意,我真的不知道我在做什么)。我在做)。

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

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#? 我知道如何使用系统F#库,但是如何在F#中引用C#库? 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. 我已经看到了 一点 (甚至更加接近我的问题),但是那些人都比我更了解F#,他们远远领先于我的问题。

In the interactive window, when punching in #r "RdioSharp.dll";; 在交互式窗口中,当#r "RdioSharp.dll";; , I get this lovely error. ,我得到这个可爱的错误。

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

The following code works if F# environment can find the location of Rdiosharp.dll . 如果F#环境可以找到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". 因此它不起作用,并告诉您“错误FS0084:找不到程序集引用'RdioSharp.dll'或无效”。

#r "RdioSharp.dll"

You can provide the exact path of this dll as in: 您可以提供此dll的确切路径,如下所示:

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

or you can add its folder into search-path: 或者您可以将其文件夹添加到搜索路径中:

#I @"c:\temp"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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