使用 vs2010 将 C++/CLI 项目更改为 4.0 以外的其他框架
由于我将项目升级为 Visual Studio 2010 项目格式,因此我的 C++/CLI 项目面向 .net Framework 4.0。
将框架版本从 C# 项目切换到另一个版本很容易,但我不知道如何在 C++/CLI 项目中执行此操作,我在项目属性页中没有看到此设置。
Since I upgraded my project to visual studio 2010 project format, my C++/CLI project is targeted to .net framework 4.0.
It is easy to switch the framework version to another version from a C# project, but I have no clue how to do this in a C++/CLI project, I see no setting for this in the project property pages.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当您在“框架和引用”对话框中按 F1 时,会显示此信息:
这对于转换后的项目来说并不是非常准确,您必须添加
元素你自己。将其放在标记为“Globals”的 PropertyGroup 中:当您使用 VS2012 及更高版本(在常规属性页中获取平台工具集设置的第一个 VS 版本)时,情况会有所不同。然后,您必须选择“v90”才能获得针对 3.5 的正确构建。然而它很笨拙,您必须在计算机上安装 VS 的所有中间版本才能使该选择可用。
为什么需要安装VS2008需要自己解释一下。核心问题是 C 运行时库(msvcrt100.dll 及更高版本)包含 .NET 代码以支持托管代码执行。关键的细节是模块初始化程序,它确保 CRT 在使用 C++/CLI 代码的程序中正确初始化。该代码始终以 .NET 4 为目标,并且由于它被硬写入 msvcrt100.dll(及更高版本)中,因此您始终对 v4.0.30319 运行时具有绝对的依赖性。当您使用旧的 C 运行时 msvcrt90.dll 时,您只能拥有纯 v2.0.50727 依赖项。只有当你使用VS2008的编译器的#include文件时才能确定你有msvcrt90.dll依赖。
冷酷的事实是,尽快迁移到 .NET 4 是非常有必要的,如果不这样做,您将面临这样的构建问题。实现这一点几乎没有什么实际障碍,.NET 4 可以在您想象的所有目标上免费广泛使用。克服与迁移到更高运行时版本相关的 FUD 通常只是真正的问题。没有理由害怕和怀疑,它是稳定的。
This shows up when you press F1 in the Framework and References dialog:
That's not terribly accurate on converted projects, you'll have to add the
<TargetFrameworkVersion>
element yourself. Put it in the PropertyGroup labeled "Globals":The story is different when you use VS2012 and up, the first version of VS that acquired the Platform Toolset setting in the General property page. You must then select "v90" to get a proper build that targets 3.5. It is however clumsy, you must have all intermediate versions of VS installed on the machine to have that selection available.
Why you need VS2008 installed requires an explanation by itself. The core issue is that the C runtime library (msvcrt100.dll and up) contains .NET code to support managed code execution. The crucial detail is a module initializer that ensures the CRT is correctly initialized in program that uses C++/CLI code. That code always targets .NET 4 and since it is hard-baked into msvcrt100.dll (and up) you always have a rock-hard dependency on the v4.0.30319 runtime. You can only ever have a pure v2.0.50727 dependency when you use the old C runtime, msvcrt90.dll. You can only be sure that you have a msvcrt90.dll dependency when you use the compiler's #include files of VS2008.
Cold hard fact that it is pretty necessary to move to .NET 4 soon, you'll struggle with build problems like this if you don't. There are very few practical obstacles to that, .NET 4 is widely available for free on all targets you'd imagine. Overcoming the FUD that is associated with moving to a higher runtime version is generally only the real issue. No reasons for fear and doubt, it is stable.
是的,即使对于托管 C++ 项目也可以更改目标:
MSDN 上的来源:如何:更改目标 .NET Framework
Yes it is possible to change the target even for managed C++ projects:
Source on MSDN: How to: Change the Target .NET Framework
来自匿名用户:
by an anonymous user:
在 VS 2010 中,如果安装了工具集,请转到项目属性 -> 配置属性 -> 常规,并将平台工具集从 v90 更改为 v100。
In VS 2010 if the toolset is installed go to project properties->config properties->general and change Platform Toolset from v90 to v100.