$(DefaultItemExcludes) in targets contains double slashes
See original GitHub issueI just stumbled on some weird behaviour trying to add generated compile files in a target:
on macOS, having only a Program.cs.template
file as an example (remove Program.cs
after each build) and a leftover assembly info file in a RID specific path in obj/
from a previous RID-specific publish:
<Target Name="GenerateSomeFiles" BeforeTargets="BeforeBuild">
<Exec Command="cp Program.cs.template Program.cs" />
<Message Importance="high" Text="DefaultItemExcludes: $(DefaultItemExcludes)" />
<Message Importance="high" Text="Exclude: $(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);@(Compile)" />
<ItemGroup>
<Compile Include="**/*$(DefaultLanguageSourceExtension)"
Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);@(Compile)" />
</ItemGroup>
<Message Importance="high" Text="Compile: @(Compile)" />
</Target>
prints:
$ dotnet build
Microsoft (R) Build Engine version 15.3.388.41745 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
DefaultItemExcludes: ;bin/Debug//**;obj/Debug//**;bin//**;obj//**;**/*.user;**/*.*proj;**/*.sln;**/*.vssscc;packages/**
Exclude: ;bin/Debug//**;obj/Debug//**;bin//**;obj//**;**/*.user;**/*.*proj;**/*.sln;**/*.vssscc;packages/**;;**/.*/**;
Compile: obj/Debug/netcoreapp2.0/osx.10.12-x64/dasmulli.sample.application.AssemblyInfo.cs;obj/Debug/netcoreapp2.0/osx.10.12-x64/sampleapp.AssemblyInfo.cs;obj/Debug/netcoreapp2.0/sampleapp.AssemblyInfo.cs;Program.cs
and then fails because an old assembly info file was included in @(Compile)
(might as well have been from switching between Debug and Release configurations).
The interesting part here is that these parts have double slashes in them:
bin/Debug//**;obj/Debug//**;bin//**;obj//**
which seem to originate from being defined like $(BaseIntermediateOutputPath)/**
.
If I add $(BaseIntermediateOutputPath)**;$(BaseOutputPath)**
to the Exclude
attribute, the directories are excluded as expected.
However, I’d expect $(DefaultItemExcludes)
to give me a safe value in all targets because the SDK should know which directories should be excluded and not require target authors to fix missing directories that only work during static evaluation. Is there anything that could be done to avoid this problem?
cc @dsplaisted
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (5 by maintainers)
Sorry I didn’t try with a recent MSBuild version, this has been fixed with MSBuild 15.5 (2.1.* CLI versions, still repros with 2.0.* CLI versions).
The issue seemed to have been a leading semicolon in the exclude patterns and not slash collapsing.
Simpler repro:
CLI 2.0.3:
CLI 2.1.3:
@dasMulli can you please give me some repro steps? I assume the problem is that the *.cs file under obj are showing up, even though they are excluded.
I tried this on macOS and it works fine: