sdk
latest
false
重要 :
请注意,此内容已使用机器翻译进行了部分本地化。 新发布内容的本地化可能需要 1-2 周的时间才能完成。
UiPath logo, featuring letters U and I in white

开发者指南

上次更新日期 2026年3月30日

创建自定义向导

通过使用官方https://pkgs.dev.azure.com/uipath/Public.Feeds/_packaging/UiPath-Official/nuget/v3/index.json源 中的UiPath.Activities.API包,您可以在 Studio 功能区中添加自己的自定义向导。有关如何使用 API 的信息,请参阅Studio 活动 SDK

docs image

备注:

UiPath.Activities.API包必须用作自定义项目中的开发依赖项。阅读有关开发依赖性的更多信息。

构建自定义向导

以下示例显示了向导的定义,该向导在单击时会创建一个空序列:

using System.Activities;
using System.Windows;
using System.Windows.Input;
using UiPath.Studio.Activities.Api;
using UiPath.Studio.Activities.Api.Wizards;
namespace MyCustomActivityPack
{
    public static class WizardCreator
    {
        public static void CreateWizards(IWorkflowDesignApi workflowDesignApi)
        {
            CreateDemoWizard(workflowDesignApi);
        }
        private static void CreateDemoWizard(IWorkflowDesignApi workflowDesignApi)
        {
            var wizardApi = workflowDesignApi.Wizards;
            var wizardDefinition = new WizardDefinition()
            {
                // You can add other definitions here to create a dropdown.
                //ChildrenDefinitions.Add()
                Wizard = new WizardBase()
                {
                    RunWizard = RunWizard
                },
                DisplayName = "DemoWizardDisplayName",
                Shortcut = new KeyGesture(Key.F9, ModifierKeys.Control | ModifierKeys.Shift),
                IconUri = "Icons/RecordIcon",
                Tooltip = "DemoWizardTooltip"
            };
            var collection = new WizardCollection(); //Use a collection to group all of your wizards.
            collection.WizardDefinitions.Add(wizardDefinition);
            wizardApi.Register(collection);
        }
        private static Activity RunWizard()
        {
            if(MessageBox.Show("Do you want a sequence?", "This is a wizard window", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                return new System.Activities.Statements.Sequence()
                {
                    DisplayName = "The wizard generated this sequence"
                };
            }
            return null;
        }
    }
}
using System.Activities;
using System.Windows;
using System.Windows.Input;
using UiPath.Studio.Activities.Api;
using UiPath.Studio.Activities.Api.Wizards;
namespace MyCustomActivityPack
{
    public static class WizardCreator
    {
        public static void CreateWizards(IWorkflowDesignApi workflowDesignApi)
        {
            CreateDemoWizard(workflowDesignApi);
        }
        private static void CreateDemoWizard(IWorkflowDesignApi workflowDesignApi)
        {
            var wizardApi = workflowDesignApi.Wizards;
            var wizardDefinition = new WizardDefinition()
            {
                // You can add other definitions here to create a dropdown.
                //ChildrenDefinitions.Add()
                Wizard = new WizardBase()
                {
                    RunWizard = RunWizard
                },
                DisplayName = "DemoWizardDisplayName",
                Shortcut = new KeyGesture(Key.F9, ModifierKeys.Control | ModifierKeys.Shift),
                IconUri = "Icons/RecordIcon",
                Tooltip = "DemoWizardTooltip"
            };
            var collection = new WizardCollection(); //Use a collection to group all of your wizards.
            collection.WizardDefinitions.Add(wizardDefinition);
            wizardApi.Register(collection);
        }
        private static Activity RunWizard()
        {
            if(MessageBox.Show("Do you want a sequence?", "This is a wizard window", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                return new System.Activities.Statements.Sequence()
                {
                    DisplayName = "The wizard generated this sequence"
                };
            }
            return null;
        }
    }
}

使用 MinimizeBeforeRun 属性在调用 RunWizard 之前最小化 Studio,并在 RunWizard 返回时还原。

RunWizardAsync 属性应用于异步执行向导。

将项目添加到 Studio

要使向导在 Studio 功能区可见,您需要将自定义活动发布到 NuGet 包中,并向 2019.10.1 或更高版本 Studio 中定义的订阅源提供该包。

步骤 1:创建 NuGet 包

docs image

  1. 启动 NuGet Package Explorer
  2. 单击“创建新包 (Ctrl + N)”。随即会出现一个分割窗口,其中显示“包元数据”和“包内容”。我们需要在窗口的后一部分中添加所有依赖项。
  3. 右键单击“包内容”部分。系统随即会显示一个上下文菜单。
  4. 单击“添加库文件夹”。请注意,系统会在“包内容”部分创建新的“库”项目。
  5. 右键单击“库”并选择“添加现有文件…”
  6. 加载项目的外部程序集 (.dll)。
  7. 单击“编辑”>“编辑元数据”。随即会显示“包元数据”部分。
  8. 根据需要填写字段,以更好地描述项目。
  9. 填写“ID”字段,并确保包含关键字“活动”,以便在 Studio 的“管理包”窗口中显示该包。
  10. 单击“文件”>“保存”。本示例中,我们已创建“.nupkg”文件。
    备注:

    务必为活动创建直观的文件夹结构。与 Orchestrator 一起使用时,系统会删除自定义活动中的所有空文件夹。

步骤 2:在 UiPath Studio 中安装 NuGet 包

创建 .nupkg 文件后,将其添加到 Studio 中的自定义订阅源,如此处所述。

打开“管理包”窗口并安装包。请确保在 Studio 中启用自定义订阅源。

示例向导

只需点击以下链接即可下载示例,其中还包含创建自定义活动设置的示例。

  • 构建自定义向导
  • 将项目添加到 Studio
  • 示例向导

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新