[英]Is it possible to conditionally compile to .NET Framework version?
[英]Conditionally changing target framework version
我正在尝试将#ifdef的代码库编译为两个不同的目标框架,即3.5和4.0。
我试图修改解决方案中的.proj文件无济于事。
似乎MSBuild / VS2012没有通过UI获取解决方案配置更改。
这是.proj文件之一的片段:
<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>
当我从“Release”切换到“Debug 40”时,目标框架在项目属性中不会改变(因此由于其他有条件引用的程序集而破坏了编译)。
我也有问题有条件地引用不同的程序集,好像,再次,VS / MSBuild没有获取解决方案配置(有些甚至没有显示在引用中)。
编辑:我使用以下行从v3.5版本中排除Microsoft.CSharp:
<Reference Include="Microsoft.CSharp" Condition=" '$(Configuration)' == 'Debug 40'" />
到目前为止,它似乎只是被忽略的TargetFrameworkVersion属性。
原来问题是双重的:
我最终设法通过一点耐心来编译代码库。 根据@granataCoder的建议,保持不同的输出路径(在处理条件编译等正交问题时可能容易忽略)也更好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.