i have a MsBuild.targets file which can remove all folder except some folders, in this example we exclude en-us and fa-IR:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="RemoveFolders" AfterTargets="Build">
<ItemGroup>
<RemovingFiles Include="$(OutDir)*\*.mui" Exclude="$(OutDir)en-us\*.mui;$(OutDir)fa-IR\*.mui" />
<RemovingFolders Include="@(RemovingFiles->'%(RootDir)%(Directory)')" />
</ItemGroup>
<RemoveDir Directories="@(RemovingFolders)" />
</Target>
</Project>
now i want to make this codes dynamic with a Property, for example called ExcludedLanguages, so i can exclude every folder i want:
<ExcludedLanguages>en-us;cn-zh</ExcludedLanguages>
but i dont know how to do this? i tried this codes but not working and all folders are removing.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- Comma-separated list of languages to exclude -->
<ExcludedLanguages>en-US,fa-IR</ExcludedLanguages>
</PropertyGroup>
<Target Name="RemoveFolders" AfterTargets="Build">
<ItemGroup>
<RemovingFiles Include="$(OutDir)*\*.mui" Exclude="@(ExcludedLanguages->'%(Identity)')\*.mui" />
<RemovingFolders Include="@(RemovingFiles->'%(RootDir)%(Directory)')" />
</ItemGroup>
<RemoveDir Directories="@(RemovingFolders)" />
</Target>
</Project>
Going back to your working example, the
Excludeis$(OutDir)en-us\*.mui;$(OutDir)fa-IR\*.mui.Given
en-us;cn-zhyou want a value for theExcludeof$(OutDir)en-us\*.mui;$(OutDir)cn-zh\*.mui. Put another way, for each excluded language value LANG you want to create a string of the form$(OutDir)LANG\*.mui.Building from your working example may look like the following:
(I haven't tested this code. If you find an issue leave a comment and I will address it.)