Beispiel #1
0
        public WixSourceFile([NotNull] WixProject project, [NotNull] EnvDTE.ProjectItem projectItem)
        {
            Project      = project;
            _projectItem = projectItem;

            try
            {
                _xmlFile    = _projectItem.GetXmlContent(LoadOptions.PreserveWhitespace);
                _rawXmlFile = _projectItem.GetXmlContent(LoadOptions.None);
            }
            catch
            {
                var placeholder = @"<?xml version=""1.0"" encoding=""utf-8""?><Include />";
                _xmlFile    = XDocument.Parse(placeholder);
                _rawXmlFile = XDocument.Parse(placeholder);
            }

            var root = _xmlFile.Root;

            _root = root ?? throw new InvalidDataException("Invalid source file: " + projectItem.TryGetFileName());

            WixNames = new WixNames(root.GetDefaultNamespace().NamespaceName);

            _defines = root.Nodes().OfType <XProcessingInstruction>()
                       .Where(p => p.Target.Equals(WixNames.Define, StringComparison.Ordinal))
                       .Select(p => new WixDefine(this, p))
                       .ToList();

            _componentGroupNodes = root.Descendants(WixNames.ComponentGroupNode)
                                   .Select(node => new WixComponentGroupNode(this, node))
                                   .ToList();

            _componentNodes = root.Descendants(WixNames.ComponentNode)
                              .Select(node => new WixComponentNode(this, node))
                              .ToList();

            _fileNodes = new List <WixFileNode>();

            _fileNodes.AddRange(root
                                .Descendants(WixNames.FileNode)
                                .Select(node => new WixFileNode(this, node, _fileNodes)));

            _directoryNodes = root
                              .Descendants(WixNames.DirectoryNode)
                              .Select(node => new WixDirectoryNode(this, node))
                              .Where(node => node.Id != "TARGETDIR")
                              .ToList();

            _featureNodes = root
                            .Descendants(WixNames.FeatureNode)
                            .Select(node => new WixFeatureNode(this, node))
                            .ToList();

            var featureNodesLookup = _featureNodes.ToDictionary(item => item.Id);

            foreach (var featureNode in _featureNodes)
            {
                featureNode.BuildTree(featureNodesLookup);
            }
        }
Beispiel #2
0
        public WixSourceFile([NotNull] WixProject project, [NotNull] EnvDTE.ProjectItem projectItem)
        {
            Project      = project;
            _projectItem = projectItem;

            _xmlFile    = _projectItem.GetXmlContent(LoadOptions.PreserveWhitespace);
            _rawXmlFile = _projectItem.GetXmlContent(LoadOptions.None);

            var root = _xmlFile.Root;

            _root = root ?? throw new InvalidDataException("Invalid source file: " + projectItem.TryGetFileName());

            WixNames = new WixNames(root.GetDefaultNamespace().NamespaceName);

            _defines = root.Nodes().OfType <XProcessingInstruction>()
                       .Where(p => p.Target.Equals(WixNames.Define, StringComparison.Ordinal))
                       .Select(p => new WixDefine(this, p))
                       .ToList();

            _componentGroupNodes = root.Descendants(WixNames.ComponentGroupNode)
                                   // ReSharper disable once AssignNullToNotNullAttribute
                                   .Select(node => new WixComponentGroupNode(this, node))
                                   .ToList();

            _componentNodes = root.Descendants(WixNames.ComponentNode)
                              // ReSharper disable once AssignNullToNotNullAttribute
                              .Select(node => new WixComponentNode(this, node))
                              .ToList();

            _fileNodes = new List <WixFileNode>();

            _fileNodes.AddRange(root
                                .Descendants(WixNames.FileNode)
                                // ReSharper disable once AssignNullToNotNullAttribute
                                .Select(node => new WixFileNode(this, node, _fileNodes)));

            _directoryNodes = root
                              .Descendants(WixNames.DirectoryNode)
                              // ReSharper disable once AssignNullToNotNullAttribute
                              .Select(node => new WixDirectoryNode(this, node))
                              .Where(node => node.Id != "TARGETDIR")
                              .ToList();

            _featureNodes = root
                            .Descendants(WixNames.FeatureNode)
                            // ReSharper disable once AssignNullToNotNullAttribute
                            .Select(node => new WixFeatureNode(this, node))
                            .ToList();

            // ReSharper disable once PossibleNullReferenceException
            var featureNodesLookup = _featureNodes.ToDictionary(item => item.Id);

            foreach (var featureNode in _featureNodes)
            {
                featureNode.BuildTree(featureNodesLookup);
            }
        }
Beispiel #3
0
        public WixSourceFile([NotNull] WixProject project, [NotNull] EnvDTE.ProjectItem projectItem)
        {
            Contract.Requires(project != null);
            Contract.Requires(projectItem != null);

            _project     = project;
            _projectItem = projectItem;

            _xmlFile    = _projectItem.GetXmlContent(LoadOptions.PreserveWhitespace);
            _rawXmlFile = _projectItem.GetXmlContent(LoadOptions.None);

            var root = _xmlFile.Root;

            if (root == null)
            {
                throw new InvalidDataException("Invalid source file: " + projectItem.TryGetFileName());
            }

            _root = root;

            WixNames = new WixNames(_root.GetDefaultNamespace().NamespaceName);

            _defines = _root.Nodes().OfType <XProcessingInstruction>()
                       .Where(p => p.Target.Equals(WixNames.Define, StringComparison.Ordinal))
                       .Select(p => new WixDefine(this, p))
                       .ToList();

            _componentGroups = _root.Descendants(WixNames.ComponentGroupNode)
                               .Select(node => new WixComponentGroupNode(this, node))
                               .ToList();

            _fileNodes = new List <WixFileNode>();

            _fileNodes.AddRange(_root
                                .Descendants(WixNames.FileNode)
                                .Select(node => new WixFileNode(this, node, _fileNodes)));

            _directoryNodes = _root
                              .Descendants(WixNames.DirectoryNode)
                              .Select(node => new WixDirectoryNode(this, node))
                              .Where(node => node.Id != "TARGETDIR")
                              .ToList();

            _featureNodes = _root
                            .Descendants(WixNames.FeatureNode)
                            .Select(node => new WixFeatureNode(this, node))
                            .ToList();
        }