Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Allow response files to resolve the environment variables. #2482

Open
moh-hassan opened this issue Aug 30, 2024 · 4 comments

Comments

@moh-hassan
Copy link

When using environment variables in command line, OS resolve these environment variables.
Example:

# Windows 
--token %token%

# Linux
--token $token

When trying to use the response file, the Environment Variables are not resolved and used as is.
Currently, System.Command enables the use of the [env:key=value] directive, allowing environment variables to be set from the command line during invocation.
Also, it support of resolving nesting response files for tokens prefixed by @.

It is nice if System.Command-line-api can support resolving the Environment Variables in response file based on OS .

@KalleOlaviNiemitalo
Copy link

KalleOlaviNiemitalo commented Aug 30, 2024

Prior art

MSBuild supports environment variables in its response files, ever since the initial public commit. It uses Environment.ExpandEnvironmentVariables, which recognizes the %token% syntax on all operating systems.

In addition, MSBuild expands %MSBuildThisFileDirectory% to the path of the directory that contains the response file. That came from dotnet/msbuild#4499.

@moh-hassan
Copy link
Author

moh-hassan commented Aug 30, 2024

@KalleOlaviNiemitalo
This feature is not related to msbuild

i try to use the response file in cli tool using System.Command-line-api like

mycli -a name1 @token.rsp

token.rsp is like

-t %token% --account xyz

but %token% is not resolved and used as is

That is why i request this feature

If you reviewed the source code you will find no resolve for the environment variables at all.
Regex can be used for resolving the environment variables by modifying the method static IEnumerable SplitLine(string line)

@KalleOlaviNiemitalo
Copy link

@moh-hassan, I understand System.CommandLine does not have this feature yet. I wanted to show how the similar feature in MSBuild works, so that the new feature in System.CommandLine can be made compatible with that.

@moh-hassan
Copy link
Author

I can provide PR for this feature if it is accepted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants