如何在 Visual Studio 中找到包含文件的路径链?

How to find the path chain of an included file in Visual Studio?

假设我有这些 .targets 个文件:

这是它们的内容:

Base.targets

<Project>

  <ItemGroup>
    <None Include="C:\Base\Database\Optimize.sql">
      <Link>Database\Optimize.sql</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

</Project>

Api.targets

<Project>

  <ItemGroup>
    <None Include="C:\Api\Database\Api.sql">
      <Link>Database\Api.js</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

  <Import Project="C:\Base\Base.targets" />

</Project>

游戏Api.targets

<Project>

  <ItemGroup>
    <None Include="C:\GameApi\Database\GameApi.sql">
      <Link>Database\GameApi.js</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

  <Import Project="C:\Api\Api.targets" />

</Project>

事实上,我们有一个包含 .targets 个文件的简单链。现在,当我在项目中导入 GameApi.targets 时,我看到文件被添加为该项目的链接。

如果我想知道每个文件的包含来源,我需要手动打开每个目标文件并找出包含该文件的行。

对于 .targets 文件的大型层次结构,它变得不可能并且非常乏味。

我们有工具可以向我们展示吗?

If I want to know the inclusion source of each file, I need to manually open each targets file and find out the line where that file is being included.For a large hierarchy of .targets files it become impossible and very tedious.

尝试创建一个自定义目标来显示项目文件的路径,您可以尝试这些:

解决方案

1) 将这些添加到项目的 xxx.csproj 文件中:

<Target Name="Show_Path" AfterTargets="Build">
        <Message Importance="high" Text="$([System.IO.Path]::GetFullPath('%(None.Identity)'))"></Message>
</Target>

如果你想看到Content节点或Compile节点等等,你也可以添加它们:

 <Target Name="Show_Path" AfterTargets="Build">

    <Message Importance="high" Text="$([System.IO.Path]::GetFullPath('%(None.Identity)'))"></Message>
    <Message Importance="high" Text="$([System.IO.Path]::GetFullPath('%(Content.Identity)'))"></Message>
    <Message Importance="high" Text="$([System.IO.Path]::GetFullPath('%(Compile.Identity)'))"></Message>         

 </Target>

然后,你可以构建你的项目,之后它会在输出中列出 window.

效果如下: