オフィシャル フィード (https://www.myget.org/F/workflow
) から提供される UiPath.Activities.API パッケージを使用して、Studio でアクティビティのカスタム プロジェクト設定を独自に作成、追加できます。
重要
カスタム プロジェクトでは開発依存関係として UiPath.Activities.API パッケージを使用する必要があります。開発依存関係についてご覧ください。
Activity project settings encompass a set of options that can be adjusted on a project level directly from the Project Settings window.


アクティビティ設定の作成
以下のサンプルでは、音楽プレイヤーのサンプル アクティビティで使用する一連の設定を作成します。
タブとセクションの追加
using UiPath.Studio.Activities.Api;
using UiPath.Studio.Activities.Api.Settings;
namespace MyCustomActivityPack
{
public static class SettingsCreator
{
// This is the key used to reference a tab, even across packages.
internal const string CategoryKey = "DemoTabUniqueKey";
// This is the key used to reference the setting, even across packages.
internal const string CommentTextKey = CategoryKey + ".Comment";
internal const string PresetKey = CategoryKey + ".Preset";
internal const string ShuffleKey = CategoryKey + ".Shuffle";
public static void CreateSettings(IWorkflowDesignApi workflowDesignApi)
{
var settingsApi = workflowDesignApi.Settings;
// Add the category (a tab in the settings page)
var category = new SettingsCategory()
{
Description = "Settings Sample",
Header = "Settings Sample",
Key = CategoryKey
};
settingsApi.AddCategory(category);
AddMusicPlayerSection(settingsApi, category);
AddMiscSettings(settingsApi, category);
上記のコードは、[アクティビティのプロジェクト設定] ウィンドウにタブとセクションを追加します。タブのツールチップ上にカーソルを置くと、タブについての説明が表示されます。


設定の追加
- 展開可能な設定セクション
private static SettingsSection AddMusicPlayerSection(IActivitiesSettingsService settingsApi, SettingsCategory category)
{
var section = new SettingsSection()
{
Description = "Settings for a music player",
IsExpanded = true, //set this to control default expansion
Title = "Music Player Settings",
// the key of a section has to be unique only within the category
Key = "Player"
};
settingsApi.AddSection(category, section);
AddSimpleBoolean(settingsApi, section);
AddSingleChoice(settingsApi, section);
return section;
}
次のような結果が得られます。


- Boolean 値のラジオ ボタン
private static void AddSimpleBoolean(IActivitiesSettingsService settingsApi, SettingsSection section)
{
var booleanSetting = new SingleValueEditorDescription<bool>
{
DefaultValue = true,
Description = "If active, the playlist is shuffled",
// The value returned by GetDisplayValue should be localized
GetDisplayValue = b => b ? "On" : "Off",
Key = ShuffleKey,
Label = "Shuffle"
};
settingsApi.AddSetting(section, booleanSetting);
}
次のような結果が得られます。


- 複数の値選択リスト
private static void AddSingleChoice(IActivitiesSettingsService settingsApi, SettingsSection category)
{
var booleanSetting = new SingleValueSelectorDescription
{
DefaultValue = "pop",
Values = new[] { "classic", "pop", "rock" },
Description = "Sample single choice setting",
// The value returned by GetDisplayValue should be localized
GetDisplayValue = choice => choice + " music",
Key = PresetKey,
Label = "Mixer Preset"
};
settingsApi.AddSetting(category, booleanSetting);
}
次のような結果が得られます。


- 検証機能付きのテキスト入力フィールド
private static void AddSimpleString(IActivitiesSettingsService settingsApi, SettingsSection section)
{
var simpleStringSetting = new SingleValueEditorDescription<string>()
{
Description = "A free text comment that can't contain the word 'invalid'",
// The GetDisplayValue obtains a localized screen representation of the underlying setting value.
GetDisplayValue = LocalizeSimpleSettingValue,
IsReadOnly = false,
DefaultValue = "There is no comment",
Label = "Comment",
Validate = ValidateSimpleStringSetting,
Key = CommentTextKey
};
// Add the setting to the section.
// A setting may also be directly added on a category. It will appear as a setting without a section (top level setting)
settingsApi.AddSetting(section, simpleStringSetting);
}
private static string LocalizeSimpleSettingValue(string s) => $"A localized value of `{s}`";
private static string ValidateSimpleStringSetting(string arg)
{
if (arg?.ToLowerInvariant().Contains("invalid") == true)
{
return "The sample string setting is invalid if it contains the `invalid` keyword";
}
return string.Empty;
}
次のような結果が得られます。


Studio へのプロジェクトの追加
Studio の [アクティビティのプロジェクト設定] ウィンドウに設定を表示させるには、カスタム アクティビティを NuGet パッケージにパブリッシュして、このパッケージを Studio バージョン 2019.10.1 以降で定義したフィードで利用できるようにする必要があります。
NuGet パッケージの作成


- NuGet Package Explorer を起動します。
- [Create a new package] (Ctrl + N) をクリックします。[Package metadata] と、[Package contents] を示す分割ウィンドウが表示されます。後者のセクションに、すべての依存関係を追加する必要があります。
- [Package contents] セクションを右クリックします。コンテキスト メニューが表示されます。
- [Add lib folder] をクリックします。新しい [lib] 項目が、[Package contents] セクションに作成されます。
- [lib] を右クリックして、[Add Existing File…] を選択します。
- プロジェクトの外部アセンブリ (.dll) を読み込みます。
- [Edit] > [Edit Metadata] をクリックします。[Package metadata] セクションが表示されます。
- プロジェクトの適切な説明をフィールドに入力します。
- [Id] フィールドに入力し、キーワード Activities が含まれていることを確認します。これにより、Studio の [パッケージを管理] ウィンドウにパッケージが表示されるようになります。
- [File] > [Save] をクリックします。このケースでは、
.nupkg
ファイルが作成されます。
注:
アクティビティには、直感的なフォルダー構造を作成してください。Orchestrator で使用すると、カスタム アクティビティ内の空のフォルダーはすべて削除されます。
UiPath Studio への NuGet パッケージのインストール
Once the .nupkg
file is created, add it to a custom feed in Studio, as explained here.
Open the Manage Packages window and install the package. Make sure the custom feed is enabled in Studio.
設定例
上記で作成したタブ、セクション、および設定をまとめて、[アクティビティのプロジェクト設定] ウィンドウに表示します。


下記のリンクをクリックしてサンプルをダウンロードします。サンプルには、ウィザードの作成例も含まれています。
7 か月前に更新