面向.NET框架的特定版本的Visual Studio 2010的解决方案水平 [英] Target specific version of .NET framework at Visual Studio 2010 Solution level

查看:225
本文介绍了面向.NET框架的特定版本的Visual Studio 2010的解决方案水平的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想同时针对.NET 3.5和.NET 4.0在我的Visual Studio 2010的解决方案。

I would like to target both .NET 3.5 and .NET 4.0 in my Visual Studio 2010 solution.

我知道我可以设置&LT; TargetFrameworkVersion /&GT; 在我的项目文件,但是这需要我构建解决方案的前编辑每一个项目文件具体的.NET framework版本。斯科特·多尔曼提供了确实在他的博客文章<一招宏href="http://geekswithblogs.net/sdorman/archive/2010/04/21/visual-studio-2010-and-target-framework-version.aspx">Visual Studio 2010和目标框架版本。

I am aware that I can set the <TargetFrameworkVersion /> in my project files, however this requires me to edit every project file before building the solution for a specific .NET framework version. Scott Dorman provides a macro which does the trick on his blog post Visual Studio 2010 and Target Framework Version.

我要寻找一个全球性的解决方案,我没有改变设置在每个项目中。是否有可能在解决方案层面改变中央设置来达到同样的事情?

I am looking for a global solution where I don't have to change the setting in every project. Is it possible to change a central setting at the solution level to achieve the same thing?

推荐答案

由于乔恩斯基特写道,没有定义目标架构的解决方案级别明显的方法。然而,这可以通过将特定的配置的溶液中,然后编辑 *。的csproj来完成手动文件指定为每个配置的目标,而全球范围内为整个项目。

As Jon Skeet wrote, there is no apparent way to define the target framework at the solution level. However, this can be done by adding specific configurations to the solution, then editing the *.csproj files manually to specify the targets for every configuration, rather than globally for the whole project.

下面是一步一步的指导:

Here is a step-by-step guide:

  1. 选择的构建 - 配置管理器
  2. 活动解决方案配置的下拉列表中,选择的 的,并输入一个有意义的名称(例如:调试V3.5 )的基础上的任何现有设置你已经离开。
  3. 对于每一个项目文件,在编辑器中打开它(你可以在Visual Studio中做到这一点,但你必须先在它在解决方案资源管理器中右键单击并选择的卸载项目的,那么编辑xyz.csproj 的)。
  4. 找到的&LT;的PropertyGroup&GT; 匹配你刚才创建的配置(如元素调试V3.5 |值为anycpu )。
  5. 添加在XML,比如后结束&LT; / PlatformTarget&GT; 元素,在&LT; TargetFrameworkVersion&GT; &LT; TargetFrameworkProfile&GT; 需要
  6. 保存文件。
  7. 在Solution Explorer中,用命令的刷新项目的制作再次可用的项目。
  1. Select Build - Configuration Manager.
  2. In the Active solution configuration drop-down list, select and enter a meaningful name (e.g. Debug v3.5) based on whatever existing settings you already have.
  3. For each project file, open it in the editor (you can do this in Visual Studio, but you have to first right-click on it in the Solution Explorer and select Unload Project, then Edit xyz.csproj).
  4. Find the <PropertyGroup> element which matches the configuration you have just created (for instance Debug v3.5|AnyCPU).
  5. Add in the XML, for instance after the closing </PlatformTarget> element, the <TargetFrameworkVersion> and <TargetFrameworkProfile> you need.
  6. Save the file.
  7. In the Solution Explorer, use the command Reload Project to make the project available again.

下面是一个例子:

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug v3.5|AnyCPU'">
  <DebugSymbols>true</DebugSymbols>
  <OutputPath>bin\Debug v3.5\</OutputPath>
  <DefineConstants>DEBUG;TRACE;DOTNET35</DefineConstants>
  ...
  <DebugType>full</DebugType>
  <PlatformTarget>x86</PlatformTarget>
  <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
  <TargetFrameworkProfile>Client</TargetFrameworkProfile>
  ...
</PropertyGroup>

请注意,我也定义符号 DOTNET35 ,这让我写的框架依赖于#如果语句来源$ C ​​$ C。我有,例如,几件code这依赖于 System.Tuple ,并通过添加类的简约版本,我可以回港我。 NET 4.0应用到.NET 3.5。

Note that I also define the symbol DOTNET35, which allows me to write framework dependent #if statements in the source code. I had, for instance, a few pieces of code which relied on System.Tuple and by adding a minimalistic version of the class, I could back-port my .NET 4.0 application to .NET 3.5.

下面是我的代码段:

#if DOTNET35
namespace System
{
    public class Tuple<T1, T2>
    {
        public Tuple(T1 item1, T2 item2)
        {
            this.item1 = item1;
            this.item2 = item2;
        }

        public T1 Item1
        {
            get
            {
                return this.item1;
            }
        }

        public T2 Item2
        {
            get
            {
                return this.item2;
            }
        }

        private readonly T1 item1;
        private readonly T2 item2;
    }
}
#endif

这篇关于面向.NET框架的特定版本的Visual Studio 2010的解决方案水平的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