PowerShell 모듈에서 작업하고 있으며 내 테스트 중 하나에서 경로 분석이 실제로 이상하게 작동합니다.PowerShell 경로는 사용시기에 따라 다르게 해석됩니다.
현재의 폴더 구조는 다음과 같습니다
는ISPS/
├── ISPS/
│ ├── Private/
│ ├── Public/
│ │ ├── Add-ICDCrawler.ps1
│ │ ├── Get-ICDCrawler.ps1
│ │ ├── New-ICDCrawler.ps1
│ │ └── Remove-ICDCrawler.ps1
│ ├── ISPSCrawler.psd1
│ └── ISPSCrawler.psm1
├── tests/
│ ├── Add-ICDCrawler.tests.ps1
│ ├── Get-ICDCrawler.tests.ps1
│ ├── New-ICDCrawler.tests.ps1
│ └── Remove-ICDCrawler.tests.ps1
이상한 행동있어 시험은 Remove-ICDCrawler.tests.ps1
입니다. 파일 및 관련 부분의 시작은 다음과 같습니다
$ModuleRoot = Split-Path $PSScriptRoot -Parent
. $ModuleRoot\ISPS\Public\Get-ICDCrawler.ps1
. $ModuleRoot\ISPS\Public\Remove-ICDCrawler.ps1
, 도트 소싱이 아닌 Remove-ICDCrawler
를 들어, Get-ICDCrawler
라인 올바르게 작동합니다. 다음과 같은 오류 메시지가 표시됩니다.
. : The term 'D:\Projects\ISPS\ISPS\ISPS\Public\Remove-ICDCrawler.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At D:\Projects\ISPS\tests\Remove-ICDCrawler.tests.ps1:4 char:3
+ . $ModuleRoot\ISPS\Public\Remove-ICDCrawler.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
충분히 간단합니다. 경로에 ISPS
폴더가 너무 많습니다. 테스트 라인 4에서 ISPS
폴더 중 하나를 제거하고 다시 시도하면 완벽하게 작동합니다. 문제는 Get-ICDCrawler.ps1
과 Remove-ICDCrawler.ps1
파일이 같은 디렉토리에 저장되어 있고 경로가 올바른 디렉토리로 확인되어야한다는 것입니다. 앞에서 언급했듯이 4 행의 경로에서 ISPS
을 제거하면 작동하지만 PowerShell에 대해 알고있는 모든 것에 위배됩니다. 왜 이런 일이 일어나는 지 아는 사람이 있습니까?
Name Value
---- -----
PSVersion 5.1.15063.608
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.15063.608
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1