UiPath Marketplace
最新
False
横幅背景图像
UiPath Marketplace 用户指南
上次更新日期 2024年4月16日

构建活动包

鉴于 UiPath 的平台基于 .NET Framework 构建,因此所有活动均以 Nuget 包(即 .nupkg 直接从 Go 下载活动时获得的文件! UiPath Studio包管理器中的订阅源)。 将文件捆绑到单个 Nuget 包需要 4 种类型的文件:

程序集信息文件



每当在 Visual Studio 中生成项目时,Microsoft 生成引擎(又名MSBuild )都会将该项目的代码转换为DLL ,这是一个可供其他 Windows 应用程序使用的库。 此库的元数据来自存储在项目的“属性”部分中的三个程序集信息文件,这些文件提供不同级别的活动集的信息。 让我们逐一查看:

1. AssemblyInfo.cs

[assembly: AssemblyTitle("MyCompany.MyProduct.Activities")]
[assembly: AssemblyDescription("This activity was made using the UiPath Activity Set extension.")]
[assembly: ComVisible(false)]
[assembly: Guid("133E5191-68DA-4F05-9A81-D5CFA16525C8")][assembly: AssemblyTitle("MyCompany.MyProduct.Activities")]
[assembly: AssemblyDescription("This activity was made using the UiPath Activity Set extension.")]
[assembly: ComVisible(false)]
[assembly: Guid("133E5191-68DA-4F05-9A81-D5CFA16525C8")]

AssemblyInfo.cs 包含此特定项目独有的元数据(例如 MyCompany.MyProduct)。

  • 程序集 标题”为 DLL 提供一个友好名称。 为简单起见,这应与项目的名称匹配。
  • 程序集 说明是对程序集的性质和目的的简短摘要。

    还可能包含其他几个属性,例如区域性或版本号。 有关完整列表,请参阅 Microsoft 官方文档

  • ComVisibleGuid是引用此项目事件库的应用程序使用的默认属性。 对于大多数活动,它们保持不变,但您可以在此处阅读有关其效果的更多信息。

2. MyCompany.MyProductAssemblyInfo.cs

#if DEBUG
[assembly: AssemblyVersion("1.0.*")]
#else
[assembly: AssemblyVersion("1.0.0")]
#endif#if DEBUG
[assembly: AssemblyVersion("1.0.*")]
#else
[assembly: AssemblyVersion("1.0.0")]
#endif

下一个程序集文件 <your activity name>AssemblyInfo.cs 包含元数据,这些元数据对于整个活动集是唯一的,但在所有项目之间共享;在这种情况下,只有活动版本。 请注意,每个 Visual Studio 配置的版本都不同:

  • 调试:如果 Visual Studio 处于调试模式,则构建活动时使用的版本号为 1.0.*, 这意味着已设置主要版本和次要版本 (1.0),并且补丁版本在每次内部版本中递增。 这在频繁更改相同代码时非常有用,因为每个后续包都将使用新版本构建,从而很容易区分。
  • 发布:如果 Visual Studio 处于发布模式,则设置版本号(例如 1.0.0)。 这样可以完全控制包何时正式发布。



3. GlobalAssemblyInfo.cs

[assembly: AssemblyCompany("MyCompany")]
[assembly: AssemblyProduct("Product A")]
[assembly: AssemblyCopyright("MyCompany © 2019")]
[assembly: AssemblyTrademark("MyCompany™")]
[assembly: AssemblyCulture("en-CA")]
[assembly: NeutralResourcesLanguage("en-US")][assembly: AssemblyCompany("MyCompany")]
[assembly: AssemblyProduct("Product A")]
[assembly: AssemblyCopyright("MyCompany © 2019")]
[assembly: AssemblyTrademark("MyCompany™")]
[assembly: AssemblyCulture("en-CA")]
[assembly: NeutralResourcesLanguage("en-US")]

