dotnet / dotnet/msbuild

Add scoping and information hiding for msbuild variables (properties and items)

Open
#2,480 7 comments 17 reactions 0 assignees View on GitHub
Area: Language Feature Request needs-design User Experience
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

I'd like to start a conversation around the potential for PropertyGroups / ItemGroups that are scoped to a local target.

MSBuild scripts, written by Microsoft or not, end up using overly descriptive names for properties and items to avoid clashing with those created by other targets and introducing "undefined behavior".

The proposed feature would introduce the ability to define a property/item group as "Scope=Target". Values defined in these blocks would be added to a scope that is local to the target. Variable resolution would always prefer the target scope, if it is available.

```

```

This scope would be truly local - target dependency chains wouldn't be able to see each others' target-scoped variables.

Disclaimer: While I'm reasonably familiar with _consuming_ MSBuild as a developer, as well as the web publishing tasks developed by Microsoft, I'm not at all familiar with the MSBuild source code. There might be some very good architectural reasons why this proposal isn't possible or feasible.

Outstanding questions:
- What about file/project level? Unsupported, or additional support for Scope=Project?
- What if a target defines a globally scoped variable after already defining a target scoped variable? It might be best to destroy the locally scoped variable, as it might cause developer confusion if it continues to resolve the locally scoped value in preference to the globally scoped variable.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.