如何使用不同的版本配置的项目不同的文件 - Visual Studio的C#.NET [英] How to use different files in a project for different build configurations - Visual Studio C# .net

查看:133
本文介绍了如何使用不同的版本配置的项目不同的文件 - Visual Studio的C#.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#.NET WinForms的解决方案,我想创建两个不同的构建:一个支持IE6和一个支持IE7。有几个在我的一个项目中的文件是不同的IE6建设与IE7的建设,所以我想包括IE6的文件时,我建立了IE6和IE7的文件时,我构建IE7。什么是构建我的解决方案针对这种情况的最好方法是什么?

I have a c# .net winforms solution and I want to create two different builds: one that supports IE6 and one that supports IE7. A few of the files in one of my projects are different for the IE6 build versus the IE7 build, so I want to include the IE6 files when I build for IE6 and the IE7 files when I build for IE7. What's the best way of structuring my solution for this situation?

由于其他方面的限制,我不希望创建一个包含共享项目一个单独的程序;我想这个项目编译成一个程序集foo.dll不管是哪个构建我做。

Due to other constraints I do not want to create a separate assembly that contains the shared items; I want the project to compile to a single assembly 'foo.dll' regardless of which build I'm making.

我想我可以只创建两个编译成foo.dll单独的项目,然后创建两个版本的配置,只包括在相关配置中的相关项目。不过我需要包括在这两个项目是相同的IE6和IE7的文件,我不能看到如何使用文件的一个副本的两个项目(当我添加现有项目它会创建一个副本项目目录)。我使用SVN源控制,因此也许可以用它来实现文件夹的共享,但怀疑这是最好的办法。

I thought I could just create two separate projects that compile to 'foo.dll', then create two Release Configurations and only include the relevant project in the relevant configuration. However I'd need to include the files that are the same for IE6 and IE7 in both projects, and I can't see how to use a single copy of a file in two projects (when I Add Existing Item it creates a copy in the project directory). I'm using SVN for source control so could perhaps use that to do the 'sharing' between folders, but doubt that's the best way..

注:不同的构建需要由于IE浏览器的API差异,其中细节无关的问题 - 只是相信我,有两个版本要求

NB: Different builds are needed due to API differences in IE, details of which aren't relevant to the question - just believe me that there are two builds required.

推荐答案

在MSBuild的,你可以指定条件的项目组。然后可以将这些条件结合到目标设备。

In MSBuild, you can specify conditions to item groups. You can then bind those conditions to the target device.

例如:

<!-- Declare the condition property at the beggining of the build file -->
<PropertyGroup Condition="$(Platform) == 'IE7'">
  <UseNewLibrary>true</UseNewLibrary>
</PropertyGroup>

<PropertyGroup Condition="$(Platform) == 'IE6'">
  <UseNewLibrary>false</UseNewLibrary>
</PropertyGroup>


<!-- Then those the property to select the right file -->
<ItemGroup Condition="$(UseNewLibrary)==true">
  <Compile Include="Class1.cs"/>
  <Compile Include="Class2.cs"/>
  <Compile Include="Class3.cs"/>
  <Compile Include="Class4.cs"/>
</ItemGroup>

<ItemGroup Condition="$(UseNewLibrary)==false">
   <Compile Include="Class1Old.cs"/>
   <Compile Include="Class2Old.cs"/>
   <Compile Include="Class3Old.cs"/>
   <Compile Include="Class4Old.cs"/>
</ItemGroup>

<!-- And now references -->
<ItemGroup Condition="$(UseNewLibrary)==true">
  <Reference Include="MyAssembly, Version=1.1.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</ItemGroup>

<ItemGroup Condition="$(UseNewLibrary)==false">
  <Reference Include="MyAssembly, Version=1.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</ItemGroup>

请注意,所有的文件将出现在IDE中,但是在编译的时候一切都应该正确对齐。

Note that all files will appear in the IDE, but at compile time everything should align correctly.

然后,所有你需要做的是在配置管理创建平台(IE6和IE7)。

Then, all you need to do is create your platforms (IE6 and IE7) in the configuration management.

您也可以直接使用,而不是创建一个中间性的平台特性。

You can also directly use the platform property instead of creating an intermediate property.

这篇关于如何使用不同的版本配置的项目不同的文件 - Visual Studio的C#.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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