使用 vs2010 将 C++/CLI 项目更改为 4.0 以外的其他框架

发布于 2024-09-03 08:26:56 字数 153 浏览 6 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

诗化ㄋ丶相逢 2024-09-10 08:26:56

当您在“框架和引用”对话框中按 F1 时,会显示此信息:

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

这对于转换后的项目来说并不是非常准确,您必须添加 元素你自己。将其放在标记为“Globals”的 PropertyGroup 中:

  <PropertyGroup Label="Globals">
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    <others...>
  </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:

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.*

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>

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.

删除会话 2024-09-10 08:26:56

是的,即使对于托管 C++ 项目也可以更改目标:

更改目标 .NET Framework
C++/CLI (VS 2010) 更改
.NET Framework 的版本
C++/CLI 项目(VS 2010)

右键单击解决方案中的项目
资源管理器并单击卸载项目
右键单击已卸载的项目
解决方案资源管理器并选择编辑
.vcxproj 在项目 XML 中
文件定位节点 在该节点中定位
节点 (如果
找不到节点,添加它)内部
节点的文本定义目标
框架。可以是 v2.0、v3.0、v3.5
或 v4.0 保存 vcxproj 文件并关闭它
右键单击已卸载的项目
解决方案资源管理器并单击“重新加载”
项目实例
v3.5

注意:这些步骤仅适用于
Visual Studio 2010 使用新的
C++ 项目文件的格式。

MSDN 上的来源:如何:更改目标 .NET Framework

Yes it is possible to change the target even for managed C++ projects:

Changing the Target .NET Framework for
C++/CLI (VS 2010) To change the
version of the .NET Framework for
C++/CLI projects (VS 2010)

Right click on project in Solution
Explorer and click Unload project
Right click on unloaded project in
Solution Explorer and select Edit
<projectname>.vcxproj In project XML
file locate node <PropertyGroup Label="Globals"> In that node locate
node <TargetFrameworkVersion> (if the
node cannot be found, add it) Inner
text of the node defines target
framework. It can be v2.0,v3.0, v3.5
or v4.0 Save vcxproj file and close it
Right click on unloaded project in
Solution Explorer and click Reload
Project Example
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>

Note: These steps apply only for
Visual Studio 2010 as it uses new
format of C++ project files.

Source on MSDN: How to: Change the Target .NET Framework

故人爱我别走 2024-09-10 08:26:56

来自匿名用户:

(编辑,因为我是新用户,无法对此做出回应,无论谁看到此内容,请随时提交以下内容)将工具集更改为 v100 实际上会导致 VS2010 以 .NET 4.0 为目标,尽管它仍会显示为目标3.5 在项目属性中。 VS2010 确实应该对此发出警告,因为目前看来您可以使用 v100 工具集以 .NET 3.5 为目标,但实际上您不能。

by an anonymous user:

(Editing as I am a new user and cannot respond to this, whomever sees this feel free to submit the following) Changing the Toolset to v100 actually causes VS2010 to target .NET 4.0, even though it will still show up as targetting 3.5 in the project properties. VS2010 should really spit out a warning about this, because currently it appears as you though you can target .NET 3.5 with the v100 toolset, which you can't.

折戟 2024-09-10 08:26:56

在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文