dotnet / dotnet/msbuild

MSB4096 seems too strict: A Include="@(B)" C="%(D)" requires all existing A to have metadata D

Open
#5,707 2 comments 1 reaction 0 assignees View on GitHub
Area: Language bug needs-design triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 13h
Merged PRs (30d)
133

Description

### Issue Description

I think I'm getting `MSB4096` in this situation even though in this context, it isn't a problem. Repro `build.proj` that gets `MSB4096`:

```xml







```

MSB4096's message is actionable and the workaround is easy, but it doesn't seem necessary based on my understanding of MSBuild, and I want to make sure I'm not missing some situation where the `Version` metadata actually has the potential to get replaced in a way I don't expect.

(I expect to be called out on this in a code review: my diff changes `ExactVersion` to `Other.ExactVersion` for no obvious reason. 😄 My PR goes from not having any pre-existing `PackageReference`s to adding `Foo`, causing `MSB4096`. Then I have to replace `ExactVersion` with `Other.ExactVersion` to fix that--this ends up being spooky action at a distance, and hard to review.)

### Steps to Reproduce

With above repro project:

```
$ dotnet msbuild /bl
```

### Expected Behavior

Success

### Actual Behavior

```
error MSB4096: The item "Foo" in item list "PackageReference" does not define a value for
metadata "ExactVersion". In order to use this metadata, either qualify it by specifying
%(PackageReference.ExactVersion), or ensure that all items in this list define a value for
this metadata.
```

### Workaround

Replace the last item list line with ``.

### Versions & Configurations

```
$ dotnet msbuild /version
Microsoft (R) Build Engine version 16.7.0-preview-20360-03+188921e2f for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

16.7.0.36003
```

### Attach a binlog

[metadata-must-exist-even-if-unused.zip](https://github.com/dotnet/msbuild/files/5170331/metadata-must-exist-even-if-unused.zip)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the build.proj repro in the issue and run dotnet msbuild /bl to observe MSB4096. Investigate the metadata expansion behavior for PackageReference Include="@(Other)" and determine whether the unqualified metadata should be accepted; done means the repro succeeds without requiring %(Other.ExactVersion).

Written by the indexing model from the issue text.

Assessment

Tech stack
xml
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.