[Feature Request]: Common Task for Creating and Modifying URIs (BuildUri)
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 133
Description
### Summary
A common task that can create and modify collections of URIs.
This issue is replacing the "[Proposed 'BuildUri' Common Task](https://github.com/dotnet/msbuild/discussions/7440)" discussion.
A PR will be added to this issue with a proposed implementation. [**Update**: PR is #8614]
### Background and Motivation
There is an existing [`FormatUrl`](https://learn.microsoft.com/en-us/visualstudio/msbuild/formaturl-task?view=vs-2022) task that can accept and output a string. `FormatUrl` is a specialized task that was written for a specific use case. It canonicalizes a URL and will replace 'localhost' with the current machine name. Replacing 'localhost' can easily be counter-productive for many scenarios including creating a test configuration that is meant to be distributed to multiple hosts and run locally.
`FormatUrl` doesn't support general construction and modification of URIs and there isn't other support currently provided in MSBuild.
A project that needs to generate or manipulate a URI may use string functions, a custom task, or an external script or tool. All three of these approaches can be flawed if the code used doesn't correctly understand URIs.
### Proposed Feature
The `BuildUri` task wraps the [`UriBuilder`](https://learn.microsoft.com/en-us/dotnet/api/system.uribuilder?view=net-7.0) class and operates on Item collections. Providing useful access to the `UriBuilder` class is new[^1]. Providing for Item collections makes the task very flexible.
`BuildUri` has an optional input parameter for an ItemGroup of URIs (`InputUri`), a set of optional input parameters that map to the properties of `UriBuilder`, and an output parameter for an ItemGroup of URIs (`OutputUri`).
For an empty set of `InputUri`, the other input parameters are used to create a new URI.
For a set of 1 or more `InputUri`, the other input parameters are applied to each member of the set, e.g. a set of http URIs can be changed to used https.
For the `OutputUri`, each item is set with custom metadata that reflects the properties of the `UriBuilder` class. A set of URIs could be passed through the `BuildUri` task to add the metadata and the results could then be task or target batched by the added metadata, e.g. the collection could be batched by `UriScheme`.
Creating a URI might look like the following:
```xml
```
Creating URIs for a set of hosts might look like the following:
```xml
```
[^1]: `System.UriBuilder` is a supported type for [static property functions](https://learn.microsoft.com/en-us/visualstudio/msbuild/property-functions?view=vs-2022#static-property-functions) but doesn't have any public static members.
### Alternative Designs
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.