GlobalAss口号Info.cs 包含在您生成的所有活动集之间共享的元数据。 例如, UiPath.GSuite.ActivitiesUiPath.MicrosoftOffice365.Activities包由同一家公司(UiPath) 创建,面向相同的产品(UiPath Studio),并且具有相同的版权商标语言信息,因此它们使用以避免不必要的重复。

Nuspec



将所有项目编译为 DLL 后,系统会将这些库捆绑到一个 Nuget 包中,该包可在 UiPath Studio 中使用。 此包的元数据来自设计项目中的 nuspec 文件。

您可以在此处查看通过 nuspec 提供的元数据元素的完整列表,但请先查看下面的基本示例。 这些元素与 UiPath Studio 包管理器中显示的字段相对应,并允许用户找到并区分您的活动集。

请注意,某些元素(例如 id版本)包含 $element$形式的标签。 它们从“AssemblyInfo”文件中的相应标签获取值,以防止重复信息。
<?xml version="1.0"?>
<package>
  <metadata>
    <id>$title$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <owners>$author$</owners>
    <description>$description$</description>
    <copyright>$copyright$</copyright>
    <requireLicenseAcceptance>true</requireLicenseAcceptance>
    <licenseUrl>https://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
    <projectUrl>https://integrations.uipath.com/docs/integrating-with-uipath</projectUrl>
    <iconUrl>https://raw.githubusercontent.com/NuGet/Samples/master/PackageIconNuspecExample/icon.png</iconUrl>
    <tags>UiPath Activit</tags>
    <dependencies>
    </dependencies>
  </metadata>
  <files>
    <file src="$OutputPath$**\)\)MyCompany.MyProduct*resources.dll" target="lib\)
et461"/>
  </files>
</package><?xml version="1.0"?>
<package>
  <metadata>
    <id>$title$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <owners>$author$</owners>
    <description>$description$</description>
    <copyright>$copyright$</copyright>
    <requireLicenseAcceptance>true</requireLicenseAcceptance>
    <licenseUrl>https://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
    <projectUrl>https://integrations.uipath.com/docs/integrating-with-uipath</projectUrl>
    <iconUrl>https://raw.githubusercontent.com/NuGet/Samples/master/PackageIconNuspecExample/icon.png</iconUrl>
    <tags>UiPath Activit</tags>
    <dependencies>
    </dependencies>
  </metadata>
  <files>
    <file src="$OutputPath$**\)\)MyCompany.MyProduct*resources.dll" target="lib\)
et461"/>
  </files>
</package>


注意: 如果您熟悉 Visual Studio,则可能知道它实际上能够仅使用程序集信息文件和 MSBuild 自行构建 Nuget 包。 那么,为什么要使用额外的 nuspec 文件呢? 某些元数据属性(例如包 所有者本地化 文件)仅在 nuspec 中可用,这就是我们希望保留它的原因。

设计器元数据



