Since I couldn't make Inno Setup behave the way I wanted, I eventually checked the version myself in a Check
function:
...
[Files]
Source: "..\bin\{#BuildConfig}\FooBar.dll"; DestDir: "{app}"; Flags: uninsrestartdelete; Check: ShouldInstallFooBar; BeforeInstall: BeforeInstallFooBar;
...
[Code]
function ShouldInstallFooBar() : Boolean;
var
fooBarTempPath: String;
installedFooBarPath: String;
newFooBarVersion: String;
installedFooBarVersion: String;
begin
installedFooBarPath := ExpandConstant('{app}\FooBar.dll');
if FileExists(installedFooBarPath) then begin
// Get version of currently installed file
if GetVersionNumbersString(installedFooBarPath, installedFooBarVersion) then begin
Log('File already exists; version = ' + installedFooBarVersion);
// Extract new file and get its version
ExtractTemporaryFile('FooBar.dll');
fooBarTempPath := ExpandConstant('{tmp}\FooBar.dll');
if GetVersionNumbersString(fooBarTempPath, newFooBarVersion) then begin
Log('New version = ' + newFooBarVersion);
if newFooBarVersion <> installedFooBarVersion then begin
fooBarShouldBeInstalled := true;
end else begin
fooBarShouldBeInstalled := false;
end;
end else begin
// Failed to get version for new file; assume it's different and install it
fooBarShouldBeInstalled := true;
end;
end else begin
// Failed to get version for existing file; assume it's different and install the new one
fooBarShouldBeInstalled := true;
end;
end else begin
// File doesn't exist, install it
fooBarShouldBeInstalled := true;
end;
Result := fooBarShouldBeInstalled;
end;
procedure BeforeInstallFooBar();
begin
// what I need to do before the file is installed...
end;
...