有条件改变目标框架版本

编程入门 行业动态 更新时间:2024-10-28 14:35:15
本文介绍了有条件改变目标框架版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图编译#ifdef'd代码库到两个不同的目标框架,即3.5和4.0。

I'm trying to compile an #ifdef'd codebase to two different target frameworks, namely 3.5 and 4.0.

我试图修改.proj文件该解决方案也没有用。

I attempted to modify the .proj files in the solution to no avail.

看来的MSBuild / VS2012是不是捡了通过用户界面解决方案配置的变化。

It seems MSBuild / VS2012 isn't picking up the solution configuration change via UI.

这是.proj文件中的一个片段:

This is a fragment of one of the .proj files:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>..\Binaries\</OutputPath> <DefineConstants>TRACE;NET35</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug 40|AnyCPU' "> <DebugSymbols>true</DebugSymbols> <OutputPath>..\Binaries\</OutputPath> <DefineConstants>TRACE;DEBUG;NET40</DefineConstants> <DebugType>full</DebugType> <PlatformTarget>AnyCPU</PlatformTarget> <ErrorReport>prompt</ErrorReport> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> </PropertyGroup>

当我切换到调试40,从放的目标框架并不在项目变更性能(从而打破,因为其他条件引用的程序集的编译)。

When I switch to "Debug 40" from "Release" the target framework does not change in the project properties (thus breaking the compilation because of other conditionally referenced assemblies).

我也有参考条件不同的组件,问题仿佛再次,解决方案配置ISN :T拾起VS /的MSBuild(有的甚至在参考文献中显示)

I'm also having problems conditionally referencing different assemblies, as if, again, the solution configuration isn't picked up by VS/MSBuild (some don't even show up in the references).

编辑:我从V3.5版本不包括Microsoft.CSharp使用以下行:

I'm excluding Microsoft.CSharp from the v3.5 build with the following line:

<Reference Include="Microsoft.CSharp" Condition=" '$(Configuration)' == 'Debug 40'" />

到目前为止,似乎它只是被忽略TargetFrameworkVersion属性。

So far it seems it's just the TargetFrameworkVersion property that is ignored.

推荐答案

原来,问题是双重的:

  • ReSharper的(第7版)通过显示在不同的文件编译错误,使其难以实现真正有条件引用编译的代码使事情变得更难。我认为,第7版不支持手动项目文件的变化,所以一个头高达RS7用户。
  • 编译时实际使用正确的框架VS2012不改变UI中的目标框架(尽管,为的MSBuild的详细输出看到)。

我最终设法让代码库编译有点耐心。 按@ granataCoder的建议,这也是更好地保持不同的输出路径(可能很容易像条件编译正交问题时忽略)。

I eventually managed to get the codebase to compile with a bit of patience. As per @granataCoder's suggestion, it's also better to keep different output paths (might be easy to overlook when dealing with orthogonal issues like conditional compilation).

更多推荐

有条件改变目标框架版本

本文发布于:2023-07-15 10:09:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1110590.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有条件   框架   目标   版本

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!