dkl*_*dkl 43 c# powershell visual-studio nuget
因此,我们可以在NuGet包中包含安装/卸载powershell脚本.我试过,但我的install.ps1不起作用.有没有可能找出原因?调试,记录,什么?
更新
请注意,该脚本是作为Nuget包安装过程的一部分执行的.它可能非常特定于Nuget.
Rom*_*min 27
也许我迟到了,但这里是调试NuGet特定脚本的解决方案,NuGet包NuGetDebugTools.它的脚本Add-Debugger.ps1为NuGet包管理器控制台添加了一个简单而有效的调试器.
示例场景:
打开NuGet控制台并输入命令
PM> Add-Debugger [-ReadHost]
PM> Set-PSBreakpoint -Command init
PM> Set-PSBreakpoint -Command install
Run Code Online (Sandbox Code Playgroud)(或设置更具体的断点,请参阅help Set-PSBreakpoint)
类型?作为调试器输入,看看你能做什么:
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.
Run Code Online (Sandbox Code Playgroud)键入其他调试器和PowerShell命令,并在NuGet控制台中观察输出
v1.4.0 - 新开关ReadHost告诉Read-Host用于输入而不是默认的GUI输入框.
这就是我使用PowerShell ISE逐步执行install.ps1的方法:
为了能够使用PowerShell ISE逐步执行安装脚本,请执行以下步骤:启用使用.Net 4构建的程序集的执行
或
C:\ Windows\System32\WindowsPowerShell\v1.0或
C:\ WINDOWS\Syswow64资料\ WindowsPowerShell\V1.0
取决于您使用的PS版本如果文件不存在则创建它们
C:\ Windows\System32\WindowsPowerShell\v1.0或C:\ Windows\SysWOW64\WindowsPowerShell\v1.0
取决于您使用的PS版本
如果配置文件没有创建它们
powershell.exe.config:
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
Run Code Online (Sandbox Code Playgroud)
powershell_ise.exe.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0.30319" />
</startup>
</configuration>
Run Code Online (Sandbox Code Playgroud)
为了能够运行NuGet包中包含的PowerShell脚本,需要更改执行策略:
Set-ExecutionPolicy RemoteSigned -Scope Process
复制要调试的install.ps1并修改其内容,如下所示:
删除参数块
param(
[Parameter(Mandatory=$true)] [string] $installPath,
[Parameter(Mandatory=$true)] [string] $toolsPath,
[Parameter(Mandatory=$true)] $package,
[Parameter(Mandatory=$true)] $project
)
Run Code Online (Sandbox Code Playgroud)
导入一个允许在VS主机进程之外使用nuget cmdlet的模块
下载http://community.sharpdevelop.net/blogs/mattward/NuGet/NuGetOutsideVisualStudio.zip 将bin文件夹的内容解压缩到某个地方,然后导入PackageManagement.Cmdlets.dll
像这样:
import-module "C:\dev\NuGetOutsideVisualStudio\bin\PackageManagement.Cmdlets.dll"
Run Code Online (Sandbox Code Playgroud)
现在您可以手动设置所有参数,如下所示:
$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
Run Code Online (Sandbox Code Playgroud)
这仍然留下$ package对象未设置,但我发现脚本并没有真正引用该参数
参考文献:http: //community.sharpdevelop.net/blogs/mattward/archive/2011/06/12/InstallingNuGetPackagesOutsideVisualStudio.aspx
| 归档时间: |
|
| 查看次数: |
9438 次 |
| 最近记录: |