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

标签 .net visual-studio-2010 visual-studio .net-4.0 c++-cli

自从我将项目升级到 Visual Studio 2010 项目格式后,我的 C++/CLI 项目就面向 .net Framework 4.0。

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

最佳答案

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

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 中:

  <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 通常只是真正的问题。没有理由害怕和怀疑,它是稳定的。

关于.net - 使用 vs2010 将 C++/CLI 项目更改为 4.0 以外的其他框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2921702/

相关文章:

c# - 每次运行后 20 分钟运行线程

visual-studio - 如何阻止数据库项目的构建

c++ - Visual Studio C++连接MYSQL服务器

c# - 从 Visual Studio 扩展生成代码

c# - 常量修改编译报错

c# - "' 表格1 ' already defines a member called ' .ctor ' with the same parameter types "

c# - 在 Web API 2 的自定义绑定(bind)器中使用默认 IModelBinder

.net - WinInet 如何确定缓存什么以及何时缓存?

visual-studio - 将包参数传递给执行包任务

c - RegCreateKeyEx() 和 GetLastError()