【问题标题】:Creating a DLL for Windows Store 8.1 Apps为 Windows Store 8.1 应用程序创建 DLL
【发布时间】:2015-05-02 16:14:36
【问题描述】:

我正在尝试创建一个用 C# 编写的 DLL,它将利用 Windows 8.1 包,例如 Windows.StorageWindows.Media。当不包括使用Windows 包的类时,DLL 使用csc.exe 进行编译。

当尝试编译整个 DLL(包括额外的类)时,我添加了 /r:"C:\Program Files (x86)\Windows Kits\8.1\References\CommonConfiguration\Neutral\Windows.winmd" 编译器选项以包含缺少的 Windows 包。然后编译器会抛出这个错误:

c:\Program Files (x86)\Windows Kits\8.1\References\CommonConfiguration\Neutral\Windows.winmd:错误 CS0012:类型“System.Attribute”在 未引用的程序集。您必须添加对程序集的引用 'System.Runtime,版本=4.0.0.0,文化=中性, PublicKeyToken=b03f5f7f11d50a3a'。

但是,当我尝试包含 C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.dll 时,编译器会为我使用的几乎每个类提供 error CS0433,并声明 The type '...' exists in both '...\mscorlib.dll' and '...\Runtime.dll'

有没有办法只包含来自 Runtime.dll 的必要包?还是有完全不同的方法来轻松编译这个 DLL?

【问题讨论】:

  • 您没有通过 Visual Studio 构建它的任何特殊原因?
  • @BradleyDotNET Visual Studio 拒绝让我将构建设置更改为库。所以我在 Visual Studio 中编写/测试代码,但通过批处理文件进行最终构建。通过将所有 v4.5 目录更改为 v4.5.1,我最终找到了解决方案 here

标签: c# .net dll windows-8.1


【解决方案1】:

要解决此问题,请添加对 System.Runtime.dll 外观的引用。通常,此门面位于C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Facades\System.Runtime.dll

这里的根本问题是不同的 .NET 实现在不同的程序集上定义了 System.Attribute 类型。但是,.NET/Windows 类型投影层——使 Windows 运行时类型看起来像普通 .NET 类型的粘合剂——并且编译器期望在 System.Runtime.dll 中定义 System.Attribute。这适用于某些 .NET 实现,但不适用于 Windows 附带的内置 .NET Framework。

上面引用的门面提供了一个指向编译器的指针,即System.Attribute 的实现确实在此实现的 System.dll 中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-25
    • 2017-11-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多