gpt4 book ai didi

c# - Inno Setup 循环遍历文件并注册每个 .NET dll

转载 作者:太空狗 更新时间:2023-10-30 01:20:31 26 4
gpt4 key购买 nike

我正在使用 Inno Setup 创建安装文件,我需要使用 regasm.exe 文件注册未知数量的 .net dll。我知道我可以使用下面的代码来注册 .net dll。

[Run]
Filename: "{dotnet20}\RegAsm.exe"; Parameters: /codebase MyDLL.dll; WorkingDir: {app}; StatusMsg: "Registering Controls."; Flags: runminimized

我的问题是,文件夹中有多个dll,我不知道要注册的每个dll 的名称。有没有一种方法可以循环遍历文件夹中的文件并在不知道文件数量及其名称的情况下注册每个文件?

请帮忙,谢谢

最佳答案

我找不到任何可以为您注册它们的标志,例如来自 [Files] 部分,所以我编写了这个脚本,它应该迭代指定文件夹中的所有 *.dll 文件,并为每个调用注册工具命令行。请注意,我还没有测试过这个脚本,我不确定使用的命令行及其参数,但基本思想应该在那里:

[Code]
function RegisterNetLibraries(const Folder: string): Integer;
var
RegTool: string;
FindRec: TFindRec;
ResultCode: Integer;
begin
// initialize result to 0 processed files
Result := 0;
// expand the path to the registration tool
RegTool := ExpandConstant('{dotnet20}\RegAsm.exe');
// check if the registration tool exists; if not then exit...
if not FileExists(RegTool) then
begin
MsgBox('RegAsm.exe not found!' + #13#10 + RegTool, mbError, MB_OK);
Exit;
end;
// if we've found a *.dll file in the specified folder, then...
if FindFirst(ExpandConstant(Folder + '\*.dll'), FindRec) then
try
// repeat loop for every *.dll file in the specified folder
repeat
// if the iterated item is not a directory named like Dir.dll
if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then
begin
// if the execution of the registration tool succeeded, then...
if Exec(RegTool, '/codebase ' + Folder + '\' + FindRec.Name,
ExpandConstant('{app}'), SW_HIDE, ewWaitUntilTerminated,
ResultCode)
then
// increase the returned processed file count
Result := Result + 1
else
// the execution failed, so let's try to show why
SysErrorMessage(ResultCode);
end;
until
// when there no next file item, the loop ends
not FindNext(FindRec);
finally
// release the allocated search resources
FindClose(FindRec);
end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
var
Count: Integer;
begin
// if we are at the post installation step, then...
if CurStep = ssPostInstall then
begin
// the RegisterNetLibraries function returns count of processed files,
// don't forget that you must pass expanded constant values
Count := RegisterNetLibraries(ExpandConstant('{app}\Libs'));
// show how many files have been processed
MsgBox(IntToStr(Count) + ' libraries was processed...', mbInformation,
MB_OK);
end;
end;

关于c# - Inno Setup 循环遍历文件并注册每个 .NET dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18844950/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com