【发布时间】:2015-05-02 16:14:36
【问题描述】:
我正在尝试创建一个用 C# 编写的 DLL,它将利用 Windows 8.1 包,例如 Windows.Storage 和 Windows.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