c# – Inno Setup循环浏览文件并注册每个.NET dll
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – Inno Setup循环浏览文件并注册每个.NET dll,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2389字,纯文字阅读大概需要4分钟。
内容图文
![c# – Inno Setup循环浏览文件并注册每个.NET dll](/upload/InfoBanner/zyjiaocheng/793/3a78f91f541c4eb58c8f645415c15aa2.jpg)
我正在使用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全部内容,希望文章能够帮你解决c# – Inno Setup循环浏览文件并注册每个.NET dll所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。