针对更高版本的 .NET 会在构建时导致 ms1685 警告

Targeting a higher version of .NET causes ms1685 warning when building

我正在使用 VS2013,它默认以 .NET Framework 4.5 为目标。我正在尝试使用需要面向 .NET 4.5.2 的第三方库。这是事情开始破裂的时候:

  1. 我收到警告 MSB3270 ("There was a mismatch between the processor architecture...and the processor architectur...x86"),所以我将平台更改为 x86。很好。
  2. 我遇到了错误(另请参阅此问题末尾的详细信息):

The type 'System.Runtime.Serialization.IExtensibleDataObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime.Serialization' etc.

所以我添加了对 System.Runtime.Serialization 的引用(虽然我不完全理解这个错误),我需要浏览并手动从 GAC 添加对它的引用(因为我有那里没有针对 .NET 4.5.2 的程序集)。

  1. 我还需要添加对 System.ServiceModel 的引用。

  2. 我以警告 MS1685("The predefined type (...) is defined in multiple assemblies")和 MSB3247("Found coflicts between different versions of the same dependent assemblies" 等)告终。 查看构建日志,冲突是:

There was a conflict between "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" and "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".

"System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" was chosen because it was primary and "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" was not.

我也运行 AsmSpy(ClassLibrary1是我的项目名称):

Reference: mscorlib
        4.0.0.0 by ClassLibrary1
Reference: Microsoft.Xrm.Sdk
        8.0.0.0 by ClassLibrary1
Reference: System.ServiceModel
        4.0.0.0 by ClassLibrary1

其他详细信息: 我尝试使用的第三方库是构建示例插件所需的 Dynamics CRM 程序集 here。我得到了清单 2 中提到的错误:

    // The InputParameters collection contains all the data passed in the message request.    
    if (context.InputParameters.Contains("Target") &&
                context.InputParameters["Target"] is Entity)

我阅读了有关这些警告的 SO 帖子。许多人(例如 1, 2) of them simply say to get rid of the reference causing the problem, but I guess I do need all of them. Others (1, 2)认为 CopyLocal - 我尝试将其设置为 TrueFalse,但没有帮助。

因此,我没有设法解决它,所以我很感激帮助。我知道这些都是"just warnings",但我真的很想解决它们。

我猜是.net 4.5.2 开发包没有正确安装。我无法对 Dynamics CRM 发表评论,因为我从未从事过这方面的工作。

执行以下步骤,如果可行请告诉我。 (我想首先你已经完成了第一步。如果是,那么我建议再做一次,因为它可能会修复安装错误。)

  1. 从 link https://www.microsoft.com/en-us/download/details.aspx?id=42637
  2. 安装 .net 4.5.2 开发包
  3. 通过转到项目属性对话框更改项目的目标版本。这将卸载项目并对引用程序集和配置文件进行必要的更改。
  4. 根据本文档中描述的步骤修正定位错误https://msdn.microsoft.com/en-us/library/cc668079.aspx