Question:
Why isn’t the function [System.IO.Path]::Combine
taking my first parameter?
1 2 3 4 5 6 7 8 9 10 11 12 13 |
PS C:\WINDOWS\system32> $g_basePath F:\Dev\OneClickTools PS C:\WINDOWS\system32> [Tests.Utils]::CUSTOMASSEMBLY_TEST CustomLogic.dll PS C:\WINDOWS\system32> [System.IO.Path]::Combine($g_basePath, "\bin\debug", [Tests.Utils]::CUSTOMASSEMBLY_TEST) \bin\debug\CustomLogic.dll |
The third command shows that only the second and third parameters were concatenated or is it using an empty string as $g_basePath
..?
Answer:
Just omit the leading backslash on your second path:
1 2 |
[System.IO.Path]::Combine($g_basePath, "bin\debug", [Tests.Utils]::CUSTOMASSEMBLY_TEST) |
A pure PowerShell attempt would be to use the Join-path cmdlet twice:
1 2 |
Join-Path $g_basePath 'bin\debug' | Join-path -ChildPath [Tests.Utils]::CUSTOMASSEMBLY_TEST |