簡體   English   中英

從同一解決方案打開 c# 命名空間,在 f# 中引用項目

[英]open c# namespace from same solution, referenced project in f#

我仍在嘗試了解引用項目中的命名空間。

我有一個 ac# 項目,其中定義了一個命名空間(“A”)。 我創建了一個 F# 應用程序,我在其中引用了 c# 項目。

open A

導致以下情況:

錯誤 FS0039:未定義命名空間或模塊“A”

這是我檢查過的:

MSDN 沒有多大幫助( http://msdn.microsoft.com/en-us/library/vstudio/dd393787.aspx )。

謝謝。

[編輯]

我是從頭開始的,所以這個例子既簡潔又干凈。

C# 項目“ClassLibrary1”包含:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary1
{
    public class Class1
    {
    }
}

F# 應用程序是:

// Learn more about F# at http://fsharp.net
// See the 'F# Tutorial' project for more help.
open ClassLibrary1

[<EntryPoint>]
let main argv = 
    printfn "%A" argv
    0 // return an integer exit code

錯誤:

未定義命名空間或模塊“ClassLibrary1”

確保您的引用是真實的項目引用,而不僅僅是引用 bin\\Debug 文件夾中的 DLL。

如果您無法獲得真正的項目引用,請確保將 F# 項目設置為依賴於 C# 項目,以便它首先由 Visual Studio 構建(右鍵單擊項目並轉到項目依賴項,然后使用復選框)。

我有同樣的問題。 我所要做的就是確保我的 C# 項目依賴項全部解決,構建我的 C# 項目,然后 F# 項目能夠引用正確的 dll。

在 Visual Studio 中,您可以右鍵單擊每個 C# 項目並按構建。 在 VSCode 中,您必須使用終端導航到每個項目並運行dotnet build

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM