C
C#16mo 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
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
1 Reply
skyslide22
skyslide22OP16mo ago
i want to include some folders of the project in the build folder, like Utils/<all files&folders in all subdirectories>
<ItemGroup>
<None Include="
Utils\**\*.*;
Settings\**\*.*;
Extensions\**\*.*;
Components\**\*;
Templates\**\*;
">
<Link>%(RecursiveDir)/%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Include="
Utils\**\*.*;
Settings\**\*.*;
Extensions\**\*.*;
Components\**\*;
Templates\**\*;
">
<Link>%(RecursiveDir)/%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
is actually doing what i want, but it puts the files/folders in the root of the project, i want to have them in their parent folder such as Utils, Settings chatgpt has done it...
<ItemGroup>
<None Include="
Utils\**\*.*;
Settings\**\*.*;
Extensions\**\*.*;
Components\**\*;
Templates\**\*;
">
<Link>@(NoneWithFolders->'%(RecursiveDir)%(Filename)%(Extension)')</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Include="
Utils\**\*.*;
Settings\**\*.*;
Extensions\**\*.*;
Components\**\*;
Templates\**\*;
">
<Link>@(NoneWithFolders->'%(RecursiveDir)%(Filename)%(Extension)')</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Want results from more Discord servers?
Add your server