Rod Johnson
Rod Johnson

Reputation: 2427

Conditional Reference Paths Based on Solution

I have a set of solutions that are organized like this...

Master Solution
   - Proj A          
   - Proj B
   - Proj X
   - Proj Y

SolutionAB
   - Proj A
   - Proj B

SolutionXY
   - Proj X
   - Proj Y

Dependencies

Proj A & B => Proj X & Y

What i need is to have MasterSolution look at local project references, and SolutionAB look at a totally arbritrary location for the same dlls. I can make any changes I need to the .proj files, but am limited in my ability to move projects around. These are just the limitations I have to work with.

Upvotes: 1

Views: 1040

Answers (2)

Brian Kretzler
Brian Kretzler

Reputation: 9938

You can do this with imported property files. Since references are in the project file, you can move them, or move properties used by them, to a separate .props file.

In separate .props file

<PropertyGroup>
  <SomeAssemblyFolder
    Condition="'$(SolutionName)' == 'Master'">PathTo/Master</SomeAssemblyFolder>
  <SomeAssemblyFolder
    Condition="'$(SolutionName)' == 'AB'">PathTo/AB</SomeAssemblyFolder>
</PropertyGroup>

In the project files

<Reference Include="SomeAssembly">
  <HintPath>$(SomeAssemblyFolder)\SomeAssembly.dll</HintPath>
</Reference>

I guess you could just duplicate the property definition in every project file if you wanted, but I'd move it to an import. If you need to build from the command line, or from other solution files remember to supply a reasonable default, or supply a discriminating property on the command line.

Upvotes: 3

NerdFury
NerdFury

Reputation: 19214

Library references are stored in the project files. Since the projects are shared between the solutions, I don't think there is a simple way to do this.

Any reason the projects can't always look in the arbitrary location for the files?

Upvotes: 0

Related Questions