使用 vs2010 将 C++/CLI 项目更改为 4.0 以外的其他框架 [英] Change C++/CLI project to another framework than 4.0 with vs2010

查看:22
本文介绍了使用 vs2010 将 C++/CLI 项目更改为 4.0 以外的其他框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从我将我的项目升级到 Visual Studio 2010 项目格式后,我的 C++/CLI 项目针对 .net framework 4.0.

Since I upgraded my project to visual studio 2010 project format, my C++/CLI project is targeted to .net framework 4.0.

将框架版本从 C# 项目切换到另一个版本很容易,但我不知道如何在 C++/CLI 项目中执行此操作,我在项目属性页中没有看到此设置.

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.

推荐答案

当您在框架和引用"对话框中按 F1 时会显示:

This shows up when you press F1 in the Framework and References dialog:

默认情况下,新项目的目标框架设置为.NET Framework 4.IDE 不支持修改目标框架,但您可以手动更改.在项目文件 (.vcxproj) 中,默认目标框架由 v4.0 属性元素表示.要更改目标框架,请卸载项目,使用文本编辑器打开项目文件,然后将属性元素的值从 v4.0 更改为安装在服务器上的另一个版本.例如,如果您指定代表 .NET Framework v3.5 的 v3.5,则必须安装Visual Studio 2008 SP1.保存并关闭文件,重新加载项目,并验证目标框架是否显示在属性页中.*

By default for new projects, the targeted framework is set to .NET Framework 4. The IDE does not support modifying the targeted framework, but you can change it manually. In the project file (.vcxproj), the default targeted framework is represented by the v4.0 property element. To change the targeted framework, unload the project, use a text editor to open the project file, and then change the value of the property element from v4.0 to another version that is installed on your server. For example, if you specify v3.5, which represents the .NET Framework v3.5, Visual Studio 2008 SP1 must be installed. Save and close the file, reload the project, and verify that the targeted framework is displayed in the property page.*

这在转换后的项目上不是很准确,您必须自己添加 元素.将其放入标有Globals"的 PropertyGroup:

That's not terribly accurate on converted projects, you'll have to add the <TargetFrameworkVersion> element yourself. Put it in the PropertyGroup labeled "Globals":

  <PropertyGroup Label="Globals">
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    <others...>
  </PropertyGroup>

<小时>

当您使用 VS2012 及更高版本时,情况就不同了,VS2012 是第一个在 General 属性页中获得 Platform Toolset 设置的版本.然后,您必须选择v90"以获得针对 3.5 的正确构建.然而它很笨拙,您必须在机器上安装所有中间版本的 VS 才能使用该选项.


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.

为什么需要安装 VS2008 需要自己解释.核心问题是 C 运行时库(msvcrt100.dll 及更高版本)包含支持托管代码执行的 .NET 代码.关键的细节是一个模块初始化器,它确保在使用 C++/CLI 代码的程序中正确初始化 CRT.该代码始终以 .NET 4 为目标,并且由于它被硬烘焙到 msvcrt100.dll(及更高版本)中,因此您始终对 v4.0.30319 运行时具有坚如磐石的依赖性.当您使用旧的 C 运行时 msvcrt90.dll 时,您只能拥有纯 v2.0.50727 依赖项.只有使用VS2008编译器的#include文件才能确定是否有msvcrt90.dll依赖.

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.

冷酷的事实是,很快就迁移到 .NET 4 是非常必要的,如果你不这样做,你会遇到像这样的构建问题.对此几乎没有实际障碍,.NET 4 可以在您想象的所有目标上广泛免费使用.克服与迁移到更高运行时版本相关的 FUD 通常只是真正的问题.没有恐惧和怀疑的理由,它很稳定.

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.

这篇关于使用 vs2010 将 C++/CLI 项目更改为 4.0 以外的其他框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