C#C
C#3y ago
skyslide22

✅ .csproj – how to generate nodes dynamically by iterating over a string array ?

how can i generate xml code in the .csproj file? i dont want to repeat my actions 10000 times...
so i got a list of strings i want to insert in some xml nodes:

    my-items = 
        Utils\**\*.*;
        Settings\**\*.*;
        Extensions\**\*.*;
        Components\**\*;
        Templates\**\*;
    
    foreach item in my-items
    do
    <ItemGroup>
        <None Include="@item">
          <Link>@item\%(RecursiveDir)/%(FileName)%(Extension)</Link>
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
    </ItemGroup>
    end
Was this page helpful?