dotnet / dotnet/msbuild

[Feature Request]: Import with content body (inline import)

Open
#8,633 24 comments 1 reaction 0 assignees View on GitHub
backlog Feature Request triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 13h
Merged PRs (30d)
133

Description

### Updated Summary
See the full details below. The updated idea is to have `Import` include child elements that would be treated like they were part of a `` in a separate file. In that way, you can do inline importing of content, such as targets/properties/etc. This solution satisfies the scenario mentioned in the original feature request.

#### Updated Proposal
In *Directory.Build.targets*:
```xml





$(Platform)/
@(SbomOutput)
$(SBOMFileDestPath)


```

# Original Feature Request

### Summary

The idea is to create a `TargetGroup` element. This element would only be able to hold `Target` elements. The primary purpose of this element is to allow a `Condition` attribute to be defined on the `TargetGroup`. This would allow for conditional definition of targets at evaluation-time.

### Background and Motivation

Currently, the only way to conditionally define a `Target` is to put it into its own *.targets* file and then conditionally `Import` the *.targets* file. In the example below, the override for the `GetVsixPrimaryOutputs` target will only be defined if `IsVsixProject` is set to `true`.

#### Example
In *Directory.Build.targets*:
```xml

```
In *OverrideGetVsixPrimaryOutputs.targets*:
```xml





$(Platform)/
@(SbomOutput)
$(SBOMFileDestPath)


```

### Proposed Feature

Using a `TargetGroup`, you can set the condition directly on the `TargetGroup` and do not need to define the `Target` in a separate file. Based on the example above, the proposal would look like the concept below.

#### Proposal
In *Directory.Build.targets*:
```xml





$(Platform)/
@(SbomOutput)
$(SBOMFileDestPath)


```

### Alternative Designs

Some other ideas for `TargetGroup` include:
- Allowing a way to combine the element name `Target` and the `Name` attribute for a target within a `TargetGroup`
- In a `TargetGroup`, instead of ``, you could have ``.
- Allowing the use of target sequencing modifiers (`BeforeTargets`, `AfterTargets`, `DependsOn`) to be used on a `TargetGroup`

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.