3

我有这个错误,我无法弄清楚。

我在带有 .net4.5 的 Windows 8 上使用 VS 2012 (VS11),在编译使用 VS 2010 和 .net4.0 的项目时出现此错误。

这是完整的错误:

该类型System.Windows.Input.ICommand同时存在于 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\PresentationCore.dll' 和 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\System .dll'

如果有人可以就导致它的原因和/或如何解决它提供一些见解,我将不胜感激。

谢谢。

4

4 回答 4

7

c:\Windows\Microsoft.NET\Framework\v4.0.30319\System.dll

The message is accurate, ICommand indeed exists in both assemblies for .NET 4.5. The problem is your reference to System.dll, your project is using the wrong one. The assemblies in the Microsoft.NET directory are no longer suitable to act as reference assemblies, like they were in versions of .NET prior to .NET 4.0. They should no longer be there but unfortunately are required to get C++/CLI projects built.

Your reference to PresentationCore.dll is correct, it uses the c:\program files\reference assembly subdirectory. The proper home for reference assemblies in .NET 4.0 and up. These assemblies are special, they contain only metadata and are not a copy of the runtime assemblies.

You'll need to fix your project. System.dll is probably not the only assembly that has this problem. Open the References node of your project and verify them one by one. Remove bad ones that point to Microsoft.NET and replace them with good ones by using Project + Add Reference. Best to just replace them all to be sure.

于 2013-05-27T14:56:05.163 回答
2

我对 fxcopcmd V12 也有类似的问题。我能够通过明确添加来解决它

/reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\WindowsBase.dll"

请参阅:WPF 程序集上的 FxCop 引擎异常

于 2014-07-21T07:28:35.493 回答
0

看看这个类似的帖子,我该如何解决这个问题?单元类型存在于两个 dll 文件中,这表明您正在引用具有相同类型的两个程序集,因此您需要给出要使用完全量化名称的类型。

于 2013-05-27T12:22:16.177 回答
0

迁移到新的构建服务器后,我们的库也遇到了同样的问题。

解决方案是指定要构建的 .net 框架的路径:

/p:FrameworkPathOverride="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0"

如果构建服务器上没有安装 .net 4.0 框架(多目标包)(就像我们一样),您只需将“v4.0”文件夹及其所有程序集复制到构建服务器;)

于 2017-02-21T11:08:00.223 回答