From b1f7693275c7e5dee4bbdc8896cfca2b0591237d Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Tue, 28 Oct 2014 16:33:26 -0400 Subject: [PATCH] Initial commit --- CreateInstallDescriptor.csproj | 62 ++++++++++++++++++++++++++++ CreateInstallDescriptor.sln | 24 +++++++++++ Program.cs | 75 ++++++++++++++++++++++++++++++++++ Properties/AssemblyInfo.cs | 36 ++++++++++++++++ 4 files changed, 197 insertions(+) create mode 100644 CreateInstallDescriptor.csproj create mode 100644 CreateInstallDescriptor.sln create mode 100644 Program.cs create mode 100644 Properties/AssemblyInfo.cs diff --git a/CreateInstallDescriptor.csproj b/CreateInstallDescriptor.csproj new file mode 100644 index 0000000..9cb3209 --- /dev/null +++ b/CreateInstallDescriptor.csproj @@ -0,0 +1,62 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {A5446203-AE6F-4717-B927-BF9DB24B538B} + Exe + Properties + CreateInstallDescriptor + CreateInstallDescriptor + v3.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + 3.5 + + + + + + + + + + {000C1092-0000-0000-C000-000000000046} + 1 + 0 + 1033 + tlbimp + False + + + + + \ No newline at end of file diff --git a/CreateInstallDescriptor.sln b/CreateInstallDescriptor.sln new file mode 100644 index 0000000..27a02f7 --- /dev/null +++ b/CreateInstallDescriptor.sln @@ -0,0 +1,24 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreateInstallDescriptor", "CreateInstallDescriptor.csproj", "{A5446203-AE6F-4717-B927-BF9DB24B538B}" +EndProject +Global + GlobalSection(SubversionScc) = preSolution + Svn-Managed = True + Manager = AnkhSVN - Subversion Support for Visual Studio + EndGlobalSection + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A5446203-AE6F-4717-B927-BF9DB24B538B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A5446203-AE6F-4717-B927-BF9DB24B538B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A5446203-AE6F-4717-B927-BF9DB24B538B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A5446203-AE6F-4717-B927-BF9DB24B538B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..00ac0b7 --- /dev/null +++ b/Program.cs @@ -0,0 +1,75 @@ +using System; +using System.IO; +using System.Xml; +using WindowsInstaller; + +namespace CreateInstallDescriptor +{ + class Program + { + static void Main(string[] args) + { + // Make sure we received two parameters + if (args.Length != 2) + { + Console.WriteLine("Must supply two parameters: "); + return; + } + + // Extract the parameters + string inputFile = args[0]; + string outputFile = args[1]; + + // Get the type of the Windows Installer object + Type installerType = Type.GetTypeFromProgID("WindowsInstaller.Installer"); + + // Create the Windows Installer object + Installer installer = (Installer)Activator.CreateInstance(installerType); + + // Open the MSI database in the input file + Database database = installer.OpenDatabase(inputFile, MsiOpenDatabaseMode.msiOpenDatabaseModeReadOnly); + + // Open a view on the Property table for the version property + View view = database.OpenView("SELECT * FROM Property WHERE Property = 'ProductVersion'"); + + // Execute the view query + view.Execute(null); + + // Get the record from the view + Record record = view.Fetch(); + + // Get the version from the data + string version = record.get_StringData(2); + + // ----- + + // Create the XML writer + XmlTextWriter xmlWriter = new XmlTextWriter(outputFile, null) { Formatting = Formatting.Indented }; + + // Write the root tag + xmlWriter.WriteStartElement("versionInformation"); + + // Write the version tag + xmlWriter.WriteStartElement("version"); + xmlWriter.WriteValue(version); + xmlWriter.WriteEndElement(); + + // Write the installer name tag + xmlWriter.WriteStartElement("installFile"); + xmlWriter.WriteValue(Path.GetFileName(inputFile)); + xmlWriter.WriteEndElement(); + + // Write the installer date tag + xmlWriter.WriteStartElement("installCreated"); + xmlWriter.WriteValue(DateTime.Now); + xmlWriter.WriteEndElement(); + + // End the root tag + xmlWriter.WriteEndElement(); + + // Close out the writer + xmlWriter.Flush(); + xmlWriter.Close(); + } + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..a116c6b --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CreateInstallDescriptor")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("CreateInstallDescriptor")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2009")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("4b8c4050-d609-4f05-a10b-c95a576b2cc0")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]