/// <summary> /// Processes the installation files, produces the WiX data. /// </summary> private int ConvertFiles(DirectoryRef wixDirectoryRef, ComponentGroup wixComponentGroup, InstallationDataXml dataxml, IDictionary <string, string> macros) { int nProduced = 0; // Each installation folder derives a component, regardless of whether there are more files in the same folder, or not foreach (FolderXml folderxml in dataxml.Files) { folderxml.AssertValid(); // Create the component with the files var wixComponent = new Component(); wixComponent.Id = string.Format("{0}.{1}", ComponentIdPrefix, folderxml.Id); wixComponent.Guid = folderxml.MsiComponentGuid; wixComponent.DiskId = Bag.Get <int>(AttributeName.DiskId); wixComponent.Location = Component.LocationType.local; ConvertFiles_AddToDirectory(folderxml, wixComponent, wixDirectoryRef); // To the directory structure // Add to the feature var wixComponentRef = new ComponentRef(); wixComponentRef.Id = wixComponent.Id; wixComponentGroup.AddChild(wixComponentRef); // To the feature var diSource = new DirectoryInfo(Path.Combine(LocalInstallDataResolved.ResolveSourceDirRoot(folderxml.SourceRoot, Bag), folderxml.SourceDir)); if (!diSource.Exists) { throw new InvalidOperationException(string.Format("The source folder “{0}” does not exist.", diSource.FullName)); } // Add files foreach (FileXml filexml in folderxml.Files) { filexml.AssertValid(); FileInfo[] files = diSource.GetFiles(filexml.SourceName); if (files.Length == 0) { throw new InvalidOperationException(string.Format("There are no files matching the “{0}” mask in the source folder “{1}”.", filexml.SourceName, diSource.FullName)); } if ((files.Length > 1) && (filexml.TargetName.Length > 0)) { throw new InvalidOperationException(string.Format("There are {2} files matching the “{0}” mask in the source folder “{1}”, in which case it's illegal to specify a target name for the file.", filexml.SourceName, diSource.FullName, files.Length)); } foreach (FileInfo fiSource in files) { nProduced++; var wixFile = new File(); wixComponent.AddChild(wixFile); wixFile.Id = string.Format("{0}.{1}.{2}", FileIdPrefix, folderxml.Id, fiSource.Name).Replace('-', '_').Replace(' ', '_'); // Replace chars that are not allowed in the ID wixFile.Name = filexml.TargetName.Length > 0 ? filexml.TargetName : fiSource.Name; // Explicit target name, if present and if a single file; otherwise, use from source wixFile.Checksum = YesNoType.yes; wixFile.ReadOnly = YesNoType.yes; wixFile.Source = fiSource.FullName; } } } return(nProduced); }
/// <summary> /// Emits WiX Registry Values from the installation data. /// </summary> private int ConvertRegistryValues(DirectoryRef directory, ComponentGroup componentgroup, InstallationDataXml dataxml, IDictionary <string, string> macros) { foreach (RegistryValueXml valuexml in dataxml.Registry.Value) { try { var value = new RegistryValue(); GetComponentForHive(valuexml.Hive, directory, componentgroup).AddChild(value); value.Root = GetRoot(valuexml.Hive); value.Key = LocalInstaller.SubstituteMacros(macros, valuexml.Key); if (!string.IsNullOrEmpty(valuexml.Name)) // The default value name must be Null not an empty string { value.Name = LocalInstaller.SubstituteMacros(macros, valuexml.Name); } value.Value = LocalInstaller.SubstituteMacros(macros, valuexml.Value); value.Type = GetValueType(valuexml.Type); value.Action = RegistryValue.ActionType.write; } catch (Exception ex) { throw new InvalidOperationException(string.Format("Failed to process the value {0}. {1}", valuexml, ex.Message), ex); } } return(dataxml.Registry.Value.Length); }
/// <summary> /// Creates a new WiX Component for populating with the values of a specific hive, or reuses an existing one. /// Registry items from different hives must not be mixed within a single component. /// </summary> /// <param name="hive">Registry hive.</param> /// <param name="directory">A WiX directory to parent the newly-created component.</param> /// <param name="componentgroup">A group of components to register the newly-created component into.</param> protected Component GetComponentForHive(RegistryHiveXml hive, DirectoryRef directory, ComponentGroup componentgroup) { if (directory == null) { throw new ArgumentNullException("directory"); } if (componentgroup == null) { throw new ArgumentNullException("componentgroup"); } Component component; if (myMapHiveToComponent.TryGetValue(hive, out component)) // Lookup { return(component); // Reuse existing } // Create a new one component = new Component(); myMapHiveToComponent.Add(hive, component); directory.AddChild(component); component.Id = string.Format("{0}.{1}", ComponentIdPrefix, hive); // Chose a GUID for the component, assign component.Guid = myGuidCache[GetGuidId(hive)].ToString("B").ToUpperInvariant(); // Register in the group var componentref = new ComponentRef(); componentgroup.AddChild(componentref); componentref.Id = component.Id; return(component); }
/// <summary> /// Actions under the resolver. /// </summary> protected override void ExecuteTaskResolved() { GuidCacheXml guidcachexml = GuidCacheXml.Load(new FileInfo(Bag.GetString(AttributeName.GuidCacheFile)).OpenRead()); // Global structure of the WiX fragment file var wix = new Wix(); var wixFragmentComponents = new Fragment(); // Fragment with the payload wix.AddChild(wixFragmentComponents); var wixDirectoryRef = new DirectoryRef(); // Mount into the directories tree, defined externally wixFragmentComponents.AddChild(wixDirectoryRef); wixDirectoryRef.Id = Bag.GetString(AttributeName.WixDirectoryId); var wixDirectory = new Directory(); // A locally created nameless directory that does not add any nested folders but defines the sources location wixDirectoryRef.AddChild(wixDirectory); wixDirectory.Id = DirectoryId; wixDirectory.FileSource = Bag.GetString(AttributeName.ProductBinariesDir); var wixFragmentGroup = new Fragment(); // Fragment with the component-group that collects the components wix.AddChild(wixFragmentGroup); var wixComponentGroup = new ComponentGroup(); // ComponentGroup that collects the components wixFragmentGroup.AddChild(wixComponentGroup); wixComponentGroup.Id = Bag.GetString(AttributeName.WixComponentGroupId); // A component for the generated Registry entries var wixComponentRegistry = new Component(); wixDirectory.AddChild(wixComponentRegistry); wixComponentRegistry.Id = RegistryComponentIdPrefix; wixComponentRegistry.Guid = guidcachexml[GuidIdXml.MsiComponent_ProductBinaries_Registry_Hkmu].ToString("B").ToUpper(); wixComponentRegistry.DiskId = Bag.Get <int>(AttributeName.DiskId); wixComponentRegistry.Location = Component.LocationType.local; var wixComponentRegistryRef = new ComponentRef(); wixComponentGroup.AddChild(wixComponentRegistryRef); wixComponentRegistryRef.Id = wixComponentRegistry.Id; // Create the Registry key for the Plugins section CreatePluginsRegistryKey(wixComponentRegistry); // Load the AllAssemblies file AllAssembliesXml allassembliesxml = AllAssembliesXml.LoadFrom(Bag.Get <TaskItemByValue>(AttributeName.AllAssembliesXml).ItemSpec); // Tracks the files on the target machine, to prevent the same file from being installed both as an assembly and as a reference var mapTargetFiles = new Dictionary <string, string>(); int nGeneratedComponents = ProcessAssemblies(wixDirectory, wixComponentGroup, wixComponentRegistry, allassembliesxml, mapTargetFiles, guidcachexml); // Save to the output file using (var xw = new XmlTextWriter(new FileStream(Bag.GetString(AttributeName.OutputFile), FileMode.Create, FileAccess.Write, FileShare.Read), Encoding.UTF8)) { xw.Formatting = Formatting.Indented; wix.OutputXml(xw); } // Report (also to see the target in the build logs) Log.LogMessage(MessageImportance.Normal, "Generated {0} product binary components.", nGeneratedComponents); }
/// <summary> /// Actions under the resolver. /// </summary> protected override void ExecuteTaskResolved() { // Prepare the GUID cache myGuidCache = GuidCacheXml.Load(new FileInfo(Bag.GetString(AttributeName.GuidCacheFile)).OpenRead()); // Global structure of the WiX fragment file var wix = new Wix(); var wixFragmentComponents = new Fragment(); // Fragment with the payload wix.AddChild(wixFragmentComponents); var wixDirectoryRef = new DirectoryRef(); // Mount into the directories tree, defined externally wixFragmentComponents.AddChild(wixDirectoryRef); wixDirectoryRef.Id = Bag.GetString(AttributeName.WixDirectoryId); var wixFragmentGroup = new Fragment(); // Fragment with the component-group that collects the components wix.AddChild(wixFragmentGroup); var wixComponentGroup = new ComponentGroup(); // ComponentGroup that collects the components wixFragmentGroup.AddChild(wixComponentGroup); wixComponentGroup.Id = Bag.GetString(AttributeName.WixComponentGroupId); // Get the dump from the product InstallationDataXml dataxml = CreateInstaller().HarvestInstallationData(); IDictionary <string, string> macros = GetMacros(); // Nullref guards dataxml.AssertValid(); // Convert into WiX int nProducedFiles = ConvertFiles(wixDirectoryRef, wixComponentGroup, dataxml, macros); int nProducedKeys = ConvertRegistryKeys(wixDirectoryRef, wixComponentGroup, dataxml, macros); int nProducedValues = ConvertRegistryValues(wixDirectoryRef, wixComponentGroup, dataxml, macros); // Save to the output file using (var xw = new XmlTextWriter(new FileStream(Bag.GetString(AttributeName.OutputFile), FileMode.Create, FileAccess.Write, FileShare.Read), Encoding.UTF8)) { xw.Formatting = Formatting.Indented; wix.OutputXml(xw); } // Report (also to see the target in the build logs) Log.LogMessage(MessageImportance.Normal, "Generated {0} files, {1} Registry keys, and {2} Registry values.", nProducedFiles, nProducedKeys, nProducedValues); }
/// <summary> /// Actions under the resolver. /// </summary> protected override void ExecuteTaskResolved() { // Global structure of the WiX fragment file var wix = new Wix(); var wixFragmentComponents = new Fragment(); // Fragment with the payload wix.AddChild(wixFragmentComponents); var wixDirectoryRef = new DirectoryRef(); // Mount into the directories tree, defined externally wixFragmentComponents.AddChild(wixDirectoryRef); wixDirectoryRef.Id = Bag.GetString(AttributeName.WixDirectoryId); var wixDirectory = new Directory(); // A locally created nameless directory that does not add any nested folders but defines the sources location wixDirectoryRef.AddChild(wixDirectory); wixDirectory.Id = DirectoryId; wixDirectory.FileSource = Bag.GetString(AttributeName.ProductReferencesDir); var wixFragmentGroup = new Fragment(); // Fragment with the component-group that collects the components wix.AddChild(wixFragmentGroup); var wixComponentGroup = new ComponentGroup(); // ComponentGroup that collects the components wixFragmentGroup.AddChild(wixComponentGroup); wixComponentGroup.Id = Bag.GetString(AttributeName.WixComponentGroupId); // Load the AllAssemblies file AllAssembliesXml allassembliesxml = AllAssembliesXml.LoadFrom(Bag.Get <TaskItemByValue>(AttributeName.AllAssembliesXml).ItemSpec); // Tracks the files on the target machine, to prevent the same file from being installed both as an assembly and as a reference var mapTargetFiles = new Dictionary <string, string>(); int nGeneratedComponents = ProcessReferences(wixDirectory, wixComponentGroup, allassembliesxml, mapTargetFiles); // Save to the output file using (var xw = new XmlTextWriter(new FileStream(Bag.GetString(AttributeName.OutputFile), FileMode.Create, FileAccess.Write, FileShare.Read), Encoding.UTF8)) { xw.Formatting = Formatting.Indented; wix.OutputXml(xw); } // Report (also to see the target in the build logs) Log.LogMessage(MessageImportance.Normal, "Generated {0} product reference components.", nGeneratedComponents); }
/// <summary> /// Emits WiX Registry Keys from the installation data. /// </summary> private int ConvertRegistryKeys(DirectoryRef directory, ComponentGroup componentgroup, InstallationDataXml dataxml, IDictionary <string, string> macros) { foreach (RegistryKeyXml keyxml in dataxml.Registry.Key) // Keys { try { var key = new RegistryKey(); GetComponentForHive(keyxml.Hive, directory, componentgroup).AddChild(key); key.Root = GetRoot(keyxml.Hive); key.Key = LocalInstaller.SubstituteMacros(macros, keyxml.Key); key.Action = RegistryKey.ActionType.createAndRemoveOnUninstall; } catch (Exception ex) { throw new InvalidOperationException(string.Format("Failed to process the key {0}. {1}", keyxml, ex.Message), ex); } } return(dataxml.Registry.Key.Length); }
public void Save( string slnFile, string wxsFile, Guid componentGuid) { base.Save(slnFile); this.Add(new SolutionObject(SolutionFile.CreateDotSln(slnFile))); Hashtable componentFiles = new Hashtable(); solutionName = Path.GetFileNameWithoutExtension(slnFile); Fragment fragment = new Fragment("Fragment_" + solutionName); m_SolutionFragment = fragment; if (fragmentIncludeFiles != null) { foreach (ITaskItem fragmentInclude in fragmentIncludeFiles) { fragment.PrependInclude(fragmentInclude.ItemSpec); } } DirectoryRef samplesRef = new DirectoryRef(fragment, parentDirectoryRef); WiXDirectory solutionDir = new WiXDirectory(samplesRef, solutionName); solutionDir.Id = solutionName + "_" + solutionDir.Id; DirectoryRef tempRef = new DirectoryRef(fragment, "TEMPFOLDERINSTALLDIR"); WiXDirectory tempSlnDir = new WiXDirectory(tempRef, solutionName); tempSlnDir.Id = solutionName + "_" + tempSlnDir.Id; Component component = new Component(tempSlnDir, "Component_" + solutionName, componentGuid); if (shortcut == ShortcutType.FOLDER) { Shortcut folderShortcut = new Shortcut( component, solutionDir, solutionName, new DirectoryRef(fragment, "ProgramMenuDir")); folderShortcut.Id = solutionName + "_" + folderShortcut.Id; } foreach (SolutionObject slnObj in this) { if (slnObj.Object is ProjectEx) { #region ProjectEx ProjectEx project = slnObj.Object as ProjectEx; // Add the project folder to the WiX file string projectFolderName = Path.GetFileNameWithoutExtension(project.FullFileName); WiXDirectory projectDirectory = new WiXDirectory(solutionDir, projectFolderName); projectDirectory.Id = solutionName + "_" + projectDirectory.Id; component.CreateFolder(projectDirectory); WiXFile projectFile = new WiXFile(component, Path.Combine(Path.GetDirectoryName(wxsFile), Path.GetFileName(project.FullFileName))); projectFile.CopyFile(projectDirectory.Id); // Add subfolders foreach (_BE.ProjectItem folderItem in project.MsBuildProject.GetItems("Folder")) { string addDirPath = folderItem.Xml.Include; if (addDirPath.EndsWith(Path.DirectorySeparatorChar.ToString())) { addDirPath = addDirPath.Substring(0, addDirPath.Length - 1); } AddFolder( projectDirectory, component, addDirPath); } // Loop through all known item groups that map to files // and add those files. foreach (string groupName in ProjectEx.FileGroups) { foreach (_BE.ProjectItem buildItem in project.MsBuildProject.GetItems(groupName)) { AddFile( buildItem.Xml.Include, project, projectDirectory, component, componentFiles); } } foreach (string extraFile in project.ExtraFiles) { AddFile( extraFile, project, projectDirectory, component, componentFiles); } #endregion } else { #region SolutionFile SolutionFile slnFileObj = slnObj.Object as SolutionFile; WiXFile slnFileElem = new WiXFile(component, slnFileObj.File); slnFileElem.Id = solutionName + "_" + slnFileElem.Id; slnFileElem.CopyFile(solutionDir.Id); if (slnFileObj.IsDotSln && shortcut == ShortcutType.DOTSLN) { Shortcut dotSlnShortcut = new Shortcut( slnFileElem, Path.GetFileNameWithoutExtension(slnFileElem.Name), new DirectoryRef(fragment, "ProgramMenuDir")); dotSlnShortcut.Id = solutionName + "_" + dotSlnShortcut.Id; } #endregion } } if (componentIncludeFiles != null) { foreach (ITaskItem componentInclude in componentIncludeFiles) { component.AppendInclude(componentInclude.ItemSpec); } } fragment.Element.OwnerDocument.Save(wxsFile); }
public virtual void VisitItem(Object item) { if (item == null) { return; } Module module = item as Module; if (module != null) { VisitModule(module); return; } Product product = item as Product; if (product != null) { VisitProduct(product); return; } Feature feature = item as Feature; if (feature != null) { VisitFeature(feature); return; } AdvtExecuteSequence advtExecuteSequence = item as AdvtExecuteSequence; if (advtExecuteSequence != null) { VisitAdvtExecuteSequence(advtExecuteSequence); return; } InstallUISequence installUISequence = item as InstallUISequence; if (installUISequence != null) { VisitInstallUISequence(installUISequence); return; } User user = item as User; if (user != null) { VisitUser(user); return; } Upgrade upgrade = item as Upgrade; if (upgrade != null) { VisitUpgrade(upgrade); return; } Directory directory = item as Directory; if (directory != null) { VisitDirectory(directory); return; } PropertyRef propertyRef = item as PropertyRef; if (propertyRef != null) { VisitPropertyRef(propertyRef); return; } WebSite webSite = item as WebSite; if (webSite != null) { VisitWebSite(webSite); return; } AdminUISequence adminUISequence = item as AdminUISequence; if (adminUISequence != null) { VisitAdminUISequence(adminUISequence); return; } CustomAction customAction = item as CustomAction; if (customAction != null) { VisitCustomAction(customAction); return; } DirectoryRef directoryRef = item as DirectoryRef; if (directoryRef != null) { VisitDirectoryRef(directoryRef); return; } AppId appId = item as AppId; if (appId != null) { VisitAppId(appId); return; } Media media = item as Media; if (media != null) { VisitMedia(media); return; } CustomTable customTable = item as CustomTable; if (customTable != null) { VisitCustomTable(customTable); return; } Condition condition = item as Condition; if (condition != null) { VisitCondition(condition); return; } SFPCatalog sFPCatalog = item as SFPCatalog; if (sFPCatalog != null) { VisitSFPCatalog(sFPCatalog); return; } UI ui = item as UI; if (ui != null) { VisitUI(ui); return; } FragmentRef fragmentRef = item as FragmentRef; if (fragmentRef != null) { VisitFragmentRef(fragmentRef); return; } Icon icon = item as Icon; if (icon != null) { VisitIcon(icon); return; } Property property = item as Property; if (property != null) { VisitProperty(property); return; } FeatureRef featureRef = item as FeatureRef; if (featureRef != null) { VisitFeatureRef(featureRef); return; } WebDirProperties webDirProperties = item as WebDirProperties; if (webDirProperties != null) { VisitWebDirProperties(webDirProperties); return; } ComplianceCheck complianceCheck = item as ComplianceCheck; if (complianceCheck != null) { VisitComplianceCheck(complianceCheck); return; } InstallExecuteSequence installExecuteSequence = item as InstallExecuteSequence; if (installExecuteSequence != null) { VisitInstallExecuteSequence(installExecuteSequence); return; } AdminExecuteSequence adminExecuteSequence = item as AdminExecuteSequence; if (adminExecuteSequence != null) { VisitAdminExecuteSequence(adminExecuteSequence); return; } Binary binary = item as Binary; if (binary != null) { VisitBinary(binary); return; } Group group = item as Group; if (group != null) { VisitGroup(group); return; } WebApplication webApplication = item as WebApplication; if (webApplication != null) { VisitWebApplication(webApplication); return; } ActionSequenceType actionSequenceType = item as ActionSequenceType; if (actionSequenceType != null) { VisitActionSequenceType(actionSequenceType); return; } ActionModuleSequenceType actionModuleSequenceType = item as ActionModuleSequenceType; if (actionModuleSequenceType != null) { VisitActionModuleSequenceType(actionModuleSequenceType); return; } BillboardAction billboardAction = item as BillboardAction; if (billboardAction != null) { VisitBillboardAction(billboardAction); return; } Error error = item as Error; if (error != null) { VisitError(error); return; } Dialog dialog = item as Dialog; if (dialog != null) { VisitDialog(dialog); return; } ProgressText progressText = item as ProgressText; if (progressText != null) { VisitProgressText(progressText); return; } TextStyle textStyle = item as TextStyle; if (textStyle != null) { VisitTextStyle(textStyle); return; } ListBox listBox = item as ListBox; if (listBox != null) { VisitListBox(listBox); return; } ListView listView = item as ListView; if (listView != null) { VisitListView(listView); return; } ComboBox comboBox = item as ComboBox; if (comboBox != null) { VisitComboBox(comboBox); return; } UIText uIText = item as UIText; if (uIText != null) { VisitUIText(uIText); return; } RadioGroup radioGroup = item as RadioGroup; if (radioGroup != null) { VisitRadioGroup(radioGroup); return; } IniFileSearch iniFileSearch = item as IniFileSearch; if (iniFileSearch != null) { VisitIniFileSearch(iniFileSearch); return; } RegistrySearch registrySearch = item as RegistrySearch; if (registrySearch != null) { VisitRegistrySearch(registrySearch); return; } ComponentSearch componentSearch = item as ComponentSearch; if (componentSearch != null) { VisitComponentSearch(componentSearch); return; } FileSearch fileSearch = item as FileSearch; if (fileSearch != null) { VisitFileSearch(fileSearch); return; } DirectorySearch directorySearch = item as DirectorySearch; if (directorySearch != null) { VisitDirectorySearch(directorySearch); return; } File file = item as File; if (file != null) { VisitFile(file); return; } Component component = item as Component; if (component != null) { VisitComponent(component); return; } Merge merge = item as Merge; if (merge != null) { VisitMerge(merge); return; } Custom custom = item as Custom; if (custom != null) { VisitCustom(custom); return; } WebError webError = item as WebError; if (webError != null) { VisitWebError(webError); return; } WebVirtualDir webVirtualDir = item as WebVirtualDir; if (webVirtualDir != null) { VisitWebVirtualDir(webVirtualDir); return; } WebDir webDir = item as WebDir; if (webDir != null) { VisitWebDir(webDir); return; } WebFilter webFilter = item as WebFilter; if (webFilter != null) { VisitWebFilter(webFilter); return; } MergeRef mergeRef = item as MergeRef; if (mergeRef != null) { VisitMergeRef(mergeRef); return; } Subscribe subscribe = item as Subscribe; if (subscribe != null) { VisitSubscribe(subscribe); return; } Publish publish = item as Publish; if (publish != null) { VisitPublish(publish); return; } TypeLib typeLib = item as TypeLib; if (typeLib != null) { VisitTypeLib(typeLib); return; } Shortcut shortcut = item as Shortcut; if (shortcut != null) { VisitShortcut(shortcut); return; } ODBCTranslator oDBCTranslator = item as ODBCTranslator; if (oDBCTranslator != null) { VisitODBCTranslator(oDBCTranslator); return; } Permission permission = item as Permission; if (permission != null) { VisitPermission(permission); return; } Class _class = item as Class; if (_class != null) { VisitClass(_class); return; } CopyFile copyFile = item as CopyFile; if (copyFile != null) { VisitCopyFile(copyFile); return; } Patch patch = item as Patch; if (patch != null) { VisitPatch(patch); return; } ODBCDriver oDBCDriver = item as ODBCDriver; if (oDBCDriver != null) { VisitODBCDriver(oDBCDriver); return; } PerfCounter perfCounter = item as PerfCounter; if (perfCounter != null) { VisitPerfCounter(perfCounter); return; } FileShare fileShare = item as FileShare; if (fileShare != null) { VisitFileShare(fileShare); return; } Certificate certificate = item as Certificate; if (certificate != null) { VisitCertificate(certificate); return; } Category category = item as Category; if (category != null) { VisitCategory(category); return; } WebAppPool webAppPool = item as WebAppPool; if (webAppPool != null) { VisitWebAppPool(webAppPool); return; } SqlString sqlString = item as SqlString; if (sqlString != null) { VisitSqlString(sqlString); return; } ServiceControl serviceControl = item as ServiceControl; if (serviceControl != null) { VisitServiceControl(serviceControl); return; } IsolateComponent isolateComponent = item as IsolateComponent; if (isolateComponent != null) { VisitIsolateComponent(isolateComponent); return; } ServiceConfig serviceConfig = item as ServiceConfig; if (serviceConfig != null) { VisitServiceConfig(serviceConfig); return; } WebProperty webProperty = item as WebProperty; if (webProperty != null) { VisitWebProperty(webProperty); return; } SqlScript sqlScript = item as SqlScript; if (sqlScript != null) { VisitSqlScript(sqlScript); return; } SqlDatabase sqlDatabase = item as SqlDatabase; if (sqlDatabase != null) { VisitSqlDatabase(sqlDatabase); return; } WebLockdown webLockdown = item as WebLockdown; if (webLockdown != null) { VisitWebLockdown(webLockdown); return; } Extension extension = item as Extension; if (extension != null) { VisitExtension(extension); return; } ReserveCost reserveCost = item as ReserveCost; if (reserveCost != null) { VisitReserveCost(reserveCost); return; } RemoveFile removeFile = item as RemoveFile; if (removeFile != null) { VisitRemoveFile(removeFile); return; } ProgId progId = item as ProgId; if (progId != null) { VisitProgId(progId); return; } Microsoft.Tools.WindowsInstallerXml.Serialize.Environment environment = item as Microsoft.Tools.WindowsInstallerXml.Serialize.Environment; if (environment != null) { VisitEnvironment(environment); return; } ServiceInstall serviceInstall = item as ServiceInstall; if (serviceInstall != null) { VisitServiceInstall(serviceInstall); return; } IniFile iniFile = item as IniFile; if (iniFile != null) { VisitIniFile(iniFile); return; } Registry registry = item as Registry; if (registry != null) { VisitRegistry(registry); return; } CreateFolder createFolder = item as CreateFolder; if (createFolder != null) { VisitCreateFolder(createFolder); return; } MIME mIME = item as MIME; if (mIME != null) { VisitMIME(mIME); return; } Verb verb = item as Verb; if (verb != null) { VisitVerb(verb); return; } }
public virtual void VisitDirectoryRef(DirectoryRef node) { VisitItemArray(node.Items); }
public override bool Execute() { try { // // Do some setup // this.Log.LogMessage("Create Assembly Fragment Task"); string assemblyRoot = Path.GetFileNameWithoutExtension(assemblyName); if (fragmentId == null) { fragmentId = "Fragment" + assemblyEndian + assemblyName; } componentId = "Component" + assemblyEndian + assemblyName; // // Build WiX file // Fragment fragment = new Fragment(fragmentId); if (includeFiles != null) { foreach (ITaskItem item in includeFiles) { if (item == null) { continue; } fragment.PrependInclude(item.ItemSpec); } } DirectoryRef dirref = new DirectoryRef( fragment, directoryRef); Component fileComponent = null; // Create Component and add files if (componentGuid != Guid.Empty) { // Generate new GUID for BE files, else BE files will be stranded upon uninstall if (assemblyEndian == "_be_") { componentGuid = Guid.NewGuid(); } fileComponent = new Component( dirref, componentId, componentGuid); fragment.PrependDefine( string.Format("COMPONENTID=\"{0}\"", fileComponent.Id)); foreach (ITaskItem item in componentFiles) { if (item == null) { continue; } string fileName = item.ItemSpec; string assemblyType = item.GetMetadata("AssemblyType"); assemblyType = String.IsNullOrEmpty(assemblyType) ? "" : assemblyType.ToLower(); if (assemblyType != "") { if (assemblyType != ".net" && assemblyType != "win32" && assemblyType != "no") { throw new ApplicationException("Invalid assemblyType \"" + assemblyType + "\" in file metadata "); } } Microsoft.SPOT.WiX.File file = new Microsoft.SPOT.WiX.File( fileComponent, item.GetMetadata("Name"), fileName, false); file.Id = file.Id + assemblyEndian; fragment.PrependDefine( string.Format("ID{0}=\"{1}\"", file.Name.Replace('.', '_'), file.Id)); if (!string.IsNullOrEmpty(assemblyShortcut) && fileName.ToLower().EndsWith(".exe")) { Shortcut sc = new Shortcut(file, assemblyShortcut, new DirectoryRef(fragment, "ProgramMenuDir")); } } if (componentIncludeFiles != null) { foreach (ITaskItem item in componentIncludeFiles) { if (item == null) { continue; } fileComponent.AppendInclude(item.ItemSpec); } } } if (postIncludeFiles != null) { foreach (ITaskItem item in postIncludeFiles) { if (item == null) { continue; } fragment.AppendInclude(item.ItemSpec); } } // Save Fragment File string fragmentFileDirectory = Path.GetDirectoryName(fragmentFileName); if (!System.IO.Directory.Exists(fragmentFileDirectory)) { System.IO.Directory.CreateDirectory(fragmentFileDirectory); } fragment.Element.OwnerDocument.Save(fragmentFileName); return(true); } catch (Exception e) { this.Log.LogErrorFromException(e); return(false); } }
/// <summary> /// Creates a new or uses the root directory to add the newly-created component with files being installed. /// </summary> private void ConvertFiles_AddToDirectory(FolderXml folderxml, Component wixComponent, DirectoryRef wixDirectoryRef) { if (folderxml.TargetRoot != TargetRootXml.InstallDir) { throw new InvalidOperationException(string.Format("Only the InstallDir target root is supported.")); } // No relative path — nothing to create if (folderxml.TargetDir.Length == 0) { wixDirectoryRef.AddChild(wixComponent); return; } // Create the folder structure, add to the innermost string[] arDirectoryChain = folderxml.TargetDir.Split('\\'); Directory wixParentDir = null; for (int a = 0; a < arDirectoryChain.Length; a++) { bool bInnermost = a == arDirectoryChain.Length - 1; // Whether this is the folder in which are the files itself // Create var wixDirectory = new Directory { Name = arDirectoryChain[a] }; // Mount self into the hierarchy if (wixParentDir != null) { wixParentDir.AddChild(wixDirectory); // Previous dir } else { wixDirectoryRef.AddChild(wixDirectory); // The very root } wixParentDir = wixDirectory; // Non-innermost folders get a suffix to their ID if (bInnermost) { wixDirectory.Id = string.Format("{0}.{1}", DirectoryIdPrefix, folderxml.Id); } else { wixDirectory.Id = string.Format("{0}.{1}.P{2}", DirectoryIdPrefix, folderxml.Id, arDirectoryChain.Length - 1 - a); } // Mount the component into the innermost dir if (bInnermost) { wixDirectory.AddChild(wixComponent); } } }