使用 Unity IoC 容器时 VS 2015 建模项目 MSB3268 警告

VS 2015 Modeling Project MSB3268 warnings when using Unity IoC Container

我正在使用 Visual Studio Enterprise 2015 并尝试创建一个层次图以生成和验证依赖关系。但这失败了,因为 VS 在构建建模项目时发出警告:

CurrentVersion.targets(1819,5): warning MSB3268: The primary reference "...\ClassLibrary4\bin\Debug\ClassLibrary4.dll" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "...\ClassLibrary4\bin\Debug\ClassLibrary4.dll" or retarget your application to a framework version which contains "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".

我发现如果您删除 Unity,警告就会消失,并且依赖项会按预期显示。

此行为的原因是什么?有什么解决方法吗?

我尝试了 Unity 预发布包以及其他目标框架。一点作用都没有。在添加建模项目并在一个引用项目中使用 unity 后,该问题可通过新项目重现。

我在将构建输出设置为详细后找到了解决方案。 VS2015编译建模项目使用错误的目标框架(4.0)的问题:

Task Parameter:TargetFrameworkDirectories=C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0

建模项目(*.modelproj)的项目文件中没有TargetFrameworkVersion。但是在将它添加到第一个 属性 组之后,它正在按预期进行编译和验证。没有任何警告。

解决方案:

  1. 卸载建模项目
  2. 右键单击 -> 打开 *.modelproj
  3. 将以下行添加到第一行 属性(替换为您的目标框架)

(用您的目标框架替换 v4.5)

<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>

乐于使用架构工具。