本文由网友
蓝创精英团队投稿,欢迎转载、分享Original author: Lan Chuang elite team
Original link: blog.csdn.net/i2blue/article/details/125040323
In fact, PAD, there is no external component-based or plug-in development interface in the official documents.
However, there are some like-minded friends, such as Pan Chun and Boss Pan, who are still very good in the field of RPA.
As long as there is a door, there will be a world, and now there is a door (after all, it is the. NET Framework, so research and learning will be much easier).
component development environment
The default component location is this directory under the current application
C:\Program Files (x86)\Power Automate Desktop\custom-modules
Apply the address according to your own.
In addition, the plug-in DLL requires DLL code signature.
By default, a personal signature is adopted and placed at a trusted root certificate authority in the system.
If you have money, you can buy a code signature.
At present, I don't have any other good methods here. Among them, signatures are roughly divided into two types. One is domain name certificate SSL, and code signature. They are different and cannot be mixed.
The general catalog is as follows:

The easiest Demo
Prepare to go through the development process directly and finally summarize it.
Create a new blank solution
A new solution is added by default (empty solution)

New component library
Component DLL names must meet the following rules
"?*.Modules.?*.dll",
"Modules.?*.dll"
However, the official component package looks like this
Microsoft.Flow.RPA.Desktop.Modules.System.Actions.dll
Therefore, I also follow the official standards.
就叫 YZG.Modules.HelloWorld.Actions(注:需要注意的是,像 demo,test 等名字,可能会导致识别不出来的问题,所以,建议起一些特殊的名字。)

Say hello to component projects
The default plan starts with saying hello
Reference development DLL package
然后,引用安装目录 C:\Program Files (x86)\Power Automate Desktop
These DLL packages are downloaded
Microsoft.Flow.RPA.Desktop.Modules.SDK.dll
Microsoft.Flow.RPA.Desktop.Modules.SDK.Extended.dll
Of course, if you remind you which package you need during use, you can also introduce it in.
After introduction, the effect is as follows:

Increase greeting logic
Here is the full logic code
[Action(Id = "SayHello")]
[Icon(Code = "EFF7")]
[Throws("MyError")]
public class SayHello : ActionBase
{
[InputArgument]
public string UserName { get; set; }
[OutputArgument]
public string Result { get; set; }
public override void Execute(ActionContext context)
{
try
{
this.Result = $"{UserName} 你好,中国欢迎你! -{DateTime.Now}";
}
catch (ActionException ex)
{
throw new ActionException("MyError", ex.Message, ex.InnerException);
}
}
}
Increase international support
There is no need to add foreign languages, just add Chinese support directly
First, we add a Chinese resource file (you can also refer to the language pack under the official website path for internal structure analysis)

General rules for component display
Where did the component name come from?

