2017-12-15 16 views
0

같은 디렉토리에있는 PowerShell 스크립트 Common.ps1의 일부 기능에 대해 Pester를 사용하여 Common.tests.ps1 PowerShell 테스트 스크립트를 만들었습니다. Microsoft.Xrm.Data.PowerShell 모듈을 사용하여 Dynamics CRM 인스턴스에서 레코드를 만들고 가져 오는 동일한 디렉터리에도 TestInitializer.ps1 스크립트가 있습니다. Visual Studio에서 Pester 테스트를 실행할 때 PowerShell 모듈을로드 할 수 없습니다.

비주얼 스튜디오에서 PowerShell을 테스트 스크립트를 실행

이 테스트는 메시지와 함께 테스트 탐색기에서 실패

CommandNotFoundException : 모듈 'Microsoft.Xrm.Data.PowerShell가'로드 할 수 없습니다. 자세한 내용은 'Import-Module Microsoft.Xrm.Data.PowerShell'을 실행하십시오.

PowerShell ISE에서 실행할 때와 동일한 테스트가 문제없이 실행됩니다. 이 모듈은 Visual Studio에 의해 실행되는 인스턴스 용으로 설치되지 않은 것처럼 보입니다. (Get-Module -ListAvailable을 실행할 때 이것을 확인하고 Visual Studio 테스트를 위해 Microsoft.Xrm.Data.PowerShell 모듈이 출력에 포함되지 않았 음을 확인했습니다.) : Import-Module Microsoft.Xrm.Data.PowerShell -Global -Force Visual Studio에서 스크립트를 실행하는 동안 모듈을로드하지 않는 것 같습니다.

여기 Common.test.ps1입니다 : TestInitializer.ps1에서

$here = (Split-Path -Parent $MyInvocation.MyCommand.Path) 
. $here\Common.ps1 
. $here\TestInitializer.ps1 

Describe "SelectionToSingleCharString" { 
Context "StringTransforms" { 
    It "Retrieves a CRM record and uses the optionset value to retrieve a single character" { 
    SelectionToSingleCharString($crmRecord.new_type) | Should Be "I" 
     } 
    } 
} 

발췌문 : 내가 대신로드 할 수있는 것은 아니지만, 대신에 실제로 \ 레코드를 읽을 만들려고 시도의 모의를 사용하는 테스트를 설계 할 수

# Whether or not this is uncommented does not matter 
#Import-Module "$env:SystemRoot\System32\WindowsPowerShell\v1.0\Modules\Microsoft.Xrm.Data.PowerShell\Microsoft.Xrm.Data.PowerShell.psd1" -Global -Force 


#$modules = Get-Module -ListAvailable 
#Write-Host $modules 

# Failing here 
Microsoft.Xrm.Data.PowerShell\Connect-CrmOnPremDiscovery -ServerUrl $loginServerUrl -OrganizationName $loginOrgName -Credential $cred 

외부 모듈과 Visual Studio에서 실행되는 것은 제한적입니다. 모듈에 대해서는

답변

0

디렉토리가 (당신이 실제 문제에 관심이 있다면이 건너 뛰기) 설치 :

먼저 당신이 $PSHome\Modules (%Windir%\System32\WindowsPowerShell\v1.0\Modules)에 모듈을 설치해서는 안됩니다. 이 폴더는 Windows와 함께 제공되는 모듈 용으로 예약되어 있습니다.

당신이해야 항상 모듈은 다음과 같은 경로에 사용자 만 사용 설치 :

$Home\Documents\WindowsPowerShell\Modules 

그리고 아래의 시스템 전체 설치 :

$Env:ProgramFiles\WindowsPowerShell\Modules 

PowerShell의 설치 모듈에 대한 추가 읽기 MSDN에서 찾을 수 있습니다. 당신이

를 사용하는 비주얼 어떤 스튜디오 버전 : 실제 문제에 대해서는

? VS 2017 커뮤니티 버전이 설치되어 있으며 오류를 재현 할 수 없습니다. 내 PowerShell도 64 비트 프로세스로 실행됩니다. PowerShell은 32 비트 프로세스로 실행 중일 수 있습니다. 32 비트 Powershell의 경우 모듈 디렉토리가 다릅니다. 이렇게하면 왜 설치된 모듈이 Visual Studio에 나타나지 않는지 설명 할 수 있습니다.

당신의 PowerShell에서 다음 명령을 사용하여 64 비트 프로세스에서 실행중인 경우 당신은 확인할 수 : 32 비트 PowerShell 용, 모듈에 액세스 다음과 같은 경로에 설치할 필요가하려면

PS> [Environment]::Is64BitProcess 
True 

또한 :

{$Env:ProgramFiles(x86)}\WindowsPowerShell\Modules 
+0

이것은 Visual Studio 2015에 있으며, 테스트가 32 비트 프로세스에서 실행되고있는 것 같습니다. Windows PowerShell (x86) 환경에서'Install-Module Microsoft.Xrm.Data.PowerShell'을 실행하고 테스트를 다시 실행하면 성공했습니다. –