MSBuild: Excluding objects if %(Filename) matches any in ItemGroup
Given a target:
that receives
FilesAsBundle
as the following input (abridged for simplicity):
I can remove TerraFX.Interop.Windows.dll
from the list. But I have a need to match any of several filenames. I naively define a ItemGroup
of DepsToExclude
as such:
and then attempted to amend the comparison:
and also attempted to directly Remove
from FilesToBundle
as follows:
but neither approach was successful. I'm struggling to follow how and when MSBuild expands @
to automatically cover all elements in a group. What would be the correct way to express this?1 Reply
That version looked as follows:
FilesToBundle
contains all entries at the beginning, but the Remove
s have no effect
that is inconvenient, because rooting it (with a literal) means I have to presuppose where a user might have their NuGet package cache
at some point I realized that I can refer to entries in an ItemGroup
of <DepsToExclude Include="TerraFX.Interop.Windows" />
with %(DepsToExclude.Include)
, but that performs a comparison between entry N in FilesToBundle
and DepsToExclude
respectively
when what I'd like is to compare it against all DepsToExclude
Oh there's just %(RootDir)
according to https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-well-known-item-metadata?view=vs-2022
if that helps me in any way, which I'm not certain it does
that is unfortunately not the case even on my dev machine, and God only knows about someone else's
surprisingly, that has no effect, I'm trying to step through why
oh, Filename is without extension
right
Somehow removing just those four characters (\.dll
) causes:
I'm confused by what it even means by this
Right
Good thinking
right. well, the regex works- once I expand it to cover every DLL in that list; I suppose that's a win
it is a bit more unwieldy than I originally expected it to be, but I'll take whatever I can get at this point
thank you very much
does the regex i.e. the condition
have to be on a single line? out of curiosity
honestly, just splitting up the condition across lines and having the regex be a single line all its own was enough
thanks, this was a lifesaving assist
in the course of trying one relatively simple thing I ended up learning a ton about MSBuild and .NET packaging