CLR 库编译但 C# 调用 returns 错误 CS0103,即使使用现有的编译元数据也是如此

CLR library compiles but C# call returns error CS0103 even with existing compiled metadata

我有一个 Visual Studio 解决方案,其中包含一个 Class 库 (C#) 和一个 CLR Class 库 (C++)。 CLR class 库正确构建,对于头文件,它非常简单:

public ref class CLRClass
{
public:
    static void CLRMethod();
};

cpp 只实现了一个空的 CLRMethod。在 C# 库中,我添加了对 CLR 项目的引用,我只是调用 CLR 方法:

CLRClass.CLRMethod();

C# 库未构建,returns 错误:

error CS0103: The name 'CLRClass' does not exist in the current context

但令人惊讶的是,如果我在 Visual Studio 中的 CLRClass 上按 F12,它确实会将我带到 dll 中编译文件的正确元数据,显示 CLR 库已正确编译且可访问:

public class CLRClass
{
  public CLRClass();

  public static void CLRMethod();
}

我不明白如何访问元数据,但是在编译 C# 库时出现 CR0103 错误,关于如何解决这个问题有什么建议吗?

C# .Net Target Framework 版本的问题。请注意,您的参考资料中有此警告:

这是因为 C# Class 库针对的框架版本 (4.7.1) 比 C++/CLI 框架 (4.8) 的版本旧。只需重新定位您的 C++ 库。