Skip to content

Conversation

@GeertvanHorrik
Copy link
Contributor

Fixes #4478

On Windows, when running from PowerShell terminal, the %temp% (and other) environment variables are expanded to a short path, causing issues when installing addins (NuGet can't find the files).

This PR resolves the short to long paths in the Path.

Added unit tests and tested this myself.

Other options I considered are when parsing the config file (when expanding), but at this stage Cake is not aware whether it's a path or not, and using path conversions can lead to unwanted side effects.

@GeertvanHorrik GeertvanHorrik changed the title Add environment variable expansion on PowerShell Fix environment variable expansion resulting in short paths on PowerShell May 26, 2025
@GeertvanHorrik
Copy link
Contributor Author

Added unit tests to ensure the changes are correct (and it cannot be broken in the future).

@GeertvanHorrik GeertvanHorrik requested a review from devlead May 26, 2025 18:23
@GeertvanHorrik
Copy link
Contributor Author

@devlead anything I can do (to help) to get this merged into develop so I can start using the improved caching behavior?

Copy link
Member

@devlead devlead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After internal discussion, we're a bit hesitant to change the core Path classes to introduce new implicit behavior, especially given this is addressing a platform-specific edge case. We'd prefer to avoid altering base logic unless there's a broader need.

As an alternative, could you introduce a helper method in PathExtensions for this case? This could then be used i.e. in ScriptRunner.GetToolPath / GetToolPath.

@GeertvanHorrik
Copy link
Contributor Author

What would be a good name for such an extension method?

@devlead
Copy link
Member

devlead commented Jun 2, 2025

What would be a good name for such an extension method?

Go with ExpandShortPath

@GeertvanHorrik
Copy link
Contributor Author

PR is updated.

- Add ExpandShortPath extension methods for FilePath and DirectoryPath
- Expand short paths (e.g. PROGRA~1) to full paths for proper tool/addin location
- Apply short path expansion in ScriptProcessor for installation paths
- Add comprehensive tests for new functionality
- fixes cake-build#4478
@devlead devlead changed the title Fix environment variable expansion resulting in short paths on PowerShell GH4478: Add ExpandShortPath to resolve Windows short paths Jun 5, 2025
@devlead devlead force-pushed the pr/environment-variable-expansion branch from c5ee5b0 to 4e4013c Compare June 5, 2025 12:09
@devlead devlead enabled auto-merge June 5, 2025 12:22
Copy link
Member

@devlead devlead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@devlead devlead merged commit 1b578e1 into cake-build:develop Jun 5, 2025
15 checks passed
@devlead
Copy link
Member

devlead commented Jun 5, 2025

@GeertvanHorrik your changes have been merged, thanks for your contribution 👍

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

Successfully merging this pull request may close these issues.

Failed to install addin when running from Windows powershell.exe

2 participants