使用vs2010将C ++ / CLI项目更改为另一个框架4.0 [英] Change C++/CLI project to another framework than 4.0 with vs2010

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

问题描述

自从我将项目升级为visual studio 2010项目格式后,我的C ++ / CLI项目针对.net框架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时, p>

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


默认情况下,对于新项目,目标框架设置为.NET Framework 4. IDE不支持修改目标框架,手动更改它。
在项目文件(.vcxproj)中,默认的目标框架由v4.0属性元素表示。要更改目标框架,请卸载项目,使用文本编辑器打开项目文件,然后将property元素的值从v4.0更改为安装在服务器上的另一个版本。例如,如果指定v3.5(表示.NET Framework 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.*

准确的转换项目,你必须自己添加< TargetFrameworkVersion> 元素。将它放在标记为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及以上,VS的第一个版本,它在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代码以支持托管代码执行。关键的细节是模块初始化程序,确保CRT在使用C ++ / CLI代码的程序中正确初始化。该代码总是针对.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天全站免登陆