0

我正在尝试按照入门指南使用 Visual Studio 2015 使用 Cppsharp 开始我的第一个项目。

我遵循的步骤是:

  1. 创建新的 C# 控制台项目
  2. 使用 Nuget 安装 Cppsharp
  3. 在项目中添加对 Dll 的引用
  4. 根据这个旧帖子中的示例创建 C# 源文件

虽然帖子中的示例很旧,但它似乎仍然与入门指南一致。下面列出了完整的程序。

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

using CppSharp;

namespace CppSharpTest
{
    class Program
    {

        class DllDemoGenerator : ILibrary
        {
            static void Main(string[] args)
            {
                ConsoleDriver.Run(new DllDemoGenerator());
            }

            void Setup(Driver driver)
            {
                var options = driver.Options;
                options.GeneratorKind = LanguageGeneratorKind.CSharp;
                options.LibraryName = "DllDemo";
                options.Headers.Add("DllDemo.h");
                options.Libraries.Add("DllDemo.lib");
            }

            public void SetupPasses(Driver driver) { }

            public void Preprocess(Driver driver, CppSharp.AST.Library lib) { }

            public void Postprocess(CppSharp.AST.Library lib) { }
        }

    }
}

但是,我已经面临错误参见图片

CS0012  C# The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=...'

我无法找到添加此参考的方法。我发现的一个解决方案建议针对更高的 .NET 版本(4.7.2),我尝试了这个,但错误仍然存​​在。

任何人都可以帮助克服这个问题吗?

4

1 回答 1

0

在 Github 页面上发布了同样的问题,建议从 VS2015 升级

安装 VS2019 消除了这个错误

于 2021-05-14T15:01:20.853 回答