powershell - NuGet init.ps1 执行两次

标签 powershell nuget

我按照在“Create a NuGet package that shows update notifications”找到的解决方案来获取 nuget 包更新的通知。

但是 init.ps1 脚本执行了两次。

我剥离了所有代码,因此只有以下内容在 init.ps1 中。

param($installPath, $toolsPath, $package, $project)
if ($project -eq $null) {
$project = Get-Project
}

Write-Host "Hello, I'm running inside of init.ps1" 

当我关闭并重新打开解决方案时,输出窗口中的文本出现了两次。

duplicate init execution

我正在使用 VS 2012,NuGet 2.2.31210

我检查了 packages.config 文件,我的包只有一个条目。

为什么它运行两次,有什么办法让它只运行一次吗?

谢谢, 乔

最佳答案

在 init.ps1 脚本中,Get-Project 将返回解决方案中的一个随机项目,而不是已安装包的特定项目。

使用 $projects = Get-Project -All 获取解决方案中的项目列表,遍历项目并搜索 packages.config 以检查当前项目是否安装了包。

关于powershell - NuGet init.ps1 执行两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14669518/

相关文章:

visual-studio - 使用自动包还原使用包含 msbuild 目标的 nuget 包

azure - VSO 和 Azure 中的持续集成和 NuGet 恢复

windows - 使用 Powershell 计算文件夹

Powershell:传递 `Read-Host` 作为 HashTable 的键

windows - Powershell Open可执行文件,带有Program Files\WindowsApps内部的“开始”进程-拒绝访问

c# - Jenkins 未使用新的 MSBuild 恢复目标恢复 NuGet 包

powershell - 如何使用 PowerShell 拆分文本文件?

powershell - 如何使 powershell cmdlet 静音?

nuget - 摘要和描述的最大长度是多少?

c# - Nuget 包未在 Visual Studio 中更新