Project instance can be compiled into complete MSI or WiX source file with one of the Compiler "Build" methods.
Use Project non-default constructor or C# initializers to specify required installation components.
static void Main() { string ProjectName; Guid GUID; string Conf; #if DEBUG var IsDebug = true; #else var IsDebug = false; #endif if (IsDebug) { ProjectName = "GitTfsDebug"; GUID = new Guid("6FE30B47-2577-43AD-9095-1861BA25889B"); Conf = "Debug"; } else { ProjectName = "GitTfs"; GUID = new Guid("98823CC2-0C2E-4CF7-B5ED-EA2DD26559BF"); Conf = "Release"; } var SrcDir = @"..\GitTfs\bin\" + Conf; var project = new Project(ProjectName, new Dir(@"%ProgramFiles%\GitTfs", new Files("*.*", f => !f.EndsWith(".pdb") && !f.EndsWith(".xml") && !f.EndsWith(".rtf"))), new EnvironmentVariable("PATH", "[INSTALLDIR]") { Part = EnvVarPart.last }); project.UI = WUI.WixUI_InstallDir; project.GUID = GUID; project.SourceBaseDir = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, SrcDir)); FileVersionInfo fileinfo = FileVersionInfo.GetVersionInfo(Path.Combine(project.SourceBaseDir, "git-tfs.exe")); project.Version = new Version(fileinfo.FileMajorPart, fileinfo.FileMinorPart, fileinfo.FileBuildPart, fileinfo.FilePrivatePart); project.OutFileName = ProjectName + "-" + project.Version.ToString(); TxtToRtf(Path.Combine(project.SourceBaseDir, "LICENSE"), Path.Combine(project.SourceBaseDir, "LICENSE.rtf")); project.LicenceFile = @"LICENSE.rtf"; project.ControlPanelInfo.Manufacturer = "SEP"; //project.ControlPanelInfo.ProductIcon = "GitTfs.ico"; project.ControlPanelInfo.Comments = "A Git/TFS bridge, similar to git-svn"; project.ControlPanelInfo.HelpLink = "http://git-tfs.com/"; project.ControlPanelInfo.UrlUpdateInfo = "https://github.com/git-tfs/git-tfs/releases"; project.MajorUpgrade = new MajorUpgrade { Schedule = UpgradeSchedule.afterInstallInitialize, DowngradeErrorMessage = "A later version of GitTfs is already installed. Setup will now exit." }; project.BuildMsi(); }
static public Project SetClrPrerequisite(this WixSharp.Project project, string version, string errorMessage = null) { string message = errorMessage ?? "Please install .NET " + version + " first."; project.LaunchConditions.Add(new LaunchCondition("REQUIRED_NET=\"#1\"", message)); project.Properties = project.Properties.Add(new RegValueProperty("REQUIRED_NET", RegistryHive.LocalMachine, @"Software\Microsoft\NET Framework Setup\NDP\" + version, "Install", "0")); return(project); }
protected InstallerBase(string projectName, string projectOutFileName, Guid projectGuid) { InstallerProject = new Project { Name = projectName, OutFileName = projectOutFileName, GUID = projectGuid, UI = WUI.WixUI_InstallDir, ControlPanelInfo = {Manufacturer = "DreamTeam Company"} }; }
public static string Execute() { Feature obsPlugin = new Feature("Obs Plugin"); var obsDir = new Dir(@"%ProgramFiles%\OBS\plugins", new File(obsPlugin, @"ObsPlugin\CLRHostPlugin.dll"), new Dir(obsPlugin, "CLRHostPlugin", new DirFiles(obsPlugin, @"ObsPlugin\CLRHostPlugin\*.*") )); Project project = new Project("OBS plugin for digiCamControl",obsDir); project.SetNetFxPrerequisite("NETFRAMEWORK45 >= '#378389'", "Please install .Net 4.5 First"); project.UI = WUI.WixUI_Minimal; project.GUID = new Guid("357E0D80-5093-478E-8C11-28B1A72096E7"); #if DEBUG project.SourceBaseDir = Path.GetFullPath(System.IO.Path.Combine(Environment.CurrentDirectory, @"..\CameraControl\bin\Debug\")); #else project.SourceBaseDir = Path.GetFullPath(System.IO.Path.Combine(Environment.CurrentDirectory, @"..\CameraControl\bin\Release\")); #endif FileVersionInfo ver = null; try { ver = FileVersionInfo.GetVersionInfo(Path.Combine(project.SourceBaseDir, @"ObsPlugin\CLRHostPlugin", "DccObsPlugin.dll")); } catch (FileNotFoundException ex) { project.SourceBaseDir = project.SourceBaseDir.Replace(@"Setup\bin\", ""); ver = FileVersionInfo.GetVersionInfo(Path.Combine(project.SourceBaseDir, @"ObsPlugin\CLRHostPlugin", "DccObsPlugin.dll")); } project.LicenceFile = @"Licenses\DigiCamControlLicence.rtf"; project.Version = new Version(ver.FileMajorPart, ver.FileMinorPart, ver.FileBuildPart, ver.FilePrivatePart); project.MajorUpgradeStrategy = MajorUpgradeStrategy.Default; //project.MajorUpgradeStrategy.NewerProductInstalledErrorMessage = "A version of the digiCamControl already installed. Unistall it first from Control Panel !"; project.MajorUpgradeStrategy.RemoveExistingProductAfter = Step.InstallInitialize; ////project.MajorUpgradeStrategy.UpgradeVersions = VersionRange.ThisAndOlder; ////project.MajorUpgradeStrategy.PreventDowngradingVersions = VersionRange.ThisAndOlder; project.ControlPanelInfo.Manufacturer = "Duka Istvan"; project.OutFileName = string.Format("ObsPluginSetup_{0}", ver.FileVersion); project.ControlPanelInfo.ProductIcon = "logo.ico"; project.InstallScope = InstallScope.perMachine; project.ResolveWildCards(); Compiler.PreserveTempFiles = false; return Compiler.BuildMsi(project); }
private static void Main(string[] args) { var dir = new DirectoryInfo(@"..\..\..\FirmwarePacker\bin\Release"); string exeFileFullName = dir.EnumerateFiles("*.exe").First().FullName; string exeFileName = Path.GetFileName(exeFileFullName); Assembly assembly = Assembly.LoadFile(exeFileFullName); const string projectName = "FmPack"; var mainFeature = new Feature("Программа", true) { AllowChange = false, ConfigurableDir = "INSTALLDIR" }; var project = new Project(projectName, new Dir(mainFeature, InstallerHelper.GetSautProgramLocation(projectName), new Files(dir.FullName + "\\*.*", InstallerHelper.IsFileDesired)), // Environment Variables new EnvironmentVariable("FmPack", "\"[INSTALLDIR]" + exeFileName + "\""), // Shortcuts new Dir(mainFeature, @"%ProgramMenu%\saut", new ExeFileShortcut(projectName, "[INSTALLDIR]" + exeFileName, "") { WorkingDirectory = "INSTALLDIR" } ), new Dir(mainFeature, "%Desktop%", new ExeFileShortcut(mainFeature, projectName, "[INSTALLDIR]" + exeFileName, "") { WorkingDirectory = "INSTALLDIR" } )) { DefaultFeature = mainFeature, OutDir = @"..\..\..\installers" }; project.ResolveWildCards(true) .FindFile(f => f.Name.EndsWith(exeFileName)) .First() .AddAssociation(new FileAssociation("fpc", "application/firmware-project", "Открыть", "\"%1\"") { Icon = "project.ico", Description = "Файл проекта для FmPack" }); project.SetBasicThings(new Guid("1E7AA096-4665-4BE0-A5EB-D7EE62616E38"), DotNetVersion.DotNet4); project.SetInterface(InstallerInterfaceKind.SelectDirectory); project.SetProjectInformation(assembly, @"..\..\..\FirmwarePacker\icon.ico", "https://repo.nposaut.ru/#/tools?tool=FmPack"); string msi = Compiler.BuildMsi(project); InstallerHelper.SignInstaller(msi); }
static void Main() { var project = new Project("PhotoSorter", new Dir(new Id("INSTALLDIR"), @"%LocalAppData%\PhotoSorter", new File(@"..\PhotoSorter\bin\Release\PhotoSorter.exe", new FileShortcut("PhotoSorter", @"%Desktop%"), new FileShortcut("PhotoSorter", @"%ProgramMenu%\PhotoSorter")), new Files(@"..\PhotoSorter\bin\Release\*.*", f => !f.EndsWith(".pdb") && !f.Contains("vshost") && !f.EndsWith("PhotoSorter.exe")), new ExeFileShortcut("Uninstall PhotoSorter", "[System64Folder]msiexec.exe", "/x [ProductCode]") { WorkingDirectory = "%Temp%" }) ); project.GUID = new Guid("{5E1EED8B-5CEB-4EE7-BD2D-B7A4BFA836C0}"); project.Codepage = "1251"; project.Language = "ru-RU"; project.SetVersionFromFile(@"..\PhotoSorter\bin\Release\PhotoSorter.exe"); project.Media.CompressionLevel = CompressionLevel.high; project.Media.EmbedCab = true; project.UI = WUI.WixUI_Common; project.MajorUpgradeStrategy = MajorUpgradeStrategy.Default; project.InstallScope = InstallScope.perUser; var customUi = new CustomUI(); customUi.On(NativeDialogs.ExitDialog, Buttons.Finish, new CloseDialog() { Order = 9999 }); customUi.On(NativeDialogs.WelcomeDlg, Buttons.Next, new ShowDialog(NativeDialogs.InstallDirDlg)); customUi.On(NativeDialogs.InstallDirDlg, Buttons.Back, new ShowDialog(NativeDialogs.WelcomeDlg)); customUi.On(NativeDialogs.InstallDirDlg, Buttons.Next, new SetTargetPath(), new ShowDialog(NativeDialogs.VerifyReadyDlg)); customUi.On(NativeDialogs.InstallDirDlg, Buttons.ChangeFolder, new SetProperty("_BrowseProperty", "[WIXUI_INSTALLDIR]"), new ShowDialog(CommonDialogs.BrowseDlg)); customUi.On(NativeDialogs.VerifyReadyDlg, Buttons.Back, new ShowDialog(NativeDialogs.InstallDirDlg, Condition.NOT_Installed), new ShowDialog(NativeDialogs.MaintenanceTypeDlg, Condition.Installed)); customUi.On(NativeDialogs.MaintenanceWelcomeDlg, Buttons.Next, new ShowDialog(NativeDialogs.MaintenanceTypeDlg)); customUi.On(NativeDialogs.MaintenanceTypeDlg, Buttons.Back, new ShowDialog(NativeDialogs.MaintenanceWelcomeDlg)); customUi.On(NativeDialogs.MaintenanceTypeDlg, Buttons.Repair, new ShowDialog(NativeDialogs.VerifyReadyDlg)); customUi.On(NativeDialogs.MaintenanceTypeDlg, Buttons.Remove, new ShowDialog(NativeDialogs.VerifyReadyDlg)); project.SetNetFxPrerequisite(Condition.Net45_Installed, "Please install .Net FrameWork 4.5"); project.CustomUI = customUi; project.OutFileName = "PhotoSorterSetup"; project.PreserveTempFiles = true; project.ResolveWildCards(true); project.BuildMsi(); }
public static void Main() { /* new Dir(@"%ProgramFiles%\Pamya\Resources", new File(binaries,@"..\Pamya\Resources\Localise.eo-Eo.xaml"), new File(binaries,@"..\Pamya\Resources\Localise.ru-RU.xaml"), new File(binaries,@"..\Pamya\Resources\Localise.xaml") )*/ Feature binaries = new Feature("Pamya Binaries"); Feature docs = new Feature("Documentation"); var project = new Project("Pamya", new Dir(@"%ProgramFiles%\Pamya", new File(@"..\LICENSE"), new File(binaries,@"..\Pamya\bin\Release\Pamya.exe", new FileShortcut(binaries, "Pamya", @"%ProgramMenu%\Pamya") ), new File(binaries, @"..\Pamya\PamyaIcon.ico"), new File(binaries, @"..\Pamya\bin\Release\System.Data.SQLite.dll"), new File(binaries, @"..\Pamya\bin\Release\SQLite.Interop.dll"), new Dir(@"Resources", new File(binaries, @"..\Pamya\Resources\Localise.eo-Eo.xaml"), new File(binaries, @"..\Pamya\Resources\Localise.ru-RU.xaml"), new File(binaries, @"..\Pamya\Resources\Localise.xaml") ) ), //new Dir("%Startup%", // new ExeFileShortcut(binaries, "Pamya", "[INSTALLDIR]Pamya.exe", "")), new Dir(@"%ProgramMenu%\Pamya", new ExeFileShortcut(binaries, "Uninstall Pamya", "[System64Folder]msiexec.exe", "/x [ProductCode]")) ); project.GUID = new Guid("ad4e532e-5832-4ec8-bbff-09f3dfdcc427"); project.UI = WUI.WixUI_Mondo; project.SourceBaseDir = Environment.CurrentDirectory; project.OutFileName = "Pamya"; //Compiler.AllowNonRtfLicense = true; project.LicenceFile = @"..\LICENSE.rtf"; try { Compiler.BuildMsi(project); } catch (Exception ex) { Console.WriteLine(ex); } }
private static void Main(string[] args) { var dir = new DirectoryInfo(@"..\..\..\LightUpdater\bin\Release"); string exeFileFullName = dir.EnumerateFiles("*.exe").First().FullName; string exeFileName = Path.GetFileName(exeFileFullName); Assembly assembly = Assembly.LoadFile(exeFileFullName); string projectName = assembly.GetCustomAttributes<AssemblyTitleAttribute>().First().Title; var mainFeature = new Feature("Программа", true) { AllowChange = false, ConfigurableDir = "INSTALLDIR" }; var project = new Project(projectName, new Dir(mainFeature, InstallerHelper.GetSautProgramLocation(projectName), new Files(dir.FullName + "\\*.*", InstallerHelper.IsFileDesired)), // Shortcuts new Dir(mainFeature, @"%ProgramMenu%", new ExeFileShortcut(projectName, "[INSTALLDIR]" + exeFileName, "") { WorkingDirectory = "INSTALLDIR" }, new ExeFileShortcut(projectName + " (250 кбод)", "[INSTALLDIR]" + exeFileName, "/can1:250000 /can2:250000") { WorkingDirectory = "INSTALLDIR" } ), new Dir(mainFeature, "%Desktop%", new ExeFileShortcut(mainFeature, projectName, "[INSTALLDIR]" + exeFileName, "") { WorkingDirectory = "INSTALLDIR" } )) { DefaultFeature = mainFeature, OutDir = @"..\..\.." }; project.ResolveWildCards(true) .FindFile(f => f.Name.EndsWith(exeFileName)) .First() .AddAssociation(new FileAssociation("sfp", "application/firmware-package", "Прошить", "\"%1\"") { Icon = "sfp.ico", Description = "Файл пакета прошивки" }); project.SetBasicThings(new Guid("B390695C-291F-4B7F-8E13-1630F2BF12F1"), DotNetVersion.DotNet4); project.SetInterface(InstallerInterfaceKind.SelectDirectory); project.SetProjectInformation(assembly, @"..\..\..\LightUpdater\icon.ico", "https://repo.nposaut.ru/#/tools?tool=CanProg"); string msi = Compiler.BuildMsi(project); InstallerHelper.SignInstaller(msi); Console.ReadLine(); }
/// <summary> /// Binds the LaunchCondition to the <c>version</c> condition based on WiXNetFxExtension properties. /// <para>The typical conditions are:</para> /// <para> NETFRAMEWORK20='#1'</para> /// <para> NETFRAMEWORK40FULL='#1'</para> /// <para> NETFRAMEWORK35='#1'</para> /// <para> NETFRAMEWORK30_SP_LEVEL and NOT NETFRAMEWORK30_SP_LEVEL='#0'</para> /// <para> ...</para> /// The full list of names and values can be found here http://wixtoolset.org/documentation/manual/v3/customactions/wixnetfxextension.html /// </summary> /// <param name="project">The project.</param> /// <param name="versionCondition">Condition expression. /// </param> /// <param name="errorMessage">The error message to be displayed if .NET version is not present.</param> /// <returns></returns> static public Project SetNetFxPrerequisite(this WixSharp.Project project, string versionCondition, string errorMessage = null) { var condition = Condition.Create(versionCondition); string message = errorMessage ?? "Please install the appropriate .NET version first."; project.LaunchConditions.Add(new LaunchCondition(condition, message)); foreach (var prop in condition.GetDistinctProperties()) { project.Properties = project.Properties.Add(new PropertyRef(prop)); } project.IncludeWixExtension(WixExtension.NetFx); return(project); }
static public void Main(string[] args) { Dir directory = new Dir("AppDirectory"); directory.Files.Add(new File("readme.txt")); /*directory.Files.Add(new File(@"..\wixsh\bin\debug\wixsh.exe")); directory.Files.Add(new File(@"..\wixsh\bin\debug\wixsh.exe.config"));*/ var project = new Project("Wix# Test"); project.Dirs.Add(directory); /*project.Actions.Add(new InstalledFileAction("wixsh.exe", String.Empty, Return.check, When.After, Step.InstallFinalize, Condition.Installed));*/ project.Actions.Add(new ManagedAction("MyAction")); project.UI = WUI.WixUI_ProgressOnly; Compiler.BuildMsi(project); }
static void Main(string[] args) { Project project = new Project("MyWixProd", new Dir(new Id("INSTALL_DIR"), @"%ProgramFiles%\SharpTest", new File(new Id("wixplay.exe"), @"..\wixplay\bin\debug\wixplay.exe")), new Dir(@"%AppData%\Microsoft\Windows\Start Menu\Programs\Startup", new ExeFileShortcut(new Id("autorunShortcut"), "Build Monitor", "[INSTALL_DIR]wixplay.exe", String.Empty))) { Actions = new WixSharp.Action[] { new InstalledFileAction("wixplay.exe", "", Return.check, When.After, Step.InstallFinalize, Condition.NOT_Installed), }, GUID = new Guid("6f330b47-2577-43ad-9095-1861ba2588dd"), UI = WUI.WixUI_ProgressOnly }; Compiler.BuildMsi(project); }
static void Main(string[] args) { var project = new Project("rbpicman", new Dir(new Id("INSTALL_DIR"), @"%ProgramFiles%\rbpicman", new File(@"..\program\rbpicman.exe"), new File(@"..\shell\shellext.dll"), new File( @"..\program\ScreenshotTaker.dll" ), new ExeFileShortcut("Uninstall rbpicman", "[System64Folder]msiexec.exe", "/x [ProductCode]")), new Dir(@"%ProgramMenu%\rbpicman", new ExeFileShortcut("rbpicman", "[INSTALL_DIR]rbpicman.exe", ""), new ExeFileShortcut("Uninstall rbpicman", "[System64Folder]msiexec.exe", "/x [ProductCode]")), new Dir(@"%Desktop%", new ExeFileShortcut("rbpicman", "[INSTALL_DIR]rbpicman.exe", "")), new RegValue(RegistryHive.LocalMachine, "Software\\rbpicman", "", "[INSTALL_DIR]rbpicman.exe"), new RegValue(RegistryHive.CurrentUser, "Software\\rbpicman", "", "[INSTALL_DIR]rbpicman.exe"), new RegValue(RegistryHive.ClassesRoot, "CLSID\\{51B4D7E5-7568-4234-B4BB-47FB3C016A69}\\InprocServer32", "", "[INSTALL_DIR]shellext.dll"), new RegValue(RegistryHive.ClassesRoot, "CLSID\\{51B4D7E5-7568-4234-B4BB-47FB3C016A69}\\InprocServer32", "ThreadingModel", "Apartment"), new RegValue(RegistryHive.ClassesRoot, "*\\ShellEx\\ContextMenuHandlers\\rbpicman", "", "{51B4D7E5-7568-4234-B4BB-47FB3C016A69}"), new Property("ALLUSERS", "1")); project.GUID = new Guid("ccc0ac05-7ec8-42d6-882a-ffdffa31fbdd"); project.UI = WUI.WixUI_InstallDir; project.Version = new Version("1.1.0.0"); project.LicenceFile = @"..\..\license.rtf"; //project.Codepage = "UTF-8"; project.MajorUpgradeStrategy = MajorUpgradeStrategy.Default; project.MajorUpgradeStrategy.RemoveExistingProductAfter = Step.InstallInitialize; project.ControlPanelInfo.Comments = "Simple picture manager"; project.ControlPanelInfo.Readme = "https://github.com/rbobot/rbpicman"; project.ControlPanelInfo.Contact = "*****@*****.**"; project.ControlPanelInfo.Manufacturer = "Demidko Anatoly"; project.ControlPanelInfo.InstallLocation = "[INSTALL_DIR]"; project.ControlPanelInfo.NoModify = true; Compiler.WixSourceGenerated += doc => doc.Root .Select("Product/Upgrade/UpgradeVersion") .AddAttributes("MigrateFeatures=yes"); Compiler.PreserveTempFiles = true; Compiler.BuildMsi(project); }
private static void Main() { const string mode = #if DEBUG "Debug"; #elif FULL "Full"; #else "Release"; #endif const string rootSolutionDirectory = @"..\.."; var octoStyleOutputPath = Path.Combine(rootSolutionDirectory, @"src\OctoStyle.Console\bin\", mode); var project = new Project( "OctoStyle", new Dir( @"%ProgramFiles%\Omego2K\OctoStyle", new File(Path.Combine(octoStyleOutputPath, "OctoStyle.Console.exe")), new File(Path.Combine(octoStyleOutputPath, "OctoStyle.Core.dll")), new File(Path.Combine(octoStyleOutputPath, "NDesk.Options.dll")), new File(Path.Combine(octoStyleOutputPath, "Octokit.dll")), new File(Path.Combine(octoStyleOutputPath, "StyleCop.CSharp.Rules.dll")), new File(Path.Combine(octoStyleOutputPath, "StyleCop.dll")), new File(Path.Combine(octoStyleOutputPath, "StyleCop.CSharp.dll")), new File(Path.Combine(octoStyleOutputPath, "OMetaSharp.dll")), new File(Path.Combine(octoStyleOutputPath, "SharpDiff.dll")))); project.GenerateProductGuids(); project.MajorUpgradeStrategy = MajorUpgradeStrategy.Default; const string wixToolsLocation = @"packages\WiX.3.9.2\tools"; Compiler.WixLocation = Path.Combine(rootSolutionDirectory, wixToolsLocation); Compiler.WixSdkLocation = Path.Combine(rootSolutionDirectory, wixToolsLocation, "sdk"); Compiler.BuildMsi(project); }
static void Main( string[] args ) { var project = new Project( "rbscan", new Dir( new Id( "INSTALL_DIR" ), @"%ProgramFiles%\rbscan", new File( @"..\binary\program\PdfFileWriter.dll" ), new File( @"..\binary\program\rbscan.exe" ), new ExeFileShortcut( "Uninstall rbscan", "[System64Folder]msiexec.exe", "/x [ProductCode]" ) ), new Dir( @"%ProgramMenu%\rbscan", new ExeFileShortcut( "rbscan", "[INSTALL_DIR]rbscan.exe", "" ), new ExeFileShortcut( "Uninstall rbscan", "[System64Folder]msiexec.exe", "/x [ProductCode]" ) ), new Dir( @"%Desktop%", new ExeFileShortcut( "rbscan", "[INSTALL_DIR]rbscan.exe", "" ) ), new Property( "ALLUSERS", "1" ) ); project.GUID = new Guid( "3cdfc447-0d87-44e0-be1d-f6ef928fe6c5" ); project.UI = WUI.WixUI_InstallDir; project.Version = new Version( "2.0.0.0" ); project.LicenceFile = @"..\license.rtf"; project.MajorUpgradeStrategy = MajorUpgradeStrategy.Default; project.MajorUpgradeStrategy.RemoveExistingProductAfter = Step.InstallInitialize; project.ControlPanelInfo.Comments = "Simple WIA Scan application"; project.ControlPanelInfo.Readme = "https://github.com/rbobot/rbscan"; project.ControlPanelInfo.Contact = "*****@*****.**"; project.ControlPanelInfo.Manufacturer = "Demidko Anatoly"; project.ControlPanelInfo.InstallLocation = "[INSTALL_DIR]"; project.ControlPanelInfo.NoModify = true; Compiler.WixSourceGenerated += doc => doc.Root .Select( "Product/Upgrade/UpgradeVersion" ) .AddAttributes( "MigrateFeatures=yes" ); Compiler.PreserveTempFiles = true; Compiler.BuildMsi( project ); }
/// <summary> /// Generates WiX XML source file the specified <see cref="Project"/> instance. /// </summary> /// <param name="project">The <see cref="Project"/> instance.</param> /// <returns>Instance of XDocument class representing in-memory WiX XML source file.</returns> public static XDocument GenerateWixProj(Project project) { project.Preprocess(); ProjectValidator.Validate(project); project.ControlPanelInfo.AddMembersTo(project); project.AutoAssignedInstallDirPath = ""; project.GenerateProductGuids(); ResetCachedContent(); string extraNamespaces = project.WixNamespaces.Distinct() .Select(x => x.StartsWith("xmlns:") ? x : "xmlns:" + x) .ConcatItems(" "); XDocument doc = XDocument.Parse( @"<?xml version=""1.0"" encoding=""utf-8""?> <Wix xmlns=""http://schemas.microsoft.com/wix/2006/wi"" " + extraNamespaces + @"> <Product> <Package InstallerVersion=""200"" Compressed=""yes""/> <Media Id=""1"" Cabinet=""" + (project as WixEntity).Id + @".cab"" EmbedCab=""yes"" /> </Product> </Wix>"); XElement product = doc.Root.Select("Product"); product.Add(new XAttribute("Id", project.ProductId), new XAttribute("Name", project.Name), new XAttribute("Language", new CultureInfo(project.Language).LCID), new XAttribute("Codepage", project.Codepage), new XAttribute("Version", project.Version), new XAttribute("UpgradeCode", project.UpgradeCode)); if (project.ControlPanelInfo != null && project.ControlPanelInfo.Manufacturer.IsNotEmpty()) product.SetAttribute("Manufacturer", project.ControlPanelInfo.Manufacturer); product.AddAttributes(project.Attributes); XElement package = product.Select("Package"); package.SetAttribute("Description", project.Description) .SetAttribute("Platform", project.Platform) .SetAttribute("SummaryCodepage", project.Codepage) .SetAttribute("Languages", new CultureInfo(project.Language).LCID) .SetAttribute("InstallScope", project.InstallScope); if (project.EmitConsistentPackageId) package.CopyAttributeFrom(product, "Id"); package.AddAttributes(project.Package.Attributes); product.Select("Media").AddAttributes(project.Media.Attributes); ProcessLaunchConditions(project, product); //extend wDir XElement dirs = product.AddElement( new XElement("Directory", new XAttribute("Id", "TARGETDIR"), new XAttribute("Name", "SourceDir"))); var featureComponents = new Dictionary<Feature, List<string>>(); //feature vs. component IDs var autoGeneratedComponents = new List<string>(); //component IDs var defaultFeatureComponents = new List<string>(); //default Feature (Complete setup) components ProcessDirectories(project, featureComponents, defaultFeatureComponents, autoGeneratedComponents, dirs); ProcessRegKeys(project, featureComponents, defaultFeatureComponents, product); ProcessEnvVars(project, featureComponents, defaultFeatureComponents, product); ProcessUsers(project, featureComponents, defaultFeatureComponents, product); ProcessSql(project, featureComponents, defaultFeatureComponents, product); ProcessCertificates(project, featureComponents, defaultFeatureComponents, product); ProcessProperties(project, product); ProcessCustomActions(project, product); ProcessBinaries(project, product); //it is important to call ProcessBinaries after all other ProcessX as they may insert some implicit "binaries" ProcessFeatures(project, product, featureComponents, autoGeneratedComponents, defaultFeatureComponents); //special properties if (project.UI != WUI.WixUI_ProgressOnly) { XElement installDir = GetTopLevelDir(product); //if UIRef is set to WIXUI_INSTALLDIR must also add //<Property Id="WIXUI_INSTALLDIR" Value="directory id" /> if (project.UI == WUI.WixUI_InstallDir) product.Add(new XElement("Property", new XAttribute("Id", "WIXUI_INSTALLDIR"), new XAttribute("Value", installDir.Attribute("Id").Value))); product.Add(new XElement("UIRef", new XAttribute("Id", project.UI.ToString()))); var extensionAssembly = Utils.PathCombine(WixLocation, @"WixUIExtension.dll"); if (project.WixExtensions.Find(x => x == extensionAssembly) == null) project.WixExtensions.Add(extensionAssembly); } if (project.EmbeddedUI != null) { string bynaryPath = project.EmbeddedUI.Name; if (project.EmbeddedUI is EmbeddedAssembly) { var asmBin = project.EmbeddedUI as EmbeddedAssembly; bynaryPath = asmBin.Name.PathChangeDirectory(project.OutDir.PathGetFullPath()) .PathChangeExtension(".CA.dll"); var refAsms = asmBin.RefAssemblies.Add(typeof(Session).Assembly.Location) .Concat(project.DefaultRefAssemblies) .Distinct() .ToArray(); PackageManagedAsm(asmBin.Name, bynaryPath, refAsms, project.OutDir, project.CustomActionConfig); } product.AddElement("UI") .Add(new XElement("EmbeddedUI", new XAttribute("Id", project.EmbeddedUI.Id), new XAttribute("SourceFile", bynaryPath))); product.Select("UIRef").Remove(); } if (!project.BannerImage.IsEmpty()) { product.Add(new XElement("WixVariable", new XAttribute("Id", "WixUIBannerBmp"), new XAttribute("Value", Utils.PathCombine(project.SourceBaseDir, project.BannerImage)))); } if (!project.BackgroundImage.IsEmpty()) { product.Add(new XElement("WixVariable", new XAttribute("Id", "WixUIDialogBmp"), new XAttribute("Value", Utils.PathCombine(project.SourceBaseDir, project.BackgroundImage)))); } if (!project.LicenceFile.IsEmpty()) { if (!AllowNonRtfLicense && !project.LicenceFile.EndsWith(".rtf", StringComparison.OrdinalIgnoreCase)) throw new ApplicationException("License file must have 'rtf' file extension. Specify 'Compiler.AllowNonRtfLicense=true' to overcome this constrain."); product.Add( new XElement("WixVariable", new XAttribute("Id", "WixUILicenseRtf"), new XAttribute("Value", Utils.PathCombine(project.SourceBaseDir, project.LicenceFile)), new XAttribute("xmlns", ""))); } PostProcessMsm(project, product); ProcessUpgradeStrategy(project, product); return doc; }
/// <summary> /// Builds the WiX source file (*.wxs) from the specified <see cref="Project"/> instance. /// </summary> /// <param name="project">The <see cref="Project"/> instance.</param> /// <param name="type">The type (<see cref="OutputType"/>) of the setup file to be defined in the source file (MSI vs. MSM).</param> /// <returns>Path to the built WXS file.</returns> public static string BuildWxs(Project project, OutputType type) { //very important to keep "ClientAssembly = " in all "public Build*" methods to ensure GetCallingAssembly //returns the build script assembly but not just another method of Compiler. if (ClientAssembly.IsEmpty()) ClientAssembly = System.Reflection.Assembly.GetCallingAssembly().Location; WixEntity.ResetIdGenerator(); string file = IO.Path.GetFullPath(IO.Path.Combine(project.OutDir, project.OutFileName) + ".wxs"); if (IO.File.Exists(file)) IO.File.Delete(file); BuildWxs(project, file, type); return file; }
/// <summary> /// Builds the WiX source file (*.wxs) from the specified <see cref="Project"/> instance. /// </summary> /// <param name="project">The <see cref="Project"/> instance.</param> /// <param name="path">The path to the WXS file to be build.</param> /// <param name="type">The type (<see cref="OutputType"/>) of the setup file to be defined in the source file (MSI vs. MSM).</param> /// <returns>Path to the built WXS file.</returns> public static string BuildWxs(Project project, string path, OutputType type) { //very important to keep "ClientAssembly = " in all "public Build*" methods to ensure GetCallingAssembly //returns the build script assembly but not just another method of Compiler. if (ClientAssembly.IsEmpty()) ClientAssembly = System.Reflection.Assembly.GetCallingAssembly().Location; XDocument doc = GenerateWixProj(project); IndjectCustomUI(project.CustomUI, doc); DefaultWixSourceGeneratedHandler(doc); AutoElements.InjectAutoElementsHandler(doc); AutoElements.NormalizeFilePaths(doc, project.SourceBaseDir, EmitRelativePaths); if (type == OutputType.MSM) { //remove all pure MSI elements ConvertMsiToMsm(doc); } project.InvokeWixSourceGenerated(doc); if (WixSourceGenerated != null) WixSourceGenerated(doc); string xml = ""; using (IO.StringWriter sw = new StringWriterWithEncoding(project.Encoding)) { doc.Save(sw, SaveOptions.None); xml = sw.ToString(); } //of course you can use XmlTextWriter.WriteRaw but this is just a temporary quick'n'dirty solution //http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2657663&SiteID=1 xml = xml.Replace("xmlns=\"\"", ""); DefaultWixSourceFormatedHandler(ref xml); project.InvokeWixSourceFormated(ref xml); if (WixSourceFormated != null) WixSourceFormated(ref xml); using (var sw = new IO.StreamWriter(path, false, project.Encoding)) sw.WriteLine(xml); Console.WriteLine("\n----------------------------------------------------------\n"); Console.WriteLine("Wix project file has been built: " + path + "\n"); project.InvokeWixSourceSaved(path); if (WixSourceSaved != null) WixSourceSaved(path); return path; }
static void Build(Project project, string path, OutputType type) { string oldCurrDir = Environment.CurrentDirectory; try { //System.Diagnostics.Debug.Assert(false); Compiler.TempFiles.Clear(); string compiler = Utils.PathCombine(WixLocation, @"candle.exe"); string linker = Utils.PathCombine(WixLocation, @"light.exe"); if (!IO.File.Exists(compiler) || !IO.File.Exists(linker)) { Console.WriteLine("Wix binaries cannot be found. Expected location is " + IO.Path.GetDirectoryName(compiler)); throw new ApplicationException("Wix compiler/linker cannot be found"); } else { string wxsFile = BuildWxs(project, type); if (autogeneratedWxsForVS != null) CopyAsAutogen(wxsFile, autogeneratedWxsForVS); if (!project.SourceBaseDir.IsEmpty()) Environment.CurrentDirectory = project.SourceBaseDir; string objFile = IO.Path.ChangeExtension(wxsFile, ".wixobj"); string pdbFile = IO.Path.ChangeExtension(wxsFile, ".wixpdb"); string extensionDlls = ""; foreach (string dll in project.WixExtensions.Distinct()) extensionDlls += " -ext \"" + dll + "\""; var candleOptions = CandleOptions + " " + project.CandleOptions; var lightOptions = LightOptions + " " + project.LightOptions; //AppDomain.CurrentDomain.ExecuteAssembly(compiler, null, new string[] { projFile }); //a bit unsafer version Run(compiler, candleOptions + " " + extensionDlls + " \"" + wxsFile + "\" -out \"" + objFile + "\""); if (IO.File.Exists(objFile)) { string msiFile = IO.Path.ChangeExtension(wxsFile, "." + type.ToString().ToLower()); if (IO.File.Exists(msiFile)) IO.File.Delete(msiFile); if (project.IsLocalized && IO.File.Exists(project.LocalizationFile)) Run(linker, lightOptions + " \"" + objFile + "\" -out \"" + msiFile + "\"" + extensionDlls + " -cultures:" + project.Language + " -loc \"" + project.LocalizationFile + "\""); else Run(linker, lightOptions + " \"" + objFile + "\" -out \"" + msiFile + "\"" + extensionDlls + " -cultures:" + project.Language); if (IO.File.Exists(msiFile)) { Compiler.TempFiles.Add(wxsFile); Console.WriteLine("\n----------------------------------------------------------\n"); Console.WriteLine(type + " file has been built: " + path + "\n"); Console.WriteLine((type == OutputType.MSI ? " ProductName: " : " ModuleName: ") + project.Name); Console.WriteLine(" Version : " + project.Version); Console.WriteLine(" ProductId : {" + project.ProductId + "}"); Console.WriteLine(" UpgradeCode: {" + project.UpgradeCode + "}\n"); if (!project.AutoAssignedInstallDirPath.IsEmpty()) { Console.WriteLine(" Auto-generated InstallDir ID:"); Console.WriteLine(" " + Compiler.AutoGeneration.InstallDirDefaultId + "=" + project.AutoAssignedInstallDirPath); } IO.File.Delete(objFile); IO.File.Delete(pdbFile); if (path != msiFile) { if (IO.File.Exists(path)) IO.File.Delete(path); IO.File.Move(msiFile, path); } } } else { Console.WriteLine("Cannot build " + wxsFile); Trace.WriteLine("Cannot build " + wxsFile); } } if (!PreserveTempFiles && !project.PreserveTempFiles) foreach (var file in Compiler.TempFiles) try { if (IO.File.Exists(file)) IO.File.Delete(file); } catch { } } finally { Environment.CurrentDirectory = oldCurrDir; } }
/// <summary> /// Builds the WiX source file (*.wxs) from the specified <see cref="Project"/> instance for further compiling into MSI file. /// </summary> /// <param name="project">The <see cref="Project"/> instance.</param> /// <returns>Path to the built WXS file.</returns> public static string BuildWxs(Project project) { //very important to keep "ClientAssembly = " in all "public Build*" methods to ensure GetCallingAssembly //returns the build script assembly but not just another method of Compiler. if (ClientAssembly.IsEmpty()) ClientAssembly = System.Reflection.Assembly.GetCallingAssembly().Location; return BuildWxs(project, OutputType.MSI); }
/// <summary> /// Builds the WiX source file and generates batch file capable of building /// MSM with WiX toolset. /// </summary> /// <param name="project">The <see cref="Project"/> instance.</param> /// <returns>Path to the batch file.</returns> static public string BuildMsmCmd(Project project) { //very important to keep "ClientAssembly = " in all "public Build*" methods to ensure GetCallingAssembly //returns the build script assembly but not just another method of Compiler. if (ClientAssembly.IsEmpty()) ClientAssembly = System.Reflection.Assembly.GetCallingAssembly().Location; string cmdFile = IO.Path.GetFullPath(IO.Path.Combine(project.OutDir, "Build_" + project.OutFileName) + ".cmd"); if (IO.File.Exists(cmdFile)) IO.File.Delete(cmdFile); BuildMsmCmd(project, cmdFile); return cmdFile; }
static void BuildCmd(Project project, string path, OutputType type) { //very important to keep "ClientAssembly = " in all "public Build*" methods to ensure GetCallingAssembly //returns the build script assembly but not just another method of Compiler. if (ClientAssembly.IsEmpty()) ClientAssembly = System.Reflection.Assembly.GetCallingAssembly().Location; string compiler = Utils.PathCombine(WixLocation, "candle.exe"); string linker = Utils.PathCombine(WixLocation, "light.exe"); string batchFile = path; if (!IO.File.Exists(compiler) && !IO.File.Exists(linker)) { Console.WriteLine("Wix binaries cannot be found. Expected location is " + IO.Path.GetDirectoryName(compiler)); throw new ApplicationException("Wix compiler/linker cannot be found"); } else { string wxsFile = BuildWxs(project, type); string objFile = IO.Path.GetFileNameWithoutExtension(wxsFile) + ".wixobj"; string extensionDlls = ""; foreach (string dll in project.WixExtensions.Distinct()) extensionDlls += " -ext \"" + ResolveExtensionFile(dll) + "\""; var candleOptions = CandleOptions + " " + project.CandleOptions; var lightOptions = LightOptions + " " + project.LightOptions; string batchFileContent = "\"" + compiler + "\" " + candleOptions + " " + extensionDlls + " \"" + IO.Path.GetFileName(wxsFile) + "\"\r\n"; if (project.IsLocalized && IO.File.Exists(project.LocalizationFile)) batchFileContent += "\"" + linker + "\" " + lightOptions + " \"" + objFile + "\" " + extensionDlls + " -cultures:" + project.Language + " -loc " + project.LocalizationFile + "\r\npause"; else batchFileContent += "\"" + linker + "\" " + lightOptions + " \"" + objFile + "\" " + extensionDlls + " -cultures:" + project.Language + "\r\npause"; using (var sw = new IO.StreamWriter(batchFile)) sw.Write(batchFileContent); } }
/// <summary> /// Processes the custom actions. /// </summary> /// <param name="wProject">The w project.</param> /// <param name="product">The product.</param> /// <exception cref="System.Exception">Step.PreviousAction is specified for the very first 'Custom Action'.\nThere cannot be any previous action as it is the very first one in the sequence.</exception> static void ProcessCustomActions(Project wProject, XElement product) { string lastActionName = null; foreach (Action wAction in wProject.Actions) { string step = wAction.Step.ToString(); if (wAction.When == When.After && wAction.Step == Step.PreviousAction) { if (lastActionName == null) throw new Exception("Step.PreviousAction is specified for the very first 'Custom Action'.\nThere cannot be any previous action as it is the very first one in the sequence."); step = lastActionName; } else if (wAction.When == When.After && wAction.Step == Step.PreviousActionOrInstallFinalize) step = lastActionName ?? Step.InstallFinalize.ToString(); else if (wAction.When == When.After && wAction.Step == Step.PreviousActionOrInstallInitialize) step = lastActionName ?? Step.InstallInitialize.ToString(); lastActionName = wAction.Name.Expand(); List<XElement> sequences = new List<XElement>(); if (wAction.Sequence != Sequence.NotInSequence) { foreach (var item in wAction.Sequence.GetValues()) sequences.Add(product.SelectOrCreate(item)); } XAttribute sequenceNumberAttr = wAction.SequenceNumber.HasValue ? new XAttribute("Sequence", wAction.SequenceNumber.Value) : new XAttribute(wAction.When.ToString(), step); if (wAction is SetPropertyAction) { var wSetPropAction = (SetPropertyAction)wAction; var actionId = wSetPropAction.Id; lastActionName = actionId; //overwrite previously set standard CA name product.AddElement( new XElement("CustomAction", new XAttribute("Id", actionId), new XAttribute("Property", wSetPropAction.PropName), new XAttribute("Value", wSetPropAction.Value)) .AddAttributes(wSetPropAction.Attributes)); sequences.ForEach(sequence => sequence.Add(new XElement("Custom", wAction.Condition.ToString(), new XAttribute("Action", actionId), sequenceNumberAttr))); } else if (wAction is ScriptFileAction) { var wScriptAction = (ScriptFileAction)wAction; sequences.ForEach(sequence => sequence.Add(new XElement("Custom", wAction.Condition.ToString(), new XAttribute("Action", wAction.Id), sequenceNumberAttr))); product.Add(new XElement("Binary", new XAttribute("Id", wAction.Name.Expand() + "_File"), new XAttribute("SourceFile", Utils.PathCombine(wProject.SourceBaseDir, wScriptAction.ScriptFile)))); product.Add(new XElement("CustomAction", new XAttribute("Id", wAction.Name.Expand()), new XAttribute("BinaryKey", wAction.Name.Expand() + "_File"), new XAttribute("VBScriptCall", wScriptAction.Procedure), new XAttribute("Return", wAction.Return)) .AddAttributes(wAction.Attributes)); } else if (wAction is ScriptAction) { var wScriptAction = (ScriptAction)wAction; sequences.ForEach(sequence => sequence.Add(new XElement("Custom", wAction.Condition.ToString(), new XAttribute("Action", wAction.Id), sequenceNumberAttr))); product.Add(new XElement("CustomAction", new XCData(wScriptAction.Code), new XAttribute("Id", wAction.Name.Expand()), new XAttribute("Script", "vbscript"), new XAttribute("Return", wAction.Return)) .AddAttributes(wAction.Attributes)); } else if (wAction is ManagedAction) { var wManagedAction = (ManagedAction)wAction; var asmFile = Utils.PathCombine(wProject.SourceBaseDir, wManagedAction.ActionAssembly); var packageFile = asmFile.PathChangeDirectory(wProject.OutDir.PathGetFullPath()) .PathChangeExtension(".CA.dll"); var existingBinary = product.Descendants("Binary") .Where(e => e.Attribute("SourceFile").Value == packageFile) .FirstOrDefault(); string bynaryKey; if (existingBinary == null) { PackageManagedAsm( asmFile, packageFile, wManagedAction.RefAssemblies.Concat(wProject.DefaultRefAssemblies).Distinct().ToArray(), wProject.OutDir, wProject.CustomActionConfig, wProject.Platform); bynaryKey = wAction.Name.Expand() + "_File"; product.Add(new XElement("Binary", new XAttribute("Id", bynaryKey), new XAttribute("SourceFile", packageFile))); } else { bynaryKey = existingBinary.Attribute("Id").Value; } if (wManagedAction.Execute == Execute.deferred && wManagedAction.UsesProperties != null) //map managed action properties { string mapping = wManagedAction.ExpandAllUsedProperties(); if (!mapping.IsEmpty()) { var setPropValuesId = "Set_" + wAction.Id + "_Props"; product.Add(new XElement("CustomAction", new XAttribute("Id", setPropValuesId), new XAttribute("Property", wAction.Id), new XAttribute("Value", mapping))); sequences.ForEach(sequence => sequence.Add( new XElement("Custom", new XAttribute("Action", setPropValuesId), wAction.SequenceNumber.HasValue ? new XAttribute("Sequence", wAction.SequenceNumber.Value) : new XAttribute("After", "InstallInitialize")))); } } sequences.ForEach(sequence => sequence.Add(new XElement("Custom", wAction.Condition.ToString(), new XAttribute("Action", wAction.Id), sequenceNumberAttr))); product.Add(new XElement("CustomAction", new XAttribute("Id", wAction.Id), new XAttribute("BinaryKey", bynaryKey), new XAttribute("DllEntry", wManagedAction.MethodName), new XAttribute("Impersonate", wAction.Impersonate.ToYesNo()), new XAttribute("Execute", wAction.Execute), new XAttribute("Return", wAction.Return)) .AddAttributes(wAction.Attributes)); } else if (wAction is QtCmdLineAction) { var cmdLineAction = (QtCmdLineAction)wAction; var cmdLineActionId = wAction.Name.Expand(); var setCmdLineActionId = "Set_" + cmdLineActionId + "_CmdLine"; product.AddElement( new XElement("CustomAction", new XAttribute("Id", setCmdLineActionId), new XAttribute("Property", "QtExecCmdLine"), new XAttribute("Value", "\"" + cmdLineAction.AppPath.ExpandCommandPath() + "\" " + cmdLineAction.Args.ExpandCommandPath())) .AddAttributes(cmdLineAction.Attributes)); product.AddElement( new XElement("CustomAction", new XAttribute("Id", cmdLineActionId), new XAttribute("BinaryKey", "WixCA"), new XAttribute("DllEntry", "CAQuietExec"), new XAttribute("Impersonate", wAction.Impersonate.ToYesNo()), new XAttribute("Execute", wAction.Execute), new XAttribute("Return", wAction.Return))); lastActionName = cmdLineActionId; sequences.ForEach(sequence => sequence.Add( new XElement("Custom", wAction.Condition.ToString(), new XAttribute("Action", setCmdLineActionId), sequenceNumberAttr))); sequences.ForEach(sequence => sequence.Add( new XElement("Custom", wAction.Condition.ToString(), new XAttribute("Action", cmdLineActionId), new XAttribute("After", setCmdLineActionId)))); var extensionAssembly = Utils.PathCombine(WixLocation, @"WixUtilExtension.dll"); if (wProject.WixExtensions.Find(x => x == extensionAssembly) == null) wProject.WixExtensions.Add(extensionAssembly); } else if (wAction is InstalledFileAction) { var fileAction = (InstalledFileAction)wAction; sequences.ForEach(sequence => sequence.Add( new XElement("Custom", wAction.Condition.ToString(), new XAttribute("Action", wAction.Id), sequenceNumberAttr))); var actionElement = product.AddElement( new XElement("CustomAction", new XAttribute("Id", wAction.Name.Expand()), new XAttribute("ExeCommand", fileAction.Args.ExpandCommandPath()), new XAttribute("Return", wAction.Return)) .AddAttributes(wAction.Attributes)); actionElement.Add(new XAttribute("FileKey", fileAction.Key)); } else if (wAction is BinaryFileAction) { var binaryAction = (BinaryFileAction)wAction; sequences.ForEach(sequence => sequence.Add( new XElement("Custom", wAction.Condition.ToString(), new XAttribute("Action", wAction.Id), sequenceNumberAttr))); var actionElement = product.AddElement( new XElement("CustomAction", new XAttribute("Id", wAction.Name.Expand()), new XAttribute("ExeCommand", binaryAction.Args.ExpandCommandPath()), new XAttribute("Impersonate", wAction.Impersonate.ToYesNo()), new XAttribute("Execute", wAction.Execute), new XAttribute("Return", wAction.Return)) .AddAttributes(wAction.Attributes)); actionElement.Add(new XAttribute("BinaryKey", binaryAction.Key)); } else if (wAction is PathFileAction) { var fileAction = (PathFileAction)wAction; sequences.ForEach(sequence => sequence.Add( new XElement("Custom", fileAction.Condition.ToString(), new XAttribute("Action", fileAction.Id), sequenceNumberAttr))); var actionElement = product.AddElement( new XElement("CustomAction", new XAttribute("Id", fileAction.Name.Expand()), new XAttribute("ExeCommand", "\"" + fileAction.AppPath.ExpandCommandPath() + "\" " + fileAction.Args.ExpandCommandPath()), new XAttribute("Return", wAction.Return)) .AddAttributes(fileAction.Attributes)); Dir installedDir = Array.Find(wProject.Dirs, (x) => x.Name == fileAction.WorkingDir); if (installedDir != null) actionElement.Add(new XAttribute("Directory", installedDir.Id)); else actionElement.Add(new XAttribute("Directory", fileAction.WorkingDir.Expand())); } } }
static string Build(Project project, OutputType type) { string outFile = IO.Path.GetFullPath(IO.Path.Combine(project.OutDir, project.OutFileName) + "." + type.ToString().ToLower()); Utils.EnsureFileDir(outFile); if (IO.File.Exists(outFile)) IO.File.Delete(outFile); Build(project, outFile, type); return IO.File.Exists(outFile) ? outFile : null; }
static void ProcessProperties(Project wProject, XElement product) { foreach (var prop in wProject.Properties) { if (prop is PropertyRef) { var propRef = (prop as PropertyRef); if (propRef.Id.IsEmpty()) throw new Exception("'" + typeof(PropertyRef).Name + "'.Id must be set before compiling the project."); product.Add(new XElement("PropertyRef", new XAttribute("Id", propRef.Id))); } else if (prop is RegValueProperty) { var rvProp = (prop as RegValueProperty); XElement RegistrySearchElement; XElement xProp = product.AddElement( new XElement("Property", new XAttribute("Id", rvProp.Name), RegistrySearchElement = new XElement("RegistrySearch", new XAttribute("Id", rvProp.Name + "_RegSearch"), new XAttribute("Root", rvProp.Root.ToWString()), new XAttribute("Key", rvProp.Key), new XAttribute("Type", "raw") )) .AddAttributes(rvProp.Attributes)); if (!rvProp.Value.IsEmpty()) xProp.Add(new XAttribute("Value", rvProp.Value)); if (rvProp.EntryName != "") RegistrySearchElement.Add(new XAttribute("Name", rvProp.EntryName)); } else { product.Add(new XElement("Property", new XAttribute("Id", prop.Name), new XAttribute("Value", prop.Value)) .AddAttributes(prop.Attributes)); } } }
static void ProcessBinaries(Project wProject, XElement product) { foreach (var bin in wProject.Binaries) { string bynaryKey = bin.Id; string bynaryPath = bin.Name; if (bin is EmbeddedAssembly) { var asmBin = bin as EmbeddedAssembly; bynaryPath = asmBin.Name.PathChangeDirectory(wProject.OutDir.PathGetFullPath()) .PathChangeExtension(".CA.dll"); PackageManagedAsm(asmBin.Name, bynaryPath, asmBin.RefAssemblies.Concat(wProject.DefaultRefAssemblies).Distinct().ToArray(), wProject.OutDir, wProject.CustomActionConfig); } product.Add(new XElement("Binary", new XAttribute("Id", bynaryKey), new XAttribute("SourceFile", bynaryPath)) .AddAttributes(bin.Attributes)); } }
static void InsertIISElements(XElement dirItem, XElement component, IISVirtualDir[] wVDirs, Project project) { //http://ranjithk.com/2009/12/17/automating-web-deployment-using-windows-installer-xml-wix/ XNamespace ns = "http://schemas.microsoft.com/wix/IIsExtension"; string dirID = dirItem.Attribute("Id").Value; var xProduct = component.Parent("Product"); var uniqueWebSites = new List<WebSite>(); bool wasInserted = true; foreach (IISVirtualDir wVDir in wVDirs) { wasInserted = true; XElement xWebApp; var xVDir = component.AddElement(new XElement(ns + "WebVirtualDir", new XAttribute("Id", wVDir.Name.Expand()), new XAttribute("Alias", wVDir.Alias.IsEmpty() ? wVDir.Name : wVDir.Alias), new XAttribute("Directory", dirID), new XAttribute("WebSite", wVDir.WebSite.Name.Expand()), xWebApp = new XElement(ns + "WebApplication", new XAttribute("Id", wVDir.AppName.Expand() + "WebApplication"), new XAttribute("Name", wVDir.AppName)))); if (wVDir.AllowSessions.HasValue) xWebApp.Add(new XAttribute("AllowSessions", wVDir.AllowSessions.Value.ToYesNo())); if (wVDir.Buffer.HasValue) xWebApp.Add(new XAttribute("Buffer", wVDir.Buffer.Value.ToYesNo())); if (wVDir.ClientDebugging.HasValue) xWebApp.Add(new XAttribute("ClientDebugging", wVDir.ClientDebugging.Value.ToYesNo())); if (wVDir.DefaultScript.HasValue) xWebApp.Add(new XAttribute("DefaultScript", wVDir.DefaultScript.Value.ToString())); if (wVDir.Isolation.HasValue) xWebApp.Add(new XAttribute("Isolation", wVDir.Isolation.Value.ToString())); if (wVDir.ParentPaths.HasValue) xWebApp.Add(new XAttribute("ParentPaths", wVDir.ParentPaths.Value.ToYesNo())); if (wVDir.ScriptTimeout.HasValue) xWebApp.Add(new XAttribute("ScriptTimeout", wVDir.ScriptTimeout.Value)); if (wVDir.ServerDebugging.HasValue) xWebApp.Add(new XAttribute("ServerDebugging", wVDir.ServerDebugging.Value.ToYesNo())); if (wVDir.SessionTimeout.HasValue) xWebApp.Add(new XAttribute("SessionTimeout", wVDir.SessionTimeout.Value)); //do not create WebSite on IIS but install WebApp into existing if (!wVDir.WebSite.InstallWebSite) { if (!uniqueWebSites.Contains(wVDir.WebSite)) uniqueWebSites.Add(wVDir.WebSite); } else { InsertWebSite(wVDir.WebSite, dirID, component); } if (wVDir.WebAppPool != null) { var id = wVDir.Name.Expand() + "_AppPool"; xWebApp.Add(new XAttribute("WebAppPool", id)); var xAppPool = component.AddElement(new XElement(ns + "WebAppPool", new XAttribute("Id", id), new XAttribute("Name", wVDir.WebAppPool.Name))); xAppPool.AddAttributes(wVDir.WebAppPool.Attributes); } if (wVDir.WebDirProperties != null) { var propId = wVDir.Name.Expand() + "_WebDirProperties"; var xDirProp = xProduct.AddElement(new XElement(ns + "WebDirProperties", new XAttribute("Id", propId))); xDirProp.AddAttributes(wVDir.WebDirProperties.Attributes); xVDir.Add(new XAttribute("DirProperties", propId)); } } foreach (WebSite webSite in uniqueWebSites) { InsertWebSite(webSite, dirID, xProduct); } if (wasInserted) { if (!project.WixExtensions.Contains("WixIIsExtension.dll")) project.WixExtensions.Add("WixIIsExtension.dll"); if (!project.WixNamespaces.Contains("xmlns:iis=\"http://schemas.microsoft.com/wix/IIsExtension\"")) project.WixNamespaces.Add("xmlns:iis=\"http://schemas.microsoft.com/wix/IIsExtension\""); } }
internal static void InjectAutoElementsHandler(XDocument doc, Project project) { ExpandCustomAttributes(doc, project); InjectShortcutIcons(doc); HandleEmptyDirectories(doc); XElement product = doc.Root.Select("Product"); int?absPathCount = null; foreach (XElement dir in product.Element("Directory").Elements("Directory")) { XElement installDir = dir; XAttribute installDirName = installDir.Attribute("Name"); if (IO.Path.IsPathRooted(installDirName.Value)) { string absolutePath = installDirName.Value; if (dir == product.Element("Directory").Elements("Directory").First()) //only for the first root dir { //ManagedUI will need some hint on the install dir as it cannot rely on the session action (e.g. Set_INSTALLDIR_AbsolutePath) //because it is running outside of the sequence and analyses the tables directly for the INSTALLDIR product.AddElement("Property", "Id=INSTALLDIR_ABSOLUTEPATH; Value=" + absolutePath); } installDirName.Value = $"ABSOLUTEPATH{absPathCount}"; //<SetProperty> for INSTALLDIR is an attractive approach but it doesn't allow conditional setting of 'ui' and 'execute' as required depending on UI level // it is ether hard-coded 'both' or hard coded-both 'ui' or 'execute' // <SetProperty Id="INSTALLDIR" Value="C:\My Company\MyProduct" Sequence="both" Before="AppSearch"> string actualDirName = installDir.Attribute("Id").Value; string customAction = $"Set_DirAbsolutePath{absPathCount}"; product.Add(new XElement("CustomAction", new XAttribute("Id", customAction), new XAttribute("Property", actualDirName), new XAttribute("Value", absolutePath))); product.SelectOrCreate("InstallExecuteSequence").Add( new XElement("Custom", $"(NOT Installed) AND (UILevel < 5) AND ({actualDirName} = ABSOLUTEPATH{absPathCount})", new XAttribute("Action", customAction), new XAttribute("Before", "AppSearch"))); product.SelectOrCreate("InstallUISequence").Add( new XElement("Custom", $"(NOT Installed) AND (UILevel = 5) AND ({actualDirName} = ABSOLUTEPATH{absPathCount})", new XAttribute("Action", customAction), new XAttribute("Before", "AppSearch"))); if (absPathCount == null) { absPathCount = 0; } absPathCount++; } } CreateEmptyComponentsInDirectoriesToRemove(doc); foreach (XElement xDir in product.Descendants("Directory").ToArray()) { var dirComponents = xDir.Elements("Component").ToArray(); if (dirComponents.Any()) { var componentsWithNoFilesOrRegistry = dirComponents.Where(x => !x.ContainsFilesOrRegistries()).ToArray(); foreach (XElement item in componentsWithNoFilesOrRegistry) { //if (!item.Attribute("Id").Value.EndsWith(".EmptyDirectory")) EnsureKeyPath(item); if (!xDir.ContainsAnyRemoveFolder()) { InsertRemoveFolder(xDir, item, "uninstall"); //to keep WiX/compiler happy and allow removal of the dummy directory } } } foreach (XElement xComp in dirComponents) { if (xDir.InUserProfile()) { if (!xDir.ContainsAnyRemoveFolder()) { InsertRemoveFolder(xDir, xComp); } if (!xComp.ContainsDummyUserProfileRegistry()) { InsertDummyUserProfileRegistry(xComp); } } else { if (xComp.ContainsNonAdvertisedShortcuts()) { if (!xComp.ContainsDummyUserProfileRegistry()) { InsertDummyUserProfileRegistry(xComp); } } } foreach (XElement xFile in xComp.Elements("File")) { if (xFile.ContainsAdvertisedShortcuts() && !xComp.ContainsDummyUserProfileRegistry()) { SetFileKeyPath(xFile); } } } if (!xDir.ContainsComponents() && xDir.InUserProfile()) { if (!xDir.IsUserProfileRoot()) { XElement xComp1 = doc.CreateComponentFor(xDir); if (!xDir.ContainsAnyRemoveFolder()) { InsertRemoveFolder(xDir, xComp1); } if (!xComp1.ContainsDummyUserProfileRegistry()) { InsertDummyUserProfileRegistry(xComp1); } } } } //Not a property Id as MSI requires Predicate <string> needsProperty = value => value.Contains("\\") || value.Contains("//") || value.Contains("%") || value.Contains("[") || value.Contains("]"); foreach (XElement xShortcut in product.Descendants("Shortcut")) { if (xShortcut.HasAttribute("WorkingDirectory", x => needsProperty(x))) { string workingDirectory = xShortcut.Attribute("WorkingDirectory").Value; if (workingDirectory.StartsWith("%") && workingDirectory.EndsWith("%")) //%INSTALLDIR% { workingDirectory = workingDirectory.ExpandWixEnvConsts(); xShortcut.SetAttributeValue("WorkingDirectory", workingDirectory.Replace("%", "")); } else if (workingDirectory.StartsWith("[") && workingDirectory.EndsWith("]")) //[INSTALLDIR] { xShortcut.SetAttributeValue("WorkingDirectory", workingDirectory.Replace("[", "").Replace("]", "")); } else { string workinDirPath = workingDirectory.ReplaceWixSharpEnvConsts(); XElement existingProperty = product.Descendants("Property") .FirstOrDefault(p => p.HasAttribute("Value", workingDirectory)); if (existingProperty != null) { xShortcut.SetAttributeValue("WorkingDirectory", existingProperty.Attribute("Id").Value); } else { string propId = xShortcut.Attribute("Id").Value + ".WorkDir"; product.AddElement("Property", "Id=" + propId + "; Value=" + workinDirPath); xShortcut.SetAttributeValue("WorkingDirectory", propId); } } } } InjectPlatformAttributes(doc); }
static void Main(string[] args) { Feature appFeature = new Feature("Application files", "Main application files", true, false, @"INSTALLDIR"); var shortcut = new FileShortcut(appFeature, "ShootingLab", @"%ProgramMenu%\digiCamControl") { WorkingDirectory = @"INSTALLDIR" }; var shortcutD = new FileShortcut(appFeature, "ShootingLab", @"%Desktop%") { WorkingDirectory = @"INSTALLDIR" }; var appDir = new Dir(@"ShootingLab", new WixSharp.File(appFeature, "ShootingLab.exe", shortcut, shortcutD), new DirFiles(appFeature, @"*.dll") //new WixSharp.File(appFeature, "shootingLab.ico") ); var baseDir = new Dir(@"%ProgramFiles%\", appDir); Project project = new Project("ShootingLab", new LaunchCondition("NET40=\"#1\"", "Please install .NET 4.0 first."), baseDir, new RegValueProperty("NET40", RegistryHive.LocalMachine, @"Software\Microsoft\NET Framework Setup\NDP\v4\Full", "Install", "0"), new ManagedAction(@"MyAction", Return.ignore, When.Before, Step.InstallExecute, Condition.NOT_Installed, Sequence.InstallExecuteSequence), new ManagedAction(@"SetRightAction", Return.ignore, When.Before, Step.InstallFinalize, Condition.Always, Sequence.InstallExecuteSequence) ); project.UI = WUI.WixUI_FeatureTree; project.GUID = new Guid("4E22C775-897C-41D5-8009-1A4A616149B2"); project.SourceBaseDir = Path.GetFullPath(@"C:\Développements\LaboPDV\ShootingLab\bin\Release\"); FileVersionInfo ver = FileVersionInfo.GetVersionInfo(Path.Combine(project.SourceBaseDir, "ShootingLab.exe")); //project.LicenceFile = @"Licenses\ShootingLabLicence.rtf"; project.Version = new Version(ver.FileMajorPart, ver.FileMinorPart, ver.FileBuildPart, ver.FilePrivatePart); project.MajorUpgradeStrategy = MajorUpgradeStrategy.Default; project.MajorUpgradeStrategy.RemoveExistingProductAfter = Step.InstallInitialize; project.ControlPanelInfo.Manufacturer = "PixVert"; project.OutFileName = string.Format("ShootingLabSetup_{0}", ver.FileVersion); //project.ControlPanelInfo.ProductIcon = "shootingLab.ico"; project.ResolveWildCards(); Compiler.PreserveTempFiles = true; Compiler.BuildMsi(project); }
public static void Main(string[] args) { Feature appFeature = new Feature("Application files", "Main application files", true, false, @"INSTALLDIR"); var shortcut = new FileShortcut(appFeature, "digiCamControl", @"%ProgramMenu%\digiCamControl") { WorkingDirectory = @"INSTALLDIR" }; var shortcutD = new FileShortcut(appFeature, "digiCamControl", @"%Desktop%") { WorkingDirectory = @"INSTALLDIR" }; var appDir = new Dir(@"digiCamControl", new File(appFeature, "CameraControl.exe", shortcut, shortcutD), new File(appFeature, "CameraControl.PluginManager.exe"), new File(appFeature, "CameraControlCmd.exe"), new File(appFeature, "CameraControlRemoteCmd.exe"), new File(appFeature, "dcraw.exe"), new File(appFeature, "ffmpeg.exe"), new File(appFeature, "ngrok.exe"), new File(appFeature, "MtpTester.exe"), //new File(appFeature, "PhotoBooth.exe",new FileShortcut(appFeature, "PhotoBooth", @"%ProgramMenu%\digiCamControl")), new DirFiles(appFeature, @"*.dll"), #if DEBUG new DirFiles(appFeature, @"*.pdb"), #endif new File(appFeature, "regwia.bat"), new File(appFeature, "logo.ico"), new File(appFeature, "logo_big.jpg"), new File(appFeature, "baseMtpDevice.xml"), new DirFiles(appFeature, @"*.png"), new File(appFeature, "DigiCamControl.xbs"), new Dir(appFeature, "Data", new Files(appFeature, @"Data\*.*")), //new Dir(appFeature, "Plugins", // new Files(appFeature, @"Plugins\*.*", "MahApps.Metro.*", "System.Windows.Interactivity.*", // "WriteableBitmapEx.Wpf.*", "GalaSoft.MvvmLight.*", "*.config")), new Dir(appFeature, "Plugins", new Dir(appFeature, "CameraControl.Plugins", new File(appFeature, "Plugins\\CameraControl.Plugins\\CameraControl.Plugins.dll"), new File(appFeature, "Plugins\\CameraControl.Plugins\\dcc.plugin")), new Dir(appFeature, "Plugin.DeviceControlBox", new File(appFeature, "Plugins\\Plugin.DeviceControlBox\\Plugin.DeviceControlBox.dll"), new File(appFeature, "Plugins\\Plugin.DeviceControlBox\\dcc.plugin")) ), new Dir(appFeature, "Languages", new DirFiles(appFeature, @"Languages\*.xml")), new Dir(appFeature, "Licenses", new DirFiles(appFeature, @"Licenses\*.*")), new Dir(appFeature, "x64", new DirFiles(appFeature, @"x64\*.*")), new Dir(appFeature, "x86", new DirFiles(appFeature, @"x86\*.*")), new Dir(appFeature, "Tools", new DirFiles(appFeature, @"Tools\*.*")), new Dir(appFeature, "WebServer", new Files(appFeature, @"WebServer\*.*")) ); var baseDir = new Dir(@"%ProgramFiles%", appDir ); Project project = new Project("digiCamControl", baseDir, new ManagedAction(Setup.CustomActions.MyAction, Return.ignore, When.Before, Step.InstallExecute, Condition.NOT_Installed, Sequence.InstallExecuteSequence), new ManagedAction(Setup.CustomActions.SetRightAction, Return.ignore, When.Before, Step.InstallFinalize, Condition.Always, Sequence.InstallExecuteSequence), new RegValue(appFeature, RegistryHive.ClassesRoot, @"Wow6432Node\CLSID\{860BB310-5D01-11d0-BD3B-00A0C911CE86}\Instance\{628C6DCD-6A0A-4804-AAF3-91335A83239B}", "FriendlyName", "digiCamControl Virtual WebCam"), new RegValue(appFeature, RegistryHive.CurrentUser, @"SOFTWARE\IP Webcam", "url", "http://*****:*****@"SOFTWARE\IP Webcam", "width","640"), new RegValue(appFeature, RegistryHive.CurrentUser, @"SOFTWARE\IP Webcam", "height", "426") ); project.UI = WUI.WixUI_InstallDir; project.GUID = new Guid("19d12628-7654-4354-a305-9ab0932af676"); //project.SetNetFxPrerequisite("NETFRAMEWORK45='#1'"); #if DEBUG project.SourceBaseDir = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\CameraControl\bin\Debug\")); #else project.SourceBaseDir = Path.GetFullPath(System.IO.Path.Combine(Environment.CurrentDirectory, @"..\CameraControl\bin\Release\")); #endif /* Not particularly proud of this change, nor the matching one in ObsPluginSetup.cs, but it seems necessary to allow these * programs to be built regardless of the layout choosen for the files */ FileVersionInfo ver = null; try { ver = FileVersionInfo.GetVersionInfo(Path.Combine(project.SourceBaseDir, "CameraControl.exe")); } catch (FileNotFoundException ex) { project.SourceBaseDir = project.SourceBaseDir.Replace(@"Setup\bin\", ""); ver = FileVersionInfo.GetVersionInfo(Path.Combine(project.SourceBaseDir, "CameraControl.exe")); } project.LicenceFile = @"Licenses\DigiCamControlLicence.rtf"; project.Version = new Version(ver.FileMajorPart, ver.FileMinorPart, ver.FileBuildPart, ver.FilePrivatePart); project.MajorUpgradeStrategy = MajorUpgradeStrategy.Default; //project.MajorUpgradeStrategy.NewerProductInstalledErrorMessage = "A version of the digiCamControl already installed. Unistall it first from Control Panel !"; project.MajorUpgradeStrategy.RemoveExistingProductAfter = Step.InstallInitialize; ////project.MajorUpgradeStrategy.UpgradeVersions = VersionRange.ThisAndOlder; ////project.MajorUpgradeStrategy.PreventDowngradingVersions = VersionRange.ThisAndOlder; project.ControlPanelInfo.Manufacturer = "Duka Istvan"; project.OutFileName = string.Format("digiCamControlsetup_{0}", ver.FileVersion); project.ControlPanelInfo.ProductIcon = "logo.ico"; if (System.IO.Directory.Exists(Path.Combine(project.SourceBaseDir, "Branding"))) { appDir.AddDir(new Dir(appFeature, "Branding", new Files(appFeature, @"Branding\*.*"))); } string branding = Path.Combine(project.SourceBaseDir, "branding.xml"); if (System.IO.File.Exists(branding)) { var doc = new XmlDocument(); doc.LoadXml(System.IO.File.ReadAllText(branding)); string name = doc.DocumentElement.SelectSingleNode("/Branding/ApplicationTitle").InnerText; project.ControlPanelInfo.Manufacturer = name; project.OutFileName = string.Format(name.Replace(" ", "_") + "_{0}", ver.FileVersion); appDir.AddFile(new File(appFeature, "branding.xml")); project.Name = name; if (System.IO.File.Exists(Path.Combine(project.SourceBaseDir, "Branding", "logo.ico"))) { project.ControlPanelInfo.ProductIcon = Path.Combine(project.SourceBaseDir, "Branding", "logo.ico"); shortcut.IconFile = Path.Combine(project.SourceBaseDir, "Branding", "logo.ico"); shortcutD.IconFile = Path.Combine(project.SourceBaseDir, "Branding", "logo.ico"); shortcut.Name = name; shortcutD.Name = name; } if (System.IO.File.Exists(Path.Combine(project.SourceBaseDir, "Branding", "Licence.rtf"))) project.LicenceFile = "Branding\\Licence.rtf"; } project.InstallScope = InstallScope.perMachine; project.ResolveWildCards(); Compiler.PreserveTempFiles = false; string productMsi = Compiler.BuildMsi(project); string obsMsi = ObsPluginSetup.Execute(); Thread.Sleep(2000); var dict = new Dictionary<string, string>(); dict.Add("Visible","yes"); var bootstrapper =new Bundle(project.Name, new PackageGroupRef("NetFx46Web"), //new ExePackage("vcredist_x86.exe"){InstallCommand ="/quite" }, new MsiPackage(Path.Combine(Path.GetDirectoryName(productMsi), "IPCamAdapter.msi")) { Permanent = false,Attributes = dict}, new MsiPackage(obsMsi) { Id = "ObsPackageId", Attributes = dict }, new MsiPackage(productMsi) { Id = "MyProductPackageId", DisplayInternalUI = true, Attributes = dict }); bootstrapper.Copyright = project.ControlPanelInfo.Manufacturer; bootstrapper.Version = project.Version; bootstrapper.UpgradeCode = new Guid("19d12628-7654-4354-a305-3A2057E2E6C9"); bootstrapper.DisableModify = "yes"; bootstrapper.DisableRemove = true; //bootstrapper.Application = new LicenseBootstrapperApplication() //{ // LicensePath = Path.Combine(project.SourceBaseDir, project.LicenceFile), // LogoFile = project.ControlPanelInfo.ProductIcon, //}; bootstrapper.IconFile = project.ControlPanelInfo.ProductIcon; bootstrapper.PreserveTempFiles = true; bootstrapper.OutFileName = project.OutFileName; bootstrapper.Build(); }
static public int Main(string[] args) { // Takes for granted that the current working directory is the same as this file if (args.Length == 0) { Console.WriteLine("No platform argument given (x86|x64)"); return(1); } string platform = args[0].ToLower(); if (platform == "x86") { Console.WriteLine("Building Win32 installer for x86 platform."); } else if (platform == "x64") { Console.WriteLine("Building Win64 installer for x64 platform."); } else { Console.WriteLine("Unknown build platform: {0}", platform); } string PATH_ROOT = Path.GetFullPath(".."); string PATH_BUILD = PATH_ROOT + @"\build"; string PATH_DATA = PATH_ROOT + @"\TestData"; string PATH_SOURCE = PATH_ROOT + @"\src"; string PATH_LIB_SOURCE = PATH_ROOT + @"\Tiled2UnityLib"; string PATH_RELEASE = ""; string PATH_UNITY_PACKAGE = ""; string VERSION = ""; string GUID = ""; string WIN_PLATFORM = ""; string PATH_PROGRAM_FILES = ""; if (platform == "x86") { PATH_RELEASE = PATH_ROOT + @"\src\bin\Release"; GUID = "91b20082-6384-40d1-b090-33dcaa49eab5"; WIN_PLATFORM = "win32"; PATH_PROGRAM_FILES = Environment.GetEnvironmentVariable("ProgramFiles(x86)"); } else { PATH_RELEASE = PATH_ROOT + @"\src\bin\x64\Release"; GUID = "e3a46be2-728d-492d-928f-77021c74eb15"; WIN_PLATFORM = "win64"; PATH_PROGRAM_FILES = Environment.GetEnvironmentVariable("ProgramFiles"); } // Get the version from the exe FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(PATH_RELEASE + @"\Tiled2UnityLib.dll"); VERSION = versionInfo.ProductVersion; PATH_UNITY_PACKAGE = PATH_BUILD + @"\Tiled2Unity." + VERSION + @".unitypackage"; Console.WriteLine("-- Building MSI installer for version: {0}", VERSION); Console.WriteLine("-- PATH_ROOT: {0}", PATH_ROOT); Console.WriteLine("-- PATH_BUILD: {0}", PATH_BUILD); Console.WriteLine("-- PATH_DATA: {0}", PATH_DATA); Console.WriteLine("-- PATH_SOURCE: {0}", PATH_SOURCE); Console.WriteLine("-- PATH_LIB_SOURCE: {0}", PATH_LIB_SOURCE); Console.WriteLine("-- PATH_RELEASE: {0}", PATH_RELEASE); Console.WriteLine("-- PATH_UNITY_PACKAGE: {0}", PATH_UNITY_PACKAGE); Console.WriteLine("-- GUID: {0}", GUID); Console.WriteLine("-- WIN_PLATFORM: {0}", WIN_PLATFORM); Console.WriteLine("-- PATH_PROGRAM_FILES: {0}", PATH_PROGRAM_FILES); Console.WriteLine("-- VERSION: {0}", VERSION); // Fill out the Wix project string projectName = String.Format("Tiled2Unity ({0})", WIN_PLATFORM); var project = new WixSharp.Project(projectName, new WixSharp.Dir(@"%ProgramFiles%\Tiled2Unity", new WixSharp.File(PATH_BUILD + @"\ReadMe.txt"), new WixSharp.File(PATH_RELEASE + @"\Tiled2Unity.exe"), new WixSharp.File(PATH_RELEASE + @"\Tiled2Unity.exe.config"), new WixSharp.File(PATH_RELEASE + @"\Tiled2UnityLib.dll"), new WixSharp.File(PATH_RELEASE + @"\NDesk.Options.dll"), new WixSharp.File(PATH_RELEASE + @"\SkiaSharp.dll"), new WixSharp.File(PATH_RELEASE + @"\libSkiaSharp.dll"), new WixSharp.File(PATH_BUILD + @"\Tiled2UnityLite.cs"), RenamedFile(PATH_UNITY_PACKAGE, "Tiled2Unity.unitypackage"), new WixSharp.Dir("Examples", new WixSharp.DirFiles(PATH_DATA + @"\*.*") ), new WixSharp.Dir("License", RenamedFile(PATH_SOURCE + @"\License.rtf", "License.Tiled2Unity.rtf"), RenamedFile(PATH_SOURCE + @"\ThirdParty\NDesk\License.txt", "License.NDesk.txt"), RenamedFile(PATH_LIB_SOURCE + @"\ThirdParty\Clipper\License.txt", "License.Clipper.txt"), RenamedFile(PATH_LIB_SOURCE + @"\ThirdParty\LibTessDotNet\LICENSE.txt", "License.LibTessDotNet.txt") ) )); project.GUID = new Guid(GUID); project.LicenceFile = PATH_SOURCE + @"\License.rtf"; project.UI = WUI.WixUI_InstallDir; project.Version = new Version(VERSION); project.MajorUpgradeStrategy = MajorUpgradeStrategy.Default; project.MajorUpgradeStrategy.RemoveExistingProductAfter = Step.InstallInitialize; project.Platform = (WIN_PLATFORM == "win32") ? Platform.x86 : Platform.x64; // Compile the project string msiFile = WixSharp.Compiler.BuildMsi(project); if (msiFile == null) { Console.WriteLine("Failed to build Tiled2Unity {0} installer.", platform); return(1); } // Rename the MSI output file string renamedFile = String.Format("Tiled2Unity-{0}-{1}-setup.msi", VERSION, WIN_PLATFORM); Console.WriteLine("-- Renaming: {0} -> {1}", System.IO.Path.GetFileName(msiFile), renamedFile); if (System.IO.File.Exists(renamedFile)) { System.IO.File.Delete(renamedFile); } System.IO.File.Move(msiFile, renamedFile); msiFile = renamedFile; // Install the MSI file Console.WriteLine("-- Install the MSI file"); Process p = Process.Start(msiFile); p.WaitForExit(); if (p.ExitCode != 0) { Console.WriteLine("-- Installation of {0} either failed or was canceled.", msiFile); return(1); } Console.WriteLine("-- Successfully installed {0}", msiFile); // Zip the installation string zipFromDir = PATH_PROGRAM_FILES + @"\Tiled2Unity"; string zipToFile = "Tiled2Unity-" + VERSION + "-" + WIN_PLATFORM + ".zip"; Console.WriteLine("-- Zipping installation {0} -> {1}", zipFromDir, zipToFile); if (System.IO.File.Exists(zipToFile)) { System.IO.File.Delete(zipToFile); } ZipFile.CreateFromDirectory(zipFromDir, zipToFile); return(0); }
public static void Validate(Project project) { if (project.MajorUpgradeStrategy != null) { if (project.MajorUpgradeStrategy.UpgradeVersions == null && project.MajorUpgradeStrategy.PreventDowngradingVersions == null) { throw new UpgradeStrategyValidationException("Project MajorUpgradeStrategy.UpgradeVersions and PreventDowngradingVersions are not defined."); } if (project.MajorUpgradeStrategy.UpgradeVersions != null) { if (!IsValidVersion(project.MajorUpgradeStrategy.UpgradeVersions.Minimum)) throw new UpgradeStrategyValidationException("Project MajorUpgradeStrategy.UpgradeVersions.Minimum value is invalid."); if (!IsValidVersion(project.MajorUpgradeStrategy.UpgradeVersions.Maximum)) throw new UpgradeStrategyValidationException("Project MajorUpgradeStrategy.UpgradeVersions.Maximum value is invalid."); } if (project.MajorUpgradeStrategy.PreventDowngradingVersions != null) { if (!IsValidVersion(project.MajorUpgradeStrategy.PreventDowngradingVersions.Minimum)) throw new UpgradeStrategyValidationException("Project MajorUpgradeStrategy.PreventDowngradingVersions.Minimum value is invalid."); if (!IsValidVersion(project.MajorUpgradeStrategy.PreventDowngradingVersions.Maximum)) throw new UpgradeStrategyValidationException("Project MajorUpgradeStrategy.PreventDowngradingVersions.Maximum value is invalid."); } } foreach (Dir dir in project.AllDirs) if (dir.Name.StartsWith("%") || dir.Name.EndsWith("%")) if (!Compiler.EnvironmentConstantsMapping.ContainsKey(dir.Name)) throw new ValidationException("WixSharp.Dir.Name is set to unknown environment constant '" + dir.Name + "'.\n" + "For the list of supported constants analyze WixSharp.Compiler.EnvironmentConstantsMapping.Keys."); var incosnistentRefAsmActions = project.Actions.OfType<ManagedAction>() .GroupBy(a => a.ActionAssembly) .Where(g => g.Count() > 1) .Select(g => new { Assembly = g.Key, Info = g.Select(a => new { Name = a.MethodName, RefAsms = a.RefAssemblies.Select(r => Path.GetFileName(r)).ToArray() }).ToArray(), IsInconsistent = g.Select(action => action.GetRefAssembliesHashCode(project.DefaultRefAssemblies)).Distinct().Count() > 1, }) .Where(x => x.IsInconsistent) .FirstOrDefault(); if (incosnistentRefAsmActions != null) { var errorInfo = new StringBuilder(); errorInfo.Append(">>>>>>>>>>>>\n"); errorInfo.Append("Asm: " + incosnistentRefAsmActions.Assembly + "\n"); foreach (var item in incosnistentRefAsmActions.Info) { errorInfo.Append(" ----------\n"); errorInfo.Append(" Action: " + item.Name+"\n"); errorInfo.AppendFormat(" RefAsms: {0} items\n", item.RefAsms.Length); foreach (var name in item.RefAsms) errorInfo.Append(" - " + name + "\n"); } errorInfo.Append(">>>>>>>>>>>>\n"); throw new ApplicationException(string.Format("Assembly '{0}' is used by multiple ManagedActions but with the inconsistent set of referenced assemblies. " + "Ensure that all declarations have the same referenced assemblies by either using identical declarations or by using " + "Project.DefaultRefAssemblies.\n{1}", incosnistentRefAsmActions.Assembly, errorInfo)); } var incosnistentInstalledFileActions = project.Actions .OfType<InstalledFileAction>() .Where(x => x.When != When.After || x.Step != Step.InstallExecute) .Any(); if (incosnistentInstalledFileActions) try { Debug.WriteLine("Warning: InstalledFileAction should be scheduled for after InstallExecute. Otherwise it may produce undesired side effects."); Console.WriteLine("Warning: InstalledFileAction should be scheduled for after InstallExecute. Otherwise it may produce undesired side effects."); } catch { } }
private static void ProcessCertificates(Project project, Dictionary<Feature, List<string>> featureComponents, List<string> defaultFeatureComponents, XElement product) { if (!project.Certificates.Any()) return; project.IncludeWixExtension(WixExtension.IIs); int componentCount = 0; foreach (var certificate in project.Certificates) { componentCount++; var compId = "Certificate" + componentCount; if (certificate.Feature != null) { if (!featureComponents.ContainsKey(certificate.Feature)) featureComponents[certificate.Feature] = new List<string>(); featureComponents[certificate.Feature].Add(compId); } else { defaultFeatureComponents.Add(compId); } var topLevelDir = GetTopLevelDir(product); var comp = topLevelDir.AddElement( new XElement("Component", new XAttribute("Id", compId), new XAttribute("Guid", WixGuid.NewGuid(compId)))); comp.Add(certificate.ToXml()); } }
public static void Main(string[] args) { Feature appFeature = new Feature("Application files", "Main application files", true, false, @"INSTALLDIR"); var shortcut = new FileShortcut(appFeature, "digiCamControl", @"%ProgramMenu%\digiCamControl") { WorkingDirectory = @"INSTALLDIR" }; var shortcutD = new FileShortcut(appFeature, "digiCamControl", @"%Desktop%") { WorkingDirectory = @"INSTALLDIR" }; var appDir = new Dir(@"digiCamControl", new File(appFeature, "CameraControl.exe", shortcut, shortcutD), new File(appFeature, "CameraControl.PluginManager.exe"), new File(appFeature, "CameraControlCmd.exe"), new File(appFeature, "CameraControlRemoteCmd.exe"), new File(appFeature, "dcraw.exe"), new File(appFeature, "ffmpeg.exe"), new File(appFeature, "ngrok.exe"), new File(appFeature, "MtpTester.exe"), //new File(appFeature, "PhotoBooth.exe",new FileShortcut(appFeature, "PhotoBooth", @"%ProgramMenu%\digiCamControl")), new DirFiles(appFeature, @"*.dll"), #if DEBUG new DirFiles(appFeature, @"*.pdb"), #endif new File(appFeature, "regwia.bat"), new File(appFeature, "logo.ico"), new File(appFeature, "logo_big.jpg"), new File(appFeature, "baseMtpDevice.xml"), new DirFiles(appFeature, @"*.png"), new File(appFeature, "DigiCamControl.xbs"), new Dir(appFeature, "Data", new Files(appFeature, @"Data\*.*")), //new Dir(appFeature, "Plugins", // new Files(appFeature, @"Plugins\*.*", "MahApps.Metro.*", "System.Windows.Interactivity.*", // "WriteableBitmapEx.Wpf.*", "GalaSoft.MvvmLight.*", "*.config")), new Dir(appFeature, "Plugins", new Dir(appFeature, "CameraControl.Plugins", new File(appFeature, "Plugins\\CameraControl.Plugins\\CameraControl.Plugins.dll"), new File(appFeature, "Plugins\\CameraControl.Plugins\\dcc.plugin")), new Dir(appFeature, "Plugin.DeviceControlBox", new File(appFeature, "Plugins\\Plugin.DeviceControlBox\\Plugin.DeviceControlBox.dll"), new File(appFeature, "Plugins\\Plugin.DeviceControlBox\\dcc.plugin")) ), new Dir(appFeature, "Languages", new DirFiles(appFeature, @"Languages\*.xml")), new Dir(appFeature, "Licenses", new DirFiles(appFeature, @"Licenses\*.*")), new Dir(appFeature, "x64", new DirFiles(appFeature, @"x64\*.*")), new Dir(appFeature, "x86", new DirFiles(appFeature, @"x86\*.*")), new Dir(appFeature, "Tools", new DirFiles(appFeature, @"Tools\*.*")), new Dir(appFeature, "WebServer", new Files(appFeature, @"WebServer\*.*")) ); var baseDir = new Dir(@"%ProgramFiles%", appDir ); Project project = new Project("digiCamControl", baseDir, new ManagedAction(@"MyAction", Return.ignore, When.Before, Step.InstallExecute, Condition.NOT_Installed, Sequence.InstallExecuteSequence), new ManagedAction(@"SetRightAction", Return.ignore, When.Before, Step.InstallFinalize, Condition.Always, Sequence.InstallExecuteSequence) ); project.UI = WUI.WixUI_InstallDir; project.GUID = new Guid("19d12628-7654-4354-a305-9ab0932af676"); project.SetNetFxPrerequisite("NETFRAMEWORK40FULL='#1'"); #if DEBUG project.SourceBaseDir = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\CameraControl\bin\Debug\")); #else project.SourceBaseDir = Path.GetFullPath(System.IO.Path.Combine(Environment.CurrentDirectory, @"..\CameraControl\bin\Release\")); #endif FileVersionInfo ver = FileVersionInfo.GetVersionInfo(Path.Combine(project.SourceBaseDir, "CameraControl.exe")); project.LicenceFile = @"Licenses\DigiCamControlLicence.rtf"; project.Version = new Version(ver.FileMajorPart, ver.FileMinorPart, ver.FileBuildPart, ver.FilePrivatePart); project.MajorUpgradeStrategy = MajorUpgradeStrategy.Default; //project.MajorUpgradeStrategy.NewerProductInstalledErrorMessage = "A version of the digiCamControl already installed. Unistall it first from Control Panel !"; project.MajorUpgradeStrategy.RemoveExistingProductAfter = Step.InstallInitialize; ////project.MajorUpgradeStrategy.UpgradeVersions = VersionRange.ThisAndOlder; ////project.MajorUpgradeStrategy.PreventDowngradingVersions = VersionRange.ThisAndOlder; project.ControlPanelInfo.Manufacturer = "Duka Istvan"; project.OutFileName = string.Format("digiCamControlsetup_{0}", ver.FileVersion); project.ControlPanelInfo.ProductIcon = "logo.ico"; if (System.IO.Directory.Exists(Path.Combine(project.SourceBaseDir, "Branding"))) { appDir.AddDir(new Dir(appFeature, "Branding", new Files(appFeature, @"Branding\*.*"))); } string branding = Path.Combine(project.SourceBaseDir, "branding.xml"); if (System.IO.File.Exists(branding)) { var doc = new XmlDocument(); doc.LoadXml(System.IO.File.ReadAllText(branding)); string name = doc.DocumentElement.SelectSingleNode("/Branding/ApplicationTitle").InnerText; project.ControlPanelInfo.Manufacturer = name; project.OutFileName = string.Format(name.Replace(" ", "_") + "_{0}", ver.FileVersion); appDir.AddFile(new File(appFeature, "branding.xml")); project.Name = name; if (System.IO.File.Exists(Path.Combine(project.SourceBaseDir, "Branding", "logo.ico"))) { project.ControlPanelInfo.ProductIcon = Path.Combine(project.SourceBaseDir, "Branding", "logo.ico"); shortcut.IconFile = Path.Combine(project.SourceBaseDir, "Branding", "logo.ico"); shortcutD.IconFile = Path.Combine(project.SourceBaseDir, "Branding", "logo.ico"); shortcut.Name = name; shortcutD.Name = name; } if (System.IO.File.Exists(Path.Combine(project.SourceBaseDir, "Branding", "Licence.rtf"))) project.ControlPanelInfo.ProductIcon = "Branding\\Licence.rtf"; } project.ResolveWildCards(); Compiler.PreserveTempFiles = true; Compiler.BuildMsi(project); ObsPluginSetup.Execute(); }
static void ProcessLaunchConditions(Project project, XElement product) { foreach (var condition in project.LaunchConditions) product.Add(new XElement("Condition", new XAttribute("Message", condition.Message), condition.ToCData()) .AddAttributes(condition.Attributes)); }