[英]Inno Setup Modify app.config file when you run setup.exe
I have a WCF service which I am hosting as a Windows Service. 我有一个WCF服务,我作为Windows服务托管。 I normally go to VS command prompt and install the service using installutil.exe, then modify the base address of the service in app.config according to the machine name that I am installing it on and run the service. 我通常会转到VS命令提示符并使用installutil.exe安装该服务,然后根据我安装它的机器名修改app.config中服务的基地址并运行该服务。
base address goes like this: 基地址如下:
<endpoint address="http://MACHINE_NAME/NFCReader/" binding="webHttpBinding"/>
I modify the MACHINE_NAME in the app.config file. 我在app.config文件中修改了MACHINE_NAME。
I want to use inno setup to do the same for me. 我想使用inno设置为我做同样的事情。
What I want is when the user run the setup.exe file to install the service, I want to prompt the user for base address of the service and use that address to host it. 我想要的是当用户运行setup.exe文件来安装服务时,我想提示用户提供服务的基地址并使用该地址来托管它。 I am not able to figure out if it is possible at all OR how to do it. 我无法弄清楚它是否可能或如何做到这一点。
Any help please? 有什么帮助吗? Thanks in advance. 提前致谢。 :) :)
Just an example I use to replace string in my app config. 我只是用来替换app app中的字符串的例子。
I'm sure it can be done better :-) 我相信它可以做得更好:-)
What I replace is: 我取代的是:
add key="AppVersion" value="YYMMDD.HH.MM" add key =“AppVersion”value =“YYMMDD.HH.MM”
[Code]
procedure Update;
var
C: AnsiString;
CU: String;
begin
LoadStringFromFile(ExpandConstant('{src}\CdpDownloader.exe_base.config'), C);
CU := C;
StringChange(CU, 'YYMMDD.HH.MM', GetDateTimeString('yymmdd/hh:nn', '.', '.'));
C := CU;
SaveStringToFile(ExpandConstant('{src}\Config\CdpDownloader.exe.config'), C, False);
end;
function InitializeSetup: Boolean;
begin
Update;
result := True;
end;
I would recommend you to use XML parser for updating your configuration files. 我建议您使用XML解析器来更新配置文件。 The following function can help you with it. 以下功能可以帮助您。 It uses MSXML as a file parser: 它使用MSXML作为文件解析器:
[Code]
const
ConfigEndpointPath = '//configuration/system.serviceModel/client/endpoint';
function ChangeEndpointAddress(const FileName, Address: string): Boolean;
var
XMLNode: Variant;
XMLDocument: Variant;
begin
Result := False;
XMLDocument := CreateOleObject('Msxml2.DOMDocument.6.0');
try
XMLDocument.async := False;
XMLDocument.preserveWhiteSpace := True;
XMLDocument.load(FileName);
if (XMLDocument.parseError.errorCode <> 0) then
RaiseException(XMLDocument.parseError.reason)
else
begin
XMLDocument.setProperty('SelectionLanguage', 'XPath');
XMLNode := XMLDocument.selectSingleNode(ConfigEndpointPath);
XMLNode.setAttribute('address', Address);
XMLDocument.save(FileName);
Result := True;
end;
except
MsgBox('An error occured during processing application ' +
'config file!' + #13#10 + GetExceptionMessage, mbError, MB_OK);
end;
end;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.