Skip to content

Log item self-expansion #8581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 14, 2023
Merged

Conversation

JanKrivanek
Copy link
Member

@JanKrivanek JanKrivanek commented Mar 21, 2023

Fixes #8527

Context

Self referencing item metadata in an item definition within the target leads to possible unintended expansion (and cross-applying of pre-existing item instances).

This behavior is not a bug - it's the implication of the target batching feature - but might be confusing. So detection and warning is added here

Changes Made

A self reference (qualified or unqualified) of metadata within the item defeiniton (which is within a target) is detected and high importance message is issued.

Testing

Tests added for a warning case and for a non-warning case (self-referencing metadata outside of target context)

Doc

https://github.com/MicrosoftDocs/visualstudio-docs-pr/pull/11034

Possible impact

It's unfortunately hard to obtain data on prevalence of this pattern due to limitations of available code searches (github search doesn't support '@' sign and no escaping option; SourceGraph, grep.app doesn't support regex lookaheads). So I cannot quantify (I'll try again later on).
But there are some sparse evidence of usage:

all of those seem to be doing something else then intended (the variable part of path is empty, so it gets just the base directory), but they do not break.

tl;dr;: unless we are able to better quantify, we might resort to demote the warning to a message Demoted to Message severity

@JanKrivanek JanKrivanek changed the title Proto/item expansion warn Issue warning on item self-expansion Mar 21, 2023
@rainersigwald rainersigwald added this to the VS 17.7 milestone Mar 28, 2023
Copy link
Contributor

@Forgind Forgind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should work. I wasn't actually aware of how confusing the self-referential behavior is before you brought it up, so I appreciate it!

For the cases when people are using this in the wild, were they using it intentionally, or were they broken and just confused?

@@ -26,7 +26,7 @@ namespace Microsoft.Build.Evaluation
/// ProjectMetadataElement, and these can be added, removed, and modified.
/// </remarks>
[DebuggerDisplay("{_itemType} #Metadata={MetadataCount}")]
public class ProjectItemDefinition : IKeyed, IMetadataTable, IItemDefinition<ProjectMetadata>, IProjectMetadataParent
public class ProjectItemDefinition : IKeyed, IMetadataTable, IItemDefinition<ProjectMetadata>, IProjectMetadataParent, IItemMetadata
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems weird for a "ProjectItemDefinition" to be an "IItemMetadata"...it's possible some restructruing would help clarify that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if I misunderstood here. I renamed the interface for clarity (IItemMetadata -> IItemTypeDefinition) - hope this is adressing the concern.

@JanKrivanek JanKrivanek added the Feature: Warning Waves Warnings to enable in opt-in waves. Formerly "strict mode". label Apr 3, 2023
@JanKrivanek JanKrivanek changed the title Issue warning on item self-expansion Log item self-expansion Apr 4, 2023
@JanKrivanek JanKrivanek requested a review from Forgind April 4, 2023 12:48
Copy link
Contributor

@Forgind Forgind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@JanKrivanek JanKrivanek added the merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now. label Apr 12, 2023
@JaynieBai JaynieBai merged commit cc55017 into dotnet:main Apr 14, 2023
JaynieBai pushed a commit that referenced this pull request Apr 23, 2023
…ation (#8599)

Fixes #8579

Context
MetadataElement of an ItemElement doesn't have line&col of Location set despite those are created from known xml.
This way errors referencing the Location from metadata would end up pointing to location (0, 0) in the file.

Reason
This happens only to XmlElementWithLocation (as opposed to XmlAttributeWithLocation) during creating XmlElementWithLocation from scratch (during parsing phase that doesn't have the reader with locations already available) from an existing XmlAttributeWithLocation (that has the proper location intitialized from Load phase). Due to the need to keep the constructors contract (we override existing XmlElement), we cannot pass the additional info in the constructor.

Changes Made
Making the Location property of XmlElementWithLocation writable - so that it can be properly rewritten if constructed from an existing node with available location info.

Testing
Hand testing plus applying the changfe to the other PR: #8581, solved the issue with (0, 0) warnings location

Note
This or #8581 PR (whichever is merged later) should remove the workaround https://github.com/dotnet/msbuild/pull/8581/files#diff-e289ba4ce7fa0e72cf63049cce595eafcad1e7b2034ccb3305cd0f06c2f822b8R196-R197
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: Warning Waves Warnings to enable in opt-in waves. Formerly "strict mode". merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Cannot merge folders with wildcards
4 participants