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.

Default items and default removes trample on item groups expressed in csproj

See original GitHub issue

Can we make DefaultItems and DefaultRemoves smarter? Current implementation tramples what the user expresses in their csproj file and requires deep understanding of internal workings of MSBuild to unwind this.

Addition of Defaultitems and DefaultRemoves makes the behavior of ItemGroups in csproj unpredictable.

For example, consider this test application:

Microsoft.DotNet.Tools.Watcher.FunctionalTests.csproj
Tests.cs
TestProjects/
     TestApp/
          TestApp.csproj
          Program.cs

In RC.2, my project defined these items:

<Compile Include="**\*.cs" Exclude="TestProjects\**\*" />
<Content Include="TestProjects\**\*" CopyToOutputDirectory="PreserveNewest" />

DefaultItems causes duplication in Compile groups, and default removes remove items I want in the Content group. To workaround this, I have to change the project to:

  <PropertyGroup>
    <DisableDefaultRemoves>true</DisableDefaultRemoves>
  </PropertyGroup>

  <ItemGroup>
    <Compile Remove="TestProjects\**\*" />

    <Compile Remove="$(DefaultRemoves)" />
    <EmbeddedResource Remove="$(DefaultRemoves)" />
    <None Remove="$(DefaultRemoves)" />
    <Content Remove="$(DefaultRemoves)" />

    <Content Include="TestProjects\**\*" CopyToOutputDirectory="PreserveNewest" />
 </ItemGroup>

This seems excessively ugly.

More details: Here’s the RC.2 project I’m having difficulty porting: https://github.com/aspnet/DotNetTools/blob/cb3c5d77ade283538af441be9792590422c789a5/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/Microsoft.DotNet.Watcher.Tools.FunctionalTests.csproj#L10

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dsplaistedcommented, Jan 11, 2017

Thanks for raising this issue @natemcmaster. I’ve sent a PR to fix it.

1reaction
rainersigwaldcommented, Jan 11, 2017

I hate to sound like a broken record here, but: I still don’t think there should be implicit globs.

That said, there’s a way to avoid this type of problem: if you’re going to do anything non-default with an item group, first make the include explicit, then do your operations on the explicit copy. In other words, excluding a directory should produce this modification to the project:

<PropertyGroup>
  <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
<ItemGroup>
  <Compile Include="**\*.cs" Exclude="TestProjects\**\*" />
</ItemGroup>

Instead of the Remove stuff above.

Of course, it’s hard to socialize a solution like this–even if we fix it in VS-driven edits.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to stop visual studio from automatically adding ...
c# - How to stop visual studio from automatically adding remove in an item group in my csproj? - Stack Overflow.
Read more >
MSBuild Items
Learn how to use the MSBuild items, item types, and work with lists of items by using and modifying item metadata.
Read more >
MSBuild + .NET Core CLI Tools: Getting information about ...
By default, MSBuildProjectExtensionsPath will be the obj/ folder next to the MSBuild project. (This step could also be named “abusing ...
Read more >
Unity 2019.1.0
Asset Import: GenerateBackFaces is now enabled by default in the Sketchup Importer. Asset Import: Removed normal calculation options in Sketchup ...
Read more >
History of Ghostscript versions 9.n
As we made "SAFER" the default mode, that became unacceptable, hence the new option -dALLOWPSTRANSPARENCY which enables access to the operators.
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