views:

74

answers:

4

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.

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.

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.

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

A: 

I think you can just create a number of configurations, and add some msbuild logic to the proj file to conditionally set a reference path property and have your references use that property. If you are familiar with editing the XML in the project file, then this will not be hard; if you are not, then... hopefully someone else will help with the details.

Brian
A: 

Visual Studio 2008 and 2008 .csproj files are XML files. Reference paths are simple strings in these XML files, if you open a .csproj with a text editor, you can check this out (look for "HintPath", or check this http://geekswithblogs.net/murraybgordon/archive/2005/10/25/58103.aspx).

What you could do is write a small program that automates the build for different reference paths. Visual Studio build can be automated using DEVENV.EXE, see http://msdn.microsoft.com/en-us/library/xee0c8y7(VS.80).aspx for more on this.

Simon Mourier
+2  A: 

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.

Then you could do something like:

<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.

Jeff M
This is the basic idea.
KeithS
A: 

Modify the HintPath Element in the Project File (as it mentioned in other answers is IMO not a very good idea because Visual Studio uses this Field to store where it should look if in all other "good" nothing was found). In our Company we have a similar Situation. We solved this Problem by setting the ReferencePath of every Project in the Solution.

Do this by hand is very annoying if you have to do it for large Solutions. Because of this we have written an AddIn for VS that will do this for us. Setting the ReferencePath of a Project is very easy so i think that this task could also be done by a VS Macro.

Here's the code to set the ReferencePath by a Marco:

    Sub SetReferencePath()
    Dim project As Project

    For Each project In DTE.Solution.Projects

        If project.Kind = CodeModelLanguageConstants.vsCMLanguageCSharp Then
            project.Properties.Item("ReferencePath").Value = "PATH1;PATH2;..."

        End If

    Next
    End Sub

The value of the ReferencePath Property is a Semicolon seperated List of Paths. Another advantage of using the ReferencePath, instead of setting the Hint Element, is that you can use absolute Paths on different Drives which is IMHO not possible with the Hint Element.

Noffls