gpt4 book ai didi

powershell - 从 PowerShell 脚本将工作流事件添加到工具箱时遇到问题

转载 作者:行者123 更新时间:2023-12-03 00:20:50 25 4
gpt4 key购买 nike

我正在创建一个可以将 System.Activities 工作流事件添加到工具箱的 PowerShell 脚本(用于 NuGet)。

目前我正在使用编写为 cmdlet 的 C# 代码安装它们,但是当您尝试卸载包时这会导致问题,因为 NuGet 已加载程序集并且无法删除它。

我的目标是通过 PowerShell 完成所有操作,因此我不必加载程序集。我非常接近,除了我添加工具箱项目的最后一行被“对象必须实现 IConvertible”。这让我相信它认为我传递给它的东西是错误的类型。我确实知道 $toolbox 接口(interface)正在工作,因为它确实向工具箱添加了一个选项卡。

function AddActivity ( 
[string] $activity,
[string] $assemblyFullname,
[string] $name,
[string] $category,
[string] $bitmapPath)
{
Write-Host "Argument List"
Write-Host $activity
Write-Host $assemblyFullname
Write-Host $name
Write-Host $category
Write-Host $bitmapPath

Write-Host "Loading assemblies"
$assembly = [Reflection.Assembly]::Load("Microsoft.VisualStudio.Shell.Interop")

Write-Host "get the toolbox service"
Write-Host "get the toolbox service"
$ServiceType = [System.Type]::GetType("Microsoft.VisualStudio.Shell.Interop.SVsToolbox,{0}" -f $assembly.FullName)
$InterfaceType = [System.Type]::GetType("Microsoft.VisualStudio.Shell.Interop.IVsToolbox,{0}" -f $assembly.FullName)
$toolbox = Get-VSService $ServiceType $InterfaceType

Write-Host "Add a Tab"
$tlBoxTab = $toolbox.AddTab($category)

Write-Host "Create the DataObject"
$dataObject = New-Object Microsoft.VisualStudio.Shell.OleDataObject
$dataObject.SetData("AssemblyName", $assemblyFullname)
$dataObject.SetData("CF_WORKFLOW_4", $name)
$dataObject.SetData("WorkflowItemTypeNameFormat", ('{0}{1}' -f $activity, $assemblyFullname))

Write-Host "Load the bitmap {0}" $bitmapPath
Write-Host "$bitmapPath"
$bitmap = new-object System.Drawing.Bitmap $bitmapPath

$toolboxItemInfo = new-object Microsoft.VisualStudio.Shell.Interop.TBXITEMINFO;
$toolboxItemInfo.bstrText = $name
$toolboxItemInfo.hBmp = $bitmap.GetHbitmap()
$toolboxItemInfo.clrTransparent = [System.UInt32][System.Drawing.ColorTranslator]::ToWin32([System.Drawing.Color]::White)

#Create an array with one element
$tbiArray = [Microsoft.VisualStudio.Shell.Interop.TBXITEMINFO[]] ($toolboxItemInfo)

Write-Host "Add the item - this will blow up"
$toolbox.AddItem($dataObject, $tbiArray, $category)

# Exception calling "AddItem" with "3" argument(s): "Exception calling "InvokeMethod" with "3" argument(s): "Object must implement IConvertible.""
# At C:\users\rojacobs\documents\visual studio 2010\Projects\WorkflowConsoleApplication24\packages\Microsoft.Activities.1.8.4.630\tools\install.ps1:53 char:21
# + $toolbox.AddItem <<<< ($dataObject, $tbiArray, $category)
# + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
# + FullyQualifiedErrorId : ScriptMethodRuntimeException
}

最佳答案

罗恩,我相信问题可能与类别有关。根据我查看的文档,类别需要是可以恢复的本地化名称(http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivstoolbox.additem.aspx)使用 GetIDOfTab (http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivstoolbox3.getidoftab.aspx)。

让我知道这是否有帮助。

关于powershell - 从 PowerShell 脚本将工作流事件添加到工具箱时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6554268/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com