【发布时间】:2021-08-01 12:37:42
【问题描述】:
我有这个:
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,但不确定如何使用。
【问题讨论】:
-
为什么不使用解决方案目录作为基本路径,而不是使用相对路径?
-
@CamiloTerevinto 我正在使用 dotnet core 和 vscode。没有解决方案目录 - 即没有
MyProject.sln文件。只是一个包含项目目录的目录。