dotnet / dotnet/msbuild

`Exec` Task should allow for specifying arguments as an array instead of the full string

Open
#12,855 0 comments 3 reactions 1 assignee Assigned to @Copilot View on GitHub
Area: Tasks User Experience
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

### Summary

It's common to build up a command invocation in an Item list and then emit it as a string with a gesture like `"@(Args, ' ')`. This does create a string, but it often fails to do shell-specific escaping when the argument is emitted.

We should make this easier by allowing the Exec task to accept command argument lists, and the Exec Task should handle creating the full invocation, escaping the incoming arguments as necessary.

### Background and Motivation

[This kind of thing](https://github.com/dotnet/aspire/pull/13213/commits/dbea8e720756bcb25a20d45ba4e2f29ba15ace67#diff-34d05781acf4753dde299047c5fdc25edacfeba4503dc47dec896092bef141c9R141) means that you have to push arg-escaping into each individual argument. It sucks and is a pit of failure.

### Proposed Feature

`Exec` could grow a new `CommandArguments` `string[]` property that, when set, is appended to the generated script file that `Exec` uses. Each token in the `CommandArguments` could be checked to see if it contains spaces or other shell-relevant characters and escaped correctly as it is appended to the final generated script.

### Alternative Designs

_No response_

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.