How to easily switch reference paths for an assembly?

I have a project designed for a piece of software. Therefore, I refer to the DLLs for this software in my project so that I can code and create some plugins and extensions for the software through 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 reassign the DLL links to the corresponding software version DLL (I am doing it now). This is very annoying because my code base is the same for all versions, so when I make any updates, I have to synchronize all my duplicate projects, so I have an assembly for each version of the software.

Is there a way that I can have one project, but before I build it, select the version of software to build? I think I'm looking for an easy way to update the paths of DLL links in my project. Any ideas or advice would be greatly appreciated.

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

+3
source share
4 answers

I have very limited experience working with project files directly, but I'm sure you could add conditions for many different settings. In your case, you can add the condition either to Referenceor to the corresponding one ItemGroup.

Then you can 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>

, . , .

+8

HintPath ( , IMO , Visual Studio , , "" ), . , ReferencePath .

, . - AddIn VS, . ReferencePath , , VS.

ReferencePath 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

ReferencePath . ReferencePath Hint , , IMHO .

+2

, msbuild proj, , . XML , ; , ... , - .

0

Visual Studio 2008 2008. .csproj - XML. XML , .csproj , ( "HintPath" http://geekswithblogs.net/murraybgordon/archive/2005/10/25/58103.aspx).

, , . Visual Studio DEVENV.EXE, . http://msdn.microsoft.com/en-us/library/xee0c8y7(VS.80).aspx .

0

Source: https://habr.com/ru/post/1766290/


All Articles