Visual Studio递归折叠解决方案项

问题描述

我正在尝试折叠所有XAML依赖文件

<None Include=".\**\*.xaml.js">
  <copyToOutputDirectory>PreserveNewest</copyToOutputDirectory>
  <DependentUpon>.\%(RecursiveDir)%(FileName)</DependentUpon>
</None>
<None Include=".\**\*.xaml.d.ts">
  <copyToOutputDirectory>PreserveNewest</copyToOutputDirectory>
  <DependentUpon>.\%(RecursiveDir)%(FileName)</DependentUpon>
</None>

我可以折叠JS,但TS定义失败@H_502_8@

Look at the last item with arrow

我试图创建一个“临时”项目集合,并尝试迭代和解析路径……没有成功VS不再加载项目了

<ToFold Include=".\**\*.xaml" />
<None Include="@(ToFold->%(RecursiveDir)%(FileName).js')" DependentUpon="@(ToFold)">
  <copyToOutputDirectory>PreserveNewest</copyToOutputDirectory>
</None>

我以“另一种方式”尝试了相同的方式... ...:(

<ToFold Include=".\**\*.xaml" />
<None Include="@(ToFold->%(ToFold).js')" DependentUpon="@(ToFold)">
  <copyToOutputDirectory>PreserveNewest</copyToOutputDirectory>
</None>

问题

  • 是否可以使用x->%(RecursiveDir)%(FileName以外的其他方式解析路径?
  • 是否可以折叠*.dash.ext之类的物品?怎么样?
  • 或者有人可以帮助我实现这一目标?!

注意@H_502_8@

xaml.ts自动生成的,并以某种方式自动折叠

解决方法

我认为问题在于:

对于KYCHome.xaml.d.ts文件,%(FileName)的值为KYCHome.xaml.d而不是KYCHome.xaml。因此,当您使用它时,它将找不到KYCHome.xaml文件。

所以我能想到的方法是拦截FileName,删除.d,然后更改后的值就是我们所需要的。

解决方案

这是我使用的:

<ItemGroup>
        <None Include=".\**\*.xaml.js">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            <DependentUpon>%(RecursiveDir)%(FileName)</DependentUpon>
        </None>
        <None Include=".\**\*.xaml.d.ts">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>   
            <File>$([System.String]::Copy('%(Filename)').Replace('.d',''))</File>
            <DependentUpon>%(RecursiveDir)%(File)</DependentUpon>
        </None>
        
</ItemGroup>

注意:您应删除.\节点下的DependentUpon否则,有时DependentUpon在重新启动项目或卸载项目时将不起作用。

enter image description here

,

我是法国人,我认为这对我实现自己的目标是一个障碍。我是说折叠物品,但是如果我说嵌套物品,我会很快从Google那里得到答案。

Visual Studio具有嵌套项目功能

Nesting items button

我从这里Path segment pattern得到了答案,这是我在.filenesting.json解决方案文件中添加的节点

"dependentFileProviders": {
  "add": {
    "addedExtension": {},"pathSegment": {},"fileSuffixToExtension": {
      "add": {
        ".xaml.d.ts": [".xaml"]
      }
    }
  }
}

The files nested