简体   繁体   中英

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.

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM