在 VS2013 中针对 .Net 4.6 的某些项目的项目加载失败
Project load fails for some projects targeting .Net 4.6 in VS2013
我有一个解决方案,其中包含许多针对 .Net 4.6 的 C# 项目和一个本机 C++ 项目(无 CLR)。在 VS2015 中使用解决方案后,我现在尝试在 VS2013 中打开解决方案时出现错误,一半的项目无法加载。
原生C++项目和部分C#项目报错:
error : A numeric comparison was attempted on "$(TargetPlatformVersion)" that evaluates to "10.0.10069.0" instead of a number, in condition "'$(TargetPlatformVersion)' > '8.0'". C:\Program Files (x86)\MSBuild.0\bin\Microsoft.Common.CurrentVersion.targets
我不确定为什么有些项目可以正确加载而其他项目不能,但是,看起来所有引用 NuGet 包的 C# 项目都失败了。
有没有办法修复这些错误并允许在 VS2013 和 VS2015 中打开解决方案和项目?
在尝试对项目文件进行各种更改后,我发现从本机 C++ 项目中删除以下行后,解决方案中的所有项目都可以正确加载。
<TargetPlatformVersion>10.0.10069.0</TargetPlatformVersion>
但是加载后发现无法构建原生工程,报错:
error MSB8020: The build tools for v140 (Platform Toolset = 'v140') cannot be found.
尽管 vcxproj 指定 ToolsVersion="14.0"
,但似乎 Visual Studio 2013 将对 C++ 项目使用 12.0。在项目的属性中,Platform toolset
表示 v140 (not installed)
。将其更改为 Visual Studio 2013 (v120)
将允许项目在 VS2013 和 VS2015 中构建,但显然使用较旧的 12.0 工具而不是 14.0。相反,我将以下行添加到我的项目文件中:
<PlatformToolset Condition="'$(VisualStudioVersion)' == '12.0'">v120</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' >= '14.0'">v140</PlatformToolset>
现在 VS2013 将使用 v120
Platform toolset
而 VS2105(及更高版本)将使用 v140
.
使用 VS 2015 构建后,项目文件可能添加了 TargetPlatformVersion
and/or WindowsTargetPlatformVersion
行。如果值为 10.0.10240.0
或另一个 Windows 10 版本,则该项目将不会在 VS 2013 中加载,因为它不喜欢非十进制值。这可以通过将值更改为 8.1
来解决,告诉 Visual Studio 使用 Windows Kit for Windows 8.1 而不是 Windows 10.
注:
即使您可以将 .Net 4.6 与 VS2013 结合使用,它也无法理解 C# 6,因此如果您尝试使用任何新的语言功能,将会出错。同样,为 C++ 项目定位 v120
会阻止您使用 VS2015 中支持的更新的语言功能。