简体   繁体   English

包含引用后无法使用项目中的命名空间? F# C#

[英]Unable to use namespace from project after including reference? F# C#

I'm following a guide from Tomas Petricek on pluralsight.我正在遵循 Tomas Petricek 的关于 Multiplesight 的指南。 I'm trying to make a C# unit test project to test some methods from an F# library, however even after adding the reference to the F# project in the C# project I can't use any of the methods as they are not recognized and when trying to use the namespace from the F# project it is an unknown namespace.我正在尝试创建一个 C# 单元测试项目来测试 F# 库中的一些方法,但是即使在 C# 项目中添加对 F# 项目的引用后,我也无法使用任何方法,因为它们无法识别,并且何时尝试使用 F# 项目中的命名空间,它是一个未知的命名空间。

Most solutions to questions like these appear to be the targeting of different frameworks, however, I am targeting 4.5.2 in both projects.大多数此类问题的解决方案似乎都针对不同的框架,但是,我在两个项目中都针对 4.5.2。

What could be going wrong?可能出什么问题了?

One thing to check is to make sure that the F# project is compiled and there were no errors. 要检查的一件事是确保编译F#项目并且没有错误。

When a C# project references an F# library, the C# compiler will look at the resulting dll file and provide auto-complete based on the compiled library. 当C#项目引用F#库时,C#编译器将查看生成的dll文件,并根据编译的库提供自动完成。 This is different than when you reference C# library from a C# project, because in this case, the auto-completion is based on the checks that Visual Studio does in background. 这与从C#项目引用C#库时不同,因为在这种情况下,自动完成基于Visual Studio在后台执行的检查。

This means that, whenever you change the public API of the F# library, you need to recompile it to make sure that the C# project sees the latest version. 这意味着,每当您更改F#库的公共API时,都需要重新编译它以确保C#项目看到最新版本。

For me the project build without issues and despite multiple dotnet clean; dotnet build;对我来说,项目构建没有问题,尽管有多个dotnet clean; dotnet build; dotnet clean; dotnet build; the IDE was still complaining. IDE 仍在抱怨。 It said that my newly added modules of the references projects were not available in the test project.它说我新添加的参考项目模块在测试项目中不可用。

In the end restarting VsCode did the trick.最后重新启动 VsCode 就成功了。

I'm using VsCode 1.63 with Iodine and both projects are F# projects.我将 VsCode 1.63 与 Iodine 一起使用,并且两个项目都是 F# 项目。

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

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