如何轻松切换参考路径的构建?路径、轻松

2023-09-03 22:57:02 作者:旧时微风拂晓城

我有一个项目,是一个软件。所以,我引用的DLL库,该软件在我的项目,所以我可以code,并通过他们的API做了一些不错的插件和扩展的软件。

I have a project that is for a piece of software. So I reference DLL libraries for that software in my project so I can code and make some nice plugins and extensions for the software via their API.

现在的问题是,该软件有多种版本:企业版,精简版,1.6版,1.7版,2.0版,等等。如果我想我的项目工作,所有这些不同的版本,我不得不重复我的项目,再点DLL引用相应的软件版本的DLL库(我现在这样做)。这实在是烦人,因为我的code基是相同的所有版本,所以当我做任何更新,我有我有一个生成的每个软件版本同步我的所有重复的项目。

The problem is that the software has many kinds of versions: Enterprise, Lite, version 1.6, version 1.7, version 2.0, etc. If I want my project to work for all these different versions, I have to duplicate my project and re-point the DLL references to the respective software version's DLL library (I am doing this now). This is really annoying because my code base is the same for all versions, so when I make any updates, I have to synchronize all my duplicated projects so I have a build for each software version.

有没有办法,我可以有一个单一的项目,但在此之前我建立,挑来构建的软件版本的方法吗?我想我在寻找一种简单的方法来更新我的项目中引用的DLL的路径。任何意见或提示将不胜AP preciated。

Is there a way that I can have a single project, but before I build, pick which software version to build for? I think I am looking for an easy way to update the paths of the DLL references in my project. Any ideas or tips would be greatly appreciated.

(我可以使用Visual Studio 2008或2010和.NET 3.5或4.0,如果这有助于)

(I can use Visual Studio 2008 or 2010 and .NET 3.5 or 4.0 if this helps)

推荐答案

我有项目工作经验非常有限文件直接,但我pretty的确认您可以添加条件,许多不同的设置。你的情况,你可以添加一个条件,无论是参考或相关 ItemGroup

I have very limited experience working with project files directly but I'm pretty sure you could add conditions to many of the different settings. In your case, you could add a condition to either a Reference or associated ItemGroup.

然后,你可以这样做:

<ItemGroup>
  <Reference Include="System" />
  <Reference Include="System.Core" />
  <Reference Include="System.Data.Linq" />
  <Reference Include="System.Xml.Linq" />
  <Reference Include="MyLibrary" Condition=" '$(ProjectVersion)'=='4' ">
    <HintPath>..\..\..\..\..\..\..\Libv4\MyLibrary.dll</HintPath>
  </Reference>
  <Reference Include="MyLibrary" Condition=" '$(ProjectVersion)'=='5' ">
    <HintPath>..\..\..\..\..\..\..\Libv5\MyLibrary.dll</HintPath>
  </Reference>
  ...
</ItemGroup>

语法可能是错误的,但这个想法是存在的。我认为这是可行的这种方式。

The syntax may be wrong but the idea is there. I believe it's doable this way.