NuGet 패키지의 install.ps1 스크립트를 디버그하는 방법
따라서 NuGet 패키지에 PowerShell 설치/제거 스크립트를 포함할 수 있습니다.시도했지만, 제 install.ps1이 작동하지 않습니다.이유를 알 수 있는 가능성이 있습니까?디버깅이나 기록 같은 거요?
갱신하다
스크립트는 Nuget 패키지 설치 프로세스의 일부로 실행됩니다.Nuget에 매우 특정적일 수 있습니다.
파티에 늦었을 수도 있지만 NuGet 특정 스크립트를 디버깅하기 위한 솔루션인 NuGet 패키지 NuGetDebugTools가 있습니다.Add-Debugger.ps1 스크립트는 간단하면서도 효과적인 디버거를 NuGet 패키지 관리자 콘솔에 추가합니다.
업데이트: 이제 스크립트가 PSGallery Add-Debugger에 있습니다.NuGetDebugTools 패키지가 더 이상 업데이트되지 않습니다.PowerShelf를 사용하거나 저장소에서 개별 스크립트를 가져옵니다.
샘플 시나리오:
Visual Studio 시작
NuGet 콘솔 및 type 명령 열기
PM> Add-Debugger [-ReadHost] PM> Set-PSBreakpoint -Command init PM> Set-PSBreakpoint -Command install
(또는 보다 구체적인 중단점 설정, 참조)help Set-PSBreakpoint
)
Visual Studio 솔루션을 열거나 이미 열려 있는 경우 Install-Package XYZ 호출
디버거 입력 대화상자가 init.ps1 및 install.ps1 호출된 모든 init.ps1에 나타납니다.
?를 디버거 입력으로 입력하고 수행할 수 있는 작업을 확인합니다.
s, StepInto Step to the next statement into functions, scripts, etc. v, StepOver Step to the next statement over functions, scripts, etc. o, StepOut Step out of the current function, script, etc. c, Continue Continue operation (also on empty input). q, Quit Stop operation and exit the debugger. ?, h Display this help message. r Display PowerShell command history. k Display call stack (Get-PSCallStack). <number> Show debug location in context of <number> lines. +<number> Set location context preference to <number> lines. <command> Invoke any PowerShell <command> and write its output.
다른 디버거 및 PowerShell 명령을 입력하고 NuGet 콘솔에서 출력을 확인합니다.
v1.4.0 - 새 스위치ReadHost
사용할 것을 표시합니다.Read-Host
기본 GUI 입력 상자 대신 입력할 수 있습니다.
PowerShell ISE를 사용하여 install.ps1을 단계적으로 처리할 수 있었던 방법은 다음과 같습니다.
PowerShell ISE를 사용하여 설치 스크립트를 실행하려면 다음 단계를 수행하십시오.Net 4로 빌드된 어셈블리 실행 사용
어느 하나
C:\Windows\시스템32\Windows PowerShell\v1.0 또는
C:\Windows\SysWOW64\Windows PowerShell\v1.0
사용 중인 PS 버전에 따라 파일이 없는 경우 파일을 만듭니다.
C:\Windows\시스템32\Windows PowerShell\v1.0 또는 C:\Windows\SysWOW64\Windows PowerShell\v1.0
사용 중인 PS 버전에 따라 다름
구성 파일이 없는 경우 해당 파일
powershell.exe.config:
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
powershell_ise.exe.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0.30319" />
</startup>
</configuration>
NuGet 패키지에 포함된 PowerShell 스크립트를 실행하려면 실행 정책을 변경해야 합니다.
설정-실행 정책 원격 서명 - 범위 프로세스
디버그할 install.ps1을 복사하고 내용을 다음과 같이 수정합니다.
매개 변수 블록 삭제
param(
[Parameter(Mandatory=$true)] [string] $installPath,
[Parameter(Mandatory=$true)] [string] $toolsPath,
[Parameter(Mandatory=$true)] $package,
[Parameter(Mandatory=$true)] $project
)
VS 호스트 프로세스 외부에서 nugget cmdlet을 사용할 수 있는 모듈 가져오기
http://community.sharpdevelop.net/blogs/mattward/NuGet/NuGetOutsideVisualStudio.zip 다운로드 bin 폴더의 내용을 다른 곳으로 추출한 다음 Package Management를 가져옵니다.Cmdlets.dll
이와 같이:
import-module "C:\dev\NuGetOutsideVisualStudio\bin\PackageManagement.Cmdlets.dll"
이제 모든 파라미터를 다음과 같이 수동으로 설정할 수 있습니다.
$toolsPath="C:\dev\demo-solution\packages\X1.Registration.DbUpdate.0.4\tools"
$installPath="C:\dev\demo-solution\packages\X1.Registration.DbUpdate.0.4"
set-project DemoSolution.Logic C:\dev\demo-solution\DemoSolution.sln
$project = Get-Project -name DemoSolution.Logic
$package 객체는 여전히 설정되지 않았지만 스크립트가 실제로 해당 매개 변수를 참조하지 않는다는 것을 발견했습니다.
참고 자료: http://community.sharpdevelop.net/blogs/mattward/archive/2011/06/12/InstallingNuGetPackagesOutsideVisualStudio.aspx
사용하다Set-PsDebug -trace 2
무슨 일이 일어나는지 보기 위해.
VS의 패키지 관리자 콘솔을 통해 스크립트를 실행합니다(https://docs.nuget.org/ndocs/tools/package-manager-console) 의 콘솔에 표시됨). 도중에 오류가 발생하는 경우 빨간색으로 표시됩니다.
또한 Write-Host를 사용하여 진단 추적 유형 정보를 동일한 콘솔에 쓸 수 있습니다.
에 전화할 수 .Start-Transcript
와 설치스수시있다니습작를할의 시작 .Stop-Transcript
과 같이 수 있습니다.설치 코드를 다음과 같이 묶을 수 있습니다.
try {
$ErrorActionPreference = 'stop' # stop on error
Start-Transcript c:\a.txt
...
}
catch {
write-host $_
}
finally {
Stop-Transcript
}
도.$ErrorActionPreference = 'inquire'
(정지 대신) 작동할 수 있습니다.하지만 지금은 시도할 기회가 없습니다.http://tasteofpowershell.blogspot.com/2008/07/handling-errors-in-powershell.html 을 참조하십시오.
언급URL : https://stackoverflow.com/questions/7031944/how-to-debug-install-ps1-script-of-nuget-package
'programing' 카테고리의 다른 글
파이썬에서 WSDL(SOAP) 웹 서비스를 사용하려면 어떻게 해야 합니까? (0) | 2023.08.11 |
---|---|
(LocalDB)에 연결할 수 없음\MSSQLlocalDB -> '사용자-PC\'에 대한 로그인 실패사용자' (0) | 2023.08.11 |
부트스트랩 경고 자동 닫기 (0) | 2023.08.11 |
최대 절전 모드에서 생성된 값 무시(데이터 병합이 DB에 없습니까?) (0) | 2023.08.11 |
Oracle에서 LOT 데이터 삭제 (0) | 2023.08.11 |