Search code examples
visual-studiomsbuildvisual-studio-2019csprojsolution

Visual Studio folding solution items recursively


I am trying to fold all XAML dependents files.

<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>

I was able to fold JSs but TS definitions fail

Look at the last item with arrow

I tried to create a "temp" items collection and tried to iterate and parse paths ... no success VS didn't load the project anymore

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

I tried the same way in "another way" ... same way :(

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

Question

  • Is it possible to parse path in another way than x->%(RecursiveDir)%(FileName ?
  • Is it possible to fold items like *.dash.ext ? How ?
  • Or someone could help me achieving this ?!

NOTE

xaml.ts are auto generated and somehow auto folded


Solution

  • I think the issue is that:

    For KYCHome.xaml.d.ts file, the value of %(FileName) is KYCHome.xaml.d rather than KYCHome.xaml. So when you use it, it will not find the KYCHome.xaml file.

    So the method I can think of is to intercept the FileName, remove the .d, and then the changed value is what we need.

    Solution

    This is what I used:

    <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>
    

    Note: you should remove the .\ under DependentUpon node. Otherwise, sometimes, the DependentUpon will not work when you restart your project or unload the project.

    enter image description here