根据路径有条件地包含项目

我有这个:

MyProject/
  Common/
    Common.csproj
  Main/
    Libs/
      Utils/
        Utils.csproj
      Legacy/
        Legacy.csproj
    Server/
      Server.csproj
    Directory.Build.props

我希望 Main/ 中的所有项目都包含 Common 项目。

所以 Directory.Build.props 有这个:

<ItemGroup>
  <ProjectReference Include="../../Common/Common.csproj" />
</ItemGroup>

因此 Server 项目包括 Common 项目,因为它向下两层。但是 Libs/ 中的项目不能包含它,因为它向下三层。

我需要做这样的事情:

<ItemGroup>
  <ProjectReference Include="../../Common/Common.csproj" Condition="if 2 levels up is 'MyProject'"/>
  <ProjectReference Include="../../../Common/Common.csproj" Condition="if 3 levels up is 'MyProject'"/>
</ItemGroup>

我在 Condition 中放了什么?我知道我需要使用 MSBuildThisFileDirectory 但不确定如何使用。

bierlaopo 回答:根据路径有条件地包含项目

"first" bit
v
v
v     "last" bit (once set to 1,it NEVER shifts out to 0)
v     v
v     v
L G R S  Round
0 0 0 0  down (means drop "last" 3 bits.)
0 0 0 1  down
0 0 1 0  down
0 0 1 1  down
0 1 0 0  down
0 1 0 1  up (means drop last 3 bits AND add 1 to first bit  
0 1 1 0  up
0 1 1 1  up
1 0 0 0  down
1 0 0 1  down
1 0 1 0  down
1 0 1 1  down
1 1 0 0  up
1 1 0 1  up
1 1 1 0  up
1 1 1 1  up
本文链接:https://www.f2er.com/2098.html

大家都在问