question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

$(DefaultItemExcludes) in targets contains double slashes

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dasMullicommented, Jan 4, 2018

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:

<Project DefaultTargets="CreateAndPrintSomeItems">

  <Target Name="CreateAndPrintSomeItems">
    <PropertyGroup>
      <TheExcludes>;subdir//**</TheExcludes>
    </PropertyGroup>
    <ItemGroup>
      <RuntimeItem Include="**/*.txt"
               Exclude="$(TheExcludes)" />
    </ItemGroup>
    <Message Importance="high" Text="excludes used: $(TheExcludes)" />
    <Message Importance="high" Text="RuntimeItem: %(RuntimeItem.Identity)" />
  </Target>

</Project>
├── a.txt
├── subdir
│   └── b.txt
└── test.proj

CLI 2.0.3:

Microsoft (R) Build Engine version 15.4.8.50001 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  excludes used: ;subdir//**
  RuntimeItem: a.txt
  RuntimeItem: subdir/b.txt

CLI 2.1.3:

Microsoft (R) Build Engine version 15.5.179.9764 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  excludes used: ;subdir//**
  RuntimeItem: a.txt
0reactions
cdmihaicommented, Jan 4, 2018

@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:

<Project>
  <PropertyGroup>
    <Excludes>a/b//**;c//**</Excludes>
    <Excludes>;$(Excludes);;obj/Debug//**;obj//**;</Excludes>
  </PropertyGroup>

  <ItemGroup>
    <StaticItem Include="**/*.cs" Exclude="$(Excludes)"/>
  </ItemGroup>

  <Target Name="Build">
    <ItemGroup>
      <DynamicItem Include="**/*.cs" Exclude="$(Excludes)"/>
    </ItemGroup>
    <Message Importance="high" Text="StaticItem=[@(StaticItem)]"/>
    <Message Importance="high" Text="DynamicItem=[@(DynamicItem)]"/>
  </Target>
</Project>
├── a
│   └── b
│       └── ab.cs
├── build.proj
├── c
│   └── c.cs
└── obj
   └── Debug
       └── netcoreapp2.0
           └── osx.10.12-x64
               └── dasmulli.sample.application.AssemblyInfo.cs
~/dotnet/dotnet --version
2.2.0-preview1-007860

~/dotnet/dotnet build
Microsoft (R) Build Engine version 15.6.22.57775 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

 StaticItem=[]
 DynamicItem=[]

Build succeeded.
   0 Warning(s)
   0 Error(s)
Read more comments on GitHub >

github_iconTop Results From Across the Web

MSBuild ZipDirectory Task uses backslash on some ...
I have the following as part of a "Deploy" project which I run manually from a batch file using msbuild.exe (VS2017). <Target Name="ZipRelease" ......
Read more >
Build client web assets for your Razor Class Library
Learn how to integrate a build process for client web assets using tools like npm and webpack into the builds of your Razor...
Read more >
DefaultItemExcludes don't work,vs memory raise from 1GB ...
My asp.net core web application has “ClientApp” folder ,and the “node_modules” folder is in the folder of “ClientApp”,I want to ignore the ...
Read more >
[Solved]-unable to remove the slash "\" in json string in c#-C#
The slash isn't actually in the string. You're trying to remove something that doesn't exist. The debugger is just escaping the double quotes....
Read more >
ASP.NET Core - React: Failed to proxy the request to http ...
Coding example for the question ASP.NET Core - React: Failed to proxy the request to http://localhost:3000/, because the request to the proxy target...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found