Skip to content

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

Description

@richardszalay

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.

<PropertyGroup Scope="Target">
</PropertyGroup>

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: LanguageIssues impacting the MSBuild programming language.Feature RequestUser Experienceneeds-designRequires discussion with the dev team before attempting a fix.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions