dotnet / dotnet/msbuild

[Feature Request]: Support 'Internal' Targets that cannot be invoked from outside the project

Open
#8,995 0 comments 0 reactions 0 assignees View on GitHub
Area: Language backlog Feature Request Priority:3 triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

### Summary

Writing modular encapsulated functionality in MSBuild is sometimes difficult. A given operation may require a chain of targets where the individual targets aren't standalone and are expected to be used in concert. But all targets available on a project can be invoked on the project.

If the targets on a project are thought of being like class methods, all the methods are public.

It would be useful to have support for being able to make a target 'Internal' to a project, i.e. not public.

(If this has been proposed before, I searched and failed to find the prior issue or feature request.)

### Background and Motivation

A common pattern in MSBuild is a target that defines a chain of targets and has no body, e.g.

```xml

```

Each of the targets in the chain can have error checking and `BeforeTargets`, `AfterTargets`, and/or `DependsOnTargets` attributes to ensure they all run and all run in the correct order, regardless of which target is invoked.

But it may also be desirable to prevent the `_DefineSomethingProps`, `_PrepareSomething`, `_DoSomething`, and `_FinallySomething` targets from being invoked from outside the project. The `DoSomething` target would be the exposed public 'command'.

### Proposed Feature

Introduce a new optional attribute for the `Target` element. The attribute might be named `Internal`, expect a Boolean value, and default to `false` when the attribute is not present. Existing code would not be impacted.

```xml

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.