无法从PowerShell脚本向工具箱添加工作流活动

时间:2011-07-02 00:05:49

标签: powershell workflow-foundation-4 nuget

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

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

我的目标是从PowerShell做所有事情,所以我不必加载程序集。我非常接近,除了最后一行我添加工具箱项目爆炸“对象必须实现IConvertible”。这让我相信它认为我传递给它的东西是错误的类型..我知道$ toolbox界面正在工作,因为它确实为工具箱添加了一个标签。

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
}

1 个答案:

答案 0 :(得分:0)

罗恩,我相信这个问题可能与这个问题有关。根据文档我看了类别需要是本地化的名称(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)。

如果有帮助,请告诉我。