Reputation: 3093
I cant work out how I would tell from the installer msi, what AssemblyVersion of the application it will install is.
I would like to make a request every few hours to a network location, check the setup.msi to detect a change and then prompt the user to update.
Could I tether the two AssemblyVersions, so as I increment the application it increments the Installers? That way I could check the installer Version?
Or, is there a way to tell from the msi what application version it will install?
Or should I just go about this in a different way, say placing a text file with the revision number on the network share? (not preferred)
N.B. I have used SetupProject
to create my installer.
Upvotes: 6
Views: 1214
Reputation: 119
Although it's an older question, I tried to solve this in VB .net and came up with the following solution. Would this help?
B.t.w. this code checks for the version number of the MSI file, which can be set in the SetupProject file (see properties), but i.m.o. this version should be the same as the project/solution contained in the setup project.
Private Function checkVersionAssemblyInMsiFile(filename As String) As String
Try
Dim WindowsInstaller = CreateObject("WindowsInstaller.Installer")
Dim Database = WindowsInstaller.GetType().InvokeMember("OpenDatabase", Reflection.BindingFlags.InvokeMethod, Nothing, WindowsInstaller, {filename, 0})
Dim Query = "SELECT Value FROM Property WHERE Property = 'ProductVersion'"
Dim View = Database.GetType().InvokeMember("OpenView", Reflection.BindingFlags.InvokeMethod, Nothing, Database, {Query})
View.GetType().InvokeMember("Execute", Reflection.BindingFlags.InvokeMethod, Nothing, View, Nothing)
Dim Record = View.GetType().InvokeMember("Fetch", Reflection.BindingFlags.InvokeMethod, Nothing, View, Nothing)
Dim Version = Record.GetType().InvokeMember("StringData", Reflection.BindingFlags.GetProperty, Nothing, Record, {1})
Return Version
Catch ex As Exception
Return Nothing
End Try
End Function
Upvotes: 1
Reputation: 20780
At the risk of repeating some of Michael U's answer, I'll point out that nobody does that in a Windows Installer environment. When any of the files in a Visual Studio MSI build need deploying to clients, the only solution with VS setup projects is a major upgrade, where you increment the version of the setup project (accept the changes), set RemovePreviousVersions to true, and you must increment the file versions of the files that need updating. You don't need to change AssemblyVersion to do this, but you do need to increment AssemblyFileversion. This should help:
https://www.red-gate.com/simple-talk/dotnet/visual-studio/updates-to-setup-projects/
but it's missing the part about updating file versions.
In general, the update mechanism is fairly straightforward. Major upgrades are based on UpgradeCode, so your application just needs to do a web service call somewhere passing the current ProductVersion and UpgradeCode, and then you need to download any version that is higher than your current ProductVersion, then install it. That's the general idea that works for multiple products on a client system, and there are simpler solutions if you know there is only one product.
Upvotes: 1
Reputation: 15905
(I'm speaking generally about Windows Installer here, because I'm not deeply familiar with SetupProject.)
You could certainly tie versioning information of both an msi and the assemblies contain if your build system supports it, and if you limit your assembly versions to those that are representable as a ProductVersion. Note that if you want to use Windows Installer upgrade logic, you must have meaningful changes alter the first three fields, as Windows Installer ignores the fourth.
If you can crack open the .msi file to perform your own logic (say with Windows Installer APIs, or wrappers such as DTF), you should be able to read the assembly version from the metadata stored within the msi database. In particular, you will want to read values from the MsiAssemblyName table or the File table. Note that the MsiAssemblyName table contains assembly versions and the File table contains file versions; those values are only synchronized if you have ensured it.
Upvotes: 1