我有一个解决方案,其中包含许多针对 .Net 4.6 的 C# 项目和一个 native 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\12.0\bin\Microsoft.Common.CurrentVersion.targets
我不确定为什么有些项目可以正确加载而其他项目不能,但是,看起来所有引用 NuGet 包的 C# 项目都失败了。
有没有办法修复这些错误并允许在 VS2013 和 VS2015 中打开解决方案和项目?
最佳答案
在尝试对项目文件进行各种更改后,我发现从 native 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(未安装)
。将其更改为 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
平台工具集
,VS2105(及更高版本)将使用 v140
。
在使用 VS 2015 构建之后,项目文件可能添加了 TargetPlatformVersion
和/或 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 中支持的更新的语言功能。
关于visual-c++ - 在 VS2013 中针对 .Net 4.6 的某些项目的项目加载失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31554131/