简体   繁体   English

基于解决方案的条件参考路径

[英]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. 我需要的是让MasterSolution查看本地项目引用,并且SolutionAB查看同一dll的完全原始位置。 I can make any changes I need to the .proj files, but am limited in my ability to move projects around. 我可以对.proj文件进行所需的任何更改,但是在移动项目时能力有限。 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. 由于引用位于项目文件中,因此您可以将它们或它们使用的属性移动到单独的.props文件中。

In separate .props file 在单独的.props文件中

<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? 是什么原因导致项目无法始终在文件的任意位置查找?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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