dotnet / dotnet/msbuild

Proposal: add OptionalTargets property to Target

Open
#3,090 0 comments 2 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 13h
Merged PRs (30d)
133

Description

It would be useful to be able to avoid an error when a target depends on another target that does not exist.

Use case:
https://github.com/Microsoft/msbuild/blob/master/src/Tasks/Microsoft.Common.CurrentVersion.targets#L745-L749

For example, consider the following project file:

```xml


```

This would execute `T1`, `T2` and ignore `T0` that doesn't exist. If `T0` existed it would be also executed.

Currently the workaround is to define a property that's set to `true`, usually in the file that defines the optional target and then factor the target T2 so that a condition testing that property can be used to ignore the missing target.

Alternatively the same could be achieved by implementing `TargetExists(TargetName)` built-in function.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading src/Tasks/Microsoft.Common.CurrentVersion.targets around lines 745-749 and compare the proposed behavior with the existing property-based workaround. Done means a project with T2 depending on missing T0 and present T1 executes T1 and T2 without error, while an existing T0 also executes.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, xml
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.