创建活动并构建设计器(用户界面元素)后,必须将它们链接在一起并在元数据存储中注册,以便在 UiPath Studio 的“活动”面板中显示。 以下代码通过代表两个活动(“父作用域”和“子活动”)注册以下信息来创建两个活动:

  • 类别”:活动窗格中将显示这些活动的部分。 默认情况下,这设置为“我的公司” > “我的产品”,并且可以通过修改 Resources.resx中的“类别”属性来进行更改。 了解第 12 行如何将活动项目中的类链接到第 10 行中指定的类别。
  • 设计器”:该活动的用户界面。 了解第 13 行如何将活动项目中的类链接到设计项目中的类。
  • 文档:活动的在线文档。 选择其中一个 UiPath 工作流中的任何活动,按 F1,即可在默认浏览器中打开该活动的帮助文档。 如第 14 行所示,此文档的 URL 在此处指定(使用go.uipath.com 作为占位符)。

    namespace MyCompany.MyProduct.Activities.Design
    {
        public class DesignerMetadata : IRegisterMetadata
        {
            public void Register()
            {
                var builder = new AttributeTableBuilder();
                builder.ValidateTable();
                var categoryAttribute =  new CategoryAttribute($"{Resources.Category}");
                builder.AddCustomAttributes(typeof(ParentScope), categoryAttribute);
                builder.AddCustomAttributes(typeof(ParentScope), new DesignerAttribute(typeof(ParentScopeDesigner)));
                builder.AddCustomAttributes(typeof(ParentScope), new HelpKeywordAttribute("https://go.uipath.com"));
                builder.AddCustomAttributes(typeof(ChildActivity), categoryAttribute);
                builder.AddCustomAttributes(typeof(ChildActivity), new DesignerAttribute(typeof(ChildActivityDesigner)));
                builder.AddCustomAttributes(typeof(ChildActivity), new HelpKeywordAttribute("https://go.uipath.com"));
                MetadataStore.AddAttributeTable(builder.CreateTable());
            }
        }
    }namespace MyCompany.MyProduct.Activities.Design
    {
        public class DesignerMetadata : IRegisterMetadata
        {
            public void Register()
            {
                var builder = new AttributeTableBuilder();
                builder.ValidateTable();
                var categoryAttribute =  new CategoryAttribute($"{Resources.Category}");
                builder.AddCustomAttributes(typeof(ParentScope), categoryAttribute);
                builder.AddCustomAttributes(typeof(ParentScope), new DesignerAttribute(typeof(ParentScopeDesigner)));
                builder.AddCustomAttributes(typeof(ParentScope), new HelpKeywordAttribute("https://go.uipath.com"));
                builder.AddCustomAttributes(typeof(ChildActivity), categoryAttribute);
                builder.AddCustomAttributes(typeof(ChildActivity), new DesignerAttribute(typeof(ChildActivityDesigner)));
                builder.AddCustomAttributes(typeof(ChildActivity), new HelpKeywordAttribute("https://go.uipath.com"));
                MetadataStore.AddAttributeTable(builder.CreateTable());
            }
        }
    }


构建活动集

完成上述文件后,即可轻松构建活动集。 在“解决方案资源管理器”中,只需右键单击您的解决方案,然后选择“重建解决方案”。



然后,输出面板将指示所有三个项目都已成功构建,并将提供捆绑的 nupkg 文件的路径。



注意: 要构建活动包,您还可以右键单击并“重建” MyCompany.MyProduct 文件夹或 MyCompany.MyProduct.Activities.Design 项目。 为什么会这样? 请参阅下一节有关构建后脚本的部分。

构建后脚本

导航至“设计”项目的“属性”>“构建事件”,您将找到一个构建后脚本,该脚本会在构建所有项目后立即运行。



此脚本的第一行将删除输出目录中存在的包的所有较旧版本,以防止出现混乱。

第二行使用 NuGet 命令行工具 (nuget.exe) 将 3 个项目的 DLL 合并到一个可由 UiPath Studio 读取的 NuGet 包中。

if exist $(TargetDir)Packages\)\)MyCompany.MyProduct*.* del $(TargetDir)Packages\)\)MyCompany.MyProduct*.*
if $(ConfigurationName) == Debug "$(SolutionDir).nuget\)\)NuGet.exe" pack "$(ProjectPath)" -OutputDirectory "Packages" -IncludeReferencedProjects -Prop Configuration=$(ConfigurationName)if exist $(TargetDir)Packages\)\)MyCompany.MyProduct*.* del $(TargetDir)Packages\)\)MyCompany.MyProduct*.*
if $(ConfigurationName) == Debug "$(SolutionDir).nuget\)\)NuGet.exe" pack "$(ProjectPath)" -OutputDirectory "Packages" -IncludeReferencedProjects -Prop Configuration=$(ConfigurationName)

此页面是否有帮助?

获取您需要的帮助
了解 RPA - 自动化课程
UiPath Community 论坛
Uipath 白色徽标
信任与安全
© 2005-2024 UiPath. All rights reserved.