question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Environment]::CurrentDirectory is the Current Directory?

See original GitHub issue

Steps to reproduce

PS > Set-Location /
PS > (Get-Location).Path
/
PS > [Environment]::CurrentDirectory
/home/user

Expected behavior

PS > Set-Location /
PS > (Get-Location).Path
/
PS > [Environment]::CurrentDirectory
/

Actual behavior

[Environment]::CurrentDirectory shows not “Current Directory”, rather “Start Directory”

Environment data


Name                           Value
----                           -----
PSVersion                      7.1.2
PSEdition                      Core
GitCommitId                    7.1.2
OS                             Linux 5.10.15-172.current #1 SMP PREEMPT Fri Feb 12 16:35:57 UTC 2021
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
jborean93commented, Mar 6, 2021

[Environment]::CurrentDirectory refers to the process wide working directory. This is different from the PowerShell location which is specific to the Runspace the pipeling is running in. They are not designed to impact each other because:

  • There can be multiple runspaces per thread, if you are running multiple runspaces then each could be setting their own location overwiting the process wide working directory causing all sorts of race conditions
  • A PowerShell location can be more than just a filesystem path, on Windows you have registry/cert/wsman/etc so setting a location to something that isn’t a filesystem cannot translate to the current directory

In short you should always resolve your paths to the absolute path before calling any .NET functions. This will ensure that any relative directories are relative to PowerShell’s location rather than the process wide currenct directory.

1reaction
237dmitrycommented, Mar 6, 2021

I get the potential for confusion

Thank you. I thought I was misunderstood with all these online translators.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Environment.CurrentDirectory Property (System)
Gets or sets the fully qualified path of the current working directory.
Read more >
c# - Environment.CurrentDirectory vs System.IO.Directory. ...
I think this technique is appropriate for a relatively small number of readonly configuration files, with all files existing at build time. If ......
Read more >
C# - Environment.CurrentDirectory Property with Example
CurrentDirectory property is used to set and get the path of the current directory. Syntax. string Environment.CurrentDirectory. Parameter(s).
Read more >
C# Program to Get the Full Path of the Current Directory ...
In C#, Environment Class provides information about the current platform and manipulates, the current platform. It is useful for getting and ...
Read more >
Question about Environment.CurrentDirectory - Studio
HI @ushu. Yes it will work. In the Orchestrator the Current Directory is. C:\Users\Domain Name.nuget\packages\Process Name\1.0.8\lib\net45.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found