It comes from the AssemblyTitle in the assembly information. This name is in English by default, but it can also be translated into Chinese.
In addition, this name should not be consistent with the name of the component Action. This way, the display will be more convenient
General rules for displaying component content
通过对 组件名 或者 类型 以及 类属性 分割。
increase
- _FriendlyName
- _Description
- _Summary
其中 FriendlyName 就是各种组件的主名称,Description就是提示语相当于,Summary就是关键信息,作用还是很明显的,内部使用了模板引擎变量 < 属性名大写 >来动态显示一些信息。
A general example is as follows:
Close_Connection_Description = "新 SQL 连接的句柄"
Close_Connection_FriendlyName = "SQL 连接"
Close_Description = "关闭与数据库的开放连接"
Close_FriendlyName = "关闭 SQL 连接"
Close_Summary = "关闭 SQL 连接 <CONNECTION>"
ConnectAndExecute_Description = "连接到数据库并执行 SQL 语句"
ConnectAndExecute_Summary = "<if(RESULT)>\r\n执行 SQL 语句 <STATEMENT> 并将查询结果存储到 <RESULT> 中<else>\r\n执行 SQL 语句 <STATEMENT><endif>"
Connect_ConnectionString_Description = "用于连接到数据库的连接字符串"
Connect_ConnectionString_FriendlyName = "连接字符串"
Connect_Connection_Description = "新 SQL 连接的句柄"
Connect_Connection_FriendlyName = "SQL 连接"
Connect_Description = "打开与数据库的新连接"
Connect_FriendlyName = "打开 SQL 连接"
Connect_Summary = "<if(CONNECTION)>\r\n打开 SQL 连接 <CONNECTIONSTRING> 并将其存储到 <CONNECTION> 中<else>\r\n打开 SQL 连接 <CONNECTIONSTRING><endif>"
Database_Description = "连接到数据库并执行 SQL 语句"
Database_FriendlyName = "数据库"
ErrorMessage_CannotConnect = "无法连接到数据源"
ErrorMessage_CannotConnectError = "无法连接到数据源 {0}"
ErrorMessage_InvalidConnectionString = "连接字符串无效"
ErrorMessage_StatementError = "SQL 语句中的错误 {0}"
ErrorMessage_UniniatializedConnection = "SQL 连接未初始化。请仔细检查是否已指定正确的 SQL 连接,且该连接在“打开 SQL 连接”之后(而不是在已关闭该连接之后)使用"
Error_ConnectToDataSourceError_Description = "指示连接到数据源时出现问题"
Error_ConnectToDataSourceError_FriendlyName = "无法连接到数据源"
Error_InvalidConnectionStringError_Description = "指示指定的连接字符串无效"
Error_InvalidConnectionStringError_FriendlyName = "连接字符串无效"
Error_SqlStatementError_Description = "指示给定的 SQL 语句中存在错误"
Error_SqlStatementError_FriendlyName = "SQL 语句中的错误"
ExecuteSqlStatement_ConnectionString_Description = "用于连接到数据库的连接字符串"
ExecuteSqlStatement_ConnectionString_FriendlyName = "连接字符串"
ExecuteSqlStatement_Connection_Description = "新 SQL 连接的句柄"
ExecuteSqlStatement_Connection_FriendlyName = "SQL 连接"
ExecuteSqlStatement_Description = "连接到数据库并执行 SQL 语句"
ExecuteSqlStatement_FriendlyName = "执行 SQL 语句"
ExecuteSqlStatement_GetConnection_Description = "指定是从给定连接字符串创建新连接,还是选择已打开的连接"
ExecuteSqlStatement_GetConnection_FriendlyName = "获取连接的方式"
ExecuteSqlStatement_Result_Description = "来自数据库的结果,采用数据表的形式,包含行和列"
ExecuteSqlStatement_Result_FriendlyName = "查询结果"
ExecuteSqlStatement_Statement_Description = "要对数据库执行的 SQL 语句"
ExecuteSqlStatement_Statement_FriendlyName = "SQL 语句"
ExecuteSqlStatement_Timeout_Description = "等待来自数据库的结果的最长时间"
ExecuteSqlStatement_Timeout_FriendlyName = "超时"
Execute_Description = "连接到数据库并执行 SQL 语句"
Execute_Summary = "<if(RESULT)>\r\n对 <CONNECTION> 执行 SQL 语句 <STATEMENT> 并将查询结果存储到 <RESULT> 中<else>\r\n对 <CONNECTION> 执行 SQL 语句 <STATEMENT><endif>"
GetSQLConnectionBy_ConnectionString_FriendlyName = "连接字符串"
GetSQLConnectionBy_SQLConnectionVariable_FriendlyName = "SQL 连接变量"
Message_SqlConnection = "SQL 连接"
SqlConnectionHandle_FriendlyName = "SQL 连接"
SqlConnectionHandle_FriendlyNamePlural = "SQL 连接"
Referring to the above information, next, we will fill in the greeting program with Chinese content.
Actual Chinese content
I added these contents here

Add component project signatures
Those who have money can get their own code signature certificates, and those who have no money can come first according to my temporary self-issued certificate.
Create temporary certificate

to create a new signature (remember that VS wants administrator mode, which means starting as administrator)

Then, a signed pfx file is created

Sign a component DLL
At this time, we need to use this tool (signtool.exe) to sign, which will come with us as long as vs. is installed.
Of course, I will also provide it.
一个签名的 bat 脚本(默认签名密码为 123456)


Basically, only these two assemblies are needed to sign, and the other nuget libraries referenced are not needed.
主要是YZG.Modules.HelloWorld.Actions.dll和zh-Hans\YZG.Modules.HelloWorld.Actions.resources.dll放到签名的地方

Double click bat to sign

In this way, the signature was successful. In addition, you can see the signature information by right-clicking on the DLL.

Install certificate on target machine
If you paid for your certificate, you naturally don't need to install it. Directly recognized. Otherwise, you still need to install the certificate.
Installing the certificate is very simple. Just double click, enter the password, and then select the specified location.

Straight to the next step

next step

Select a trusted root certificate authority


Then, finish, whether to import, yes, confirm, and that's enough.
输入 CMD 命令( certmgr.msc ) 就可以看到指定分组下就有你的证书了。
At this point, the certificate installation is complete.
component deployment
The prerequisite is that the application service must be exited,

Otherwise, the DLL will be occupied.
Then, place the signed project into the specified plug-in directory under the installation directory, as follows.
In addition, this is a C drive, and ** there is another permission issue. Please note that it is best to install it on other disks **.

Then, run the PAD application and create a new task flow, or edit any task flow.
If the following problem occurs, the certificate is not installed on the target machine, just install it.

Then, under normal circumstances, if you open the design view of the PAD, it will look like the following:

A new functional test case-> Say hello and a new feature has been added.
Let's give it a try

After saving, it looks as follows

Finally, you can look at the actual movements and say that the results are very good.

problem handling
- First, regarding the problem that Chinese is not displayed, it is recommended to add a Chinese language pack. The name inside must match the code. Please refer to the example for details.
- Second, if it cannot be loaded, an error will be prompted. You can modify it according to the error prompt or add missing reference packages.
- Third, for more details, we can only explore and try more
Parameter information of extended components
Based on the summary of the netizen (Pan Chun) and my own summary, I also output such a document.
Relevant parameters required by ActionBase


and built-in related types

I also want to thank Big Brother Pan Chun for his summary
end
It's really not easy to write about it, especially PAD. When identifying your components, there will be various problems.
At this time, I have to try again many times, many times.
Fortunately, I have written a Sqlite component based on this extensible component. Examples will also be sent. For the big shots to refer to.