工程的生成版本低于引用的DLL对应的生成版本时,在安装了VS2015的环境上编译时会报错:
The primary reference "XXXXX" could not be resolved because it was built against the ".NETFramework,Version=v4.6.1" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.5.2". (MSB3274) - C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets:1697,5
The type or namespace name 'XXXX' could not be found (are you missing a using directive or an assembly reference?) (CS0246) -XXXXXXXX:NN,N
但未安装VS2015的却不会报错。
分析原因:
安装VS2015后工程编译时使用的是非C:\Windows\Microsoft.NET\Framework\v4.0.30319目录的下MSBuild.exe而是C:\Program Files (x86)\MSBuild\12.0\bin下的MSBuild.exe,这个编译工具会有其它额外的参数配置(.targets文件)。
解决:
C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets文件中<ResolveAssemblyReference 标签内的 TargetFrameworkMoniker="$(TargetFrameworkMoniker)"删除。