public static void ListPackageContent(string msiPath, DirectoryInfo di) { IInstallPackage package = null; try { package = DeploymentUnit.ScanPackage(msiPath); if (package != null) { Console.WriteLine("Title: " + package.Title); Console.WriteLine("Author: " + package.Author); Console.WriteLine("Subject: " + package.Subject); Console.WriteLine("Comments: " + package.Comments); Console.WriteLine("Keywords: " + package.Keywords); Console.WriteLine("Create Time: " + package.CreateTime.ToString("u", CultureInfo.InvariantCulture)); Console.WriteLine("Package Code: " + package.RevisionNumber); Console.WriteLine("Resource type;Luid;Filename;Version"); if ((package.Resources != null) && (package.Resources.Length != 0)) { foreach (IDeploymentResource resource in package.Resources) { Console.Write(string.Format("{0};{1};", new object[] { resource.ResourceType, resource.Luid })); // Get the corresponding file if (resource.Properties.ContainsKey("DestinationLocation")) { string filename = (string)resource.Properties["DestinationLocation"]; if (!string.IsNullOrEmpty(filename)) { FileInfo fi = new FileInfo(filename); FileInfo[] fis = di.GetFiles(fi.Name, SearchOption.AllDirectories); if (fis.Length > 0) { FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(fis[0].FullName); Console.WriteLine(string.Format("{0};{1}", filename, versionInfo.FileVersion)); } else { Console.WriteLine(";"); } } else { Console.WriteLine(";"); } } else { Console.WriteLine(";"); } } } } } catch (Exception exception) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Error occured: {0}", exception.Message); Console.ResetColor(); } }
private void ListPackageContent(string msiPath, DirectoryInfo di, Dictionary <string, string> properties) { IInstallPackage package = null; try { package = DeploymentUnit.ScanPackage(msiPath); if (package != null) { string productCode = string.Empty; if ((null != properties) && properties.ContainsKey("ProductCode")) { productCode = properties["ProductCode"]; } this.installedPackages.Package.AddPackageRow( package.Title, package.Author, package.Subject, package.Comments, package.CreateTime, package.RevisionNumber, productCode); if ((package.Resources != null) && (package.Resources.Length != 0)) { foreach (IDeploymentResource resource in package.Resources) { string filename = string.Empty; string version = string.Empty; // Get the corresponding file if (resource.Properties.ContainsKey("DestinationLocation")) { filename = (string)resource.Properties["DestinationLocation"]; if (!string.IsNullOrEmpty(filename)) { FileInfo fi = new FileInfo(filename); FileInfo[] fis = di.GetFiles(fi.Name, SearchOption.AllDirectories); if (fis.Length > 0) { FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(fis[0].FullName); version = versionInfo.FileVersion; } } } this.installedPackages.Resources.AddResourcesRow( resource.ResourceType, resource.Luid, filename, version, package.RevisionNumber); } } } } catch (Exception exception) { throw new Exception(string.Format("ListPackageContent Error occured: {0}", exception.Message), exception); } }
private void ImportFromMsi() { if (this.MsiPath == null) { // -Package Required. The path and file name of the Windows Installer package. this.Log.LogError("MSI source is required"); return; } this.LogTaskMessage(string.Format(CultureInfo.InvariantCulture, "Importing from {0}", this.MsiPath.ItemSpec)); if (string.IsNullOrEmpty(this.Application)) { // -ApplicationName Optional. The name of the BizTalk application. this.Application = this.explorer.DefaultApplication.Name; this.LogTaskMessage(string.Format(CultureInfo.InvariantCulture, "Using default application {0}", this.Application)); } // create application if it doesn't exist if (!this.CheckExists(this.Application)) { OM.Application newapp = this.explorer.AddNewApplication(); newapp.Name = this.Application; this.explorer.SaveChanges(); this.LogTaskMessage(string.Format(CultureInfo.InvariantCulture, "Creating new application {0}", this.Application)); } using (Group group = new Group()) { group.DBName = this.Database; group.DBServer = this.DatabaseServer; Microsoft.BizTalk.ApplicationDeployment.Application appl = group.Applications[this.Application]; // used to specify custom properties for import, i.e. TargetEnvironment IDictionary <string, object> requestProperties = null; if (!string.IsNullOrEmpty(this.Environment)) { // -Environment Optional. The environment to deploy. requestProperties = new Dictionary <string, object> { { "TargetEnvironment", this.Environment } }; this.LogTaskMessage(string.Format(CultureInfo.InvariantCulture, "Target environment {0} specified", this.Environment)); } // the overload that takes request properties also requires this IInstallPackage package = DeploymentUnit.ScanPackage(this.MsiPath.ItemSpec); ICollection <string> applicationReferences = package.References; // -Overwrite Optional. Update existing resources. If not specified and resource exists, import will fail. appl.Import(this.MsiPath.ItemSpec, requestProperties, applicationReferences, this.Overwrite); this.LogTaskMessage(string.Format(CultureInfo.InvariantCulture, "Successfully imported {0} into application {1}", this.MsiPath.ItemSpec, this.Application)); } }
public MsiPackage(string msiPath) { this.MsiPath = msiPath; try { _scannedPackage = DeploymentUnit.ScanPackage(msiPath); } catch (Exception) { _scannedPackage = null; } }
public static List <string> ListPackageContentAsList(string msiPath) { IInstallPackage package = null; List <string> packageInfo = new List <string>(); if (string.IsNullOrWhiteSpace(msiPath)) { return(packageInfo); } try { Dictionary <string, string> properties; string path = Helper.ExtractFiles(msiPath, out properties); DirectoryInfo di = new DirectoryInfo(path); package = DeploymentUnit.ScanPackage(msiPath); if (package != null) { packageInfo.Add("Title: " + package.Title); packageInfo.Add("Author: " + package.Author); packageInfo.Add("Subject: " + package.Subject); packageInfo.Add("Comments: " + package.Comments); packageInfo.Add("Keywords: " + package.Keywords); packageInfo.Add("Create Time: " + package.CreateTime.ToString("u", CultureInfo.InvariantCulture)); packageInfo.Add("Package Code: " + package.RevisionNumber); if ((null != properties) && properties.ContainsKey("ProductCode")) { packageInfo.Add("Product Code: " + properties["ProductCode"]); } else { packageInfo.Add("Product Code: "); } packageInfo.Add("Resource type;Luid;Filename;Version"); if ((package.Resources != null) && (package.Resources.Length != 0)) { foreach (IDeploymentResource resource in package.Resources) { string resourceItem = string.Format("{0};{1};", new object[] { resource.ResourceType, resource.Luid }); // Get the corresponding file if (resource.Properties.ContainsKey("DestinationLocation")) { string filename = (string)resource.Properties["DestinationLocation"]; if (!string.IsNullOrEmpty(filename)) { FileInfo fi = new FileInfo(filename); FileInfo[] fis = di.GetFiles(fi.Name, SearchOption.AllDirectories); if (fis.Length > 0) { FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(fis[0].FullName); resourceItem += string.Format("{0};{1}", filename, versionInfo.FileVersion); } else { resourceItem += ";"; } } else { resourceItem += ";"; } } else { resourceItem += ";"; } packageInfo.Add(resourceItem); } } } di.Delete(true); } catch (Exception exception) { throw new Exception(string.Format("ListPackageContent: Error occured: {0}", exception.Message), exception); } return(packageInfo); }