Set-Location 与 SetCurrentDirectory [英] Set-Location versus SetCurrentDirectory

查看:56
本文介绍了Set-Location 与 SetCurrentDirectory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Powershell 之间有什么区别

What is the difference in Powershell between

Set-Location "$env:ProgramFiles\My App\"

[System.IO.Directory]::SetCurrentDirectory("$env:ProgramFiles\My App\")

询问的原因是我最近有一个脚本,它使用 Add-Type -Path XXX 添加对程序集的引用.该程序集依赖于与该程序集位于同一文件夹中的多个 DLL(有些可能在运行时而不是加载时链接).

The reason for asking is that I recently had a script which used Add-Type -Path XXX to add a reference to an assembly. The assembly depended on a number of DLLs (some possibly linked at runtime not loadtime) located in the same folder as the assembly.

所以我想我会将目录更改为文件夹,以帮助程序集找到所有必要的文件.当我使用 Set-Location 更改目录时,我收到一个错误(一个特定于程序集的错误),抱怨它找不到所有的 DLL.但是使用 SetCurrentDirectory 有效.

So I thought I would change directory to the folder, to help the assembly find all the necessary files. When I changed directory using Set-Location I got an error (one that was specific to the assembly) complaining it could not find all the DLLs. Using SetCurrentDirectory worked however.

因此这两个命令似乎在做不同的事情.我本来希望它们是一样的.

Therefore the two commands seem to be doing different things. I would have expected them to be the same.

推荐答案

Set-Location 设置 PowerShell Runspace 的当前位置.PowerShell 位置可以指向任何 PowerShell 提供程序,例如 CertificateRegistryWSMan.一个进程可以有多个活动的 PowerShell Runspace 并且每个都有自己的当前位置,并且它们都可以彼此不同.

Set-Location set current location for PowerShell Runspace. PowerShell location can point to any PowerShell provider, like Certificate, Registry or WSMan. One process can have multiple active PowerShell Runspaces and each of them have their own current location, and all of them can be different from each other.

[System.IO.Directory]::SetCurrentDirectory 设置进程的当前工作目录.进程只有一个当前工作目录,它必须指向文件系统.它不能指向注册表或其他东西.

[System.IO.Directory]::SetCurrentDirectory set current working directory for process. Process have only one current working directory and it has to point to the file system. It can not point to registry or something else.

这篇关于Set-Location 与 SetCurrentDirectory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