Beispiel #1
0
        internal void AddResourceFileToProjectFile(IResourceFile file, VSProjectFileTypes filetype)
        {
            try
            {
                if (file.FileGroup.Files.Count > 0)
                {
                    if (projectXml == null)
                    {
                        projectXml = new XmlDocument();
                        projectXml.Load(GetProjectFilePath());

                        namespaceManager = new XmlNamespaceManager(projectXml.NameTable);
                        namespaceManager.AddNamespace("n", defaultnamespace);
                    }

                    string filename = getProjectRelativeFileName(file);
                    var    node     = projectXml.SelectSingleNode(String.Format("/n:Project/n:ItemGroup/n:{1}[@Include = '{0}']", filename, filetype), namespaceManager);
                    if (node == null)
                    {
                        foreach (var otherfile in file.FileGroup.Files.Values)
                        {
                            filename = getProjectRelativeFileName(otherfile);
                            node     = projectXml.SelectSingleNode(String.Format("/n:Project/n:ItemGroup[n:{1}/@Include = '{0}']", filename, filetype), namespaceManager);

                            if (node != null)
                            {
                                break;
                            }
                        }

                        if (node == null)
                        {
                            log4net.ILog log = log4net.LogManager.GetLogger(typeof(VSProject));
                            log.WarnFormat("Resource file '{0}' could not be added to project '{1}', because no existing file found in project.", file.File.Name, file.FileGroup.Container.Project.Name);
                        }
                        else
                        {
                            var embeddedResource = projectXml.CreateElement(filetype.ToString(), defaultnamespace);
                            embeddedResource.SetAttribute("Include", getProjectRelativeFileName(file));
                            node.AppendChild(embeddedResource);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                log4net.ILog log = log4net.LogManager.GetLogger(typeof(VSProject));
                log.Error("Resource file could not be added to the project.", e);
            }
        }
Beispiel #2
0
        internal void AddResourceFileToProjectFile(IResourceFile file, VSProjectFileTypes filetype)
        {
            try
            {
                if (file.FileGroup.Files.Count > 0)
                {
                    if (projectXml == null)
                    {
                        projectXml = new XmlDocument();
                        projectXml.Load(GetProjectFilePath());

                        namespaceManager = new XmlNamespaceManager(projectXml.NameTable);
                        namespaceManager.AddNamespace("n", defaultnamespace);
                    }

                    string filename = getProjectRelativeFileName(file);
                    var node = projectXml.SelectSingleNode(String.Format("/n:Project/n:ItemGroup/n:{1}[@Include = '{0}']", filename, filetype), namespaceManager);
                    if (node == null)
                    {
                        foreach (var otherfile in file.FileGroup.Files.Values)
                        {
                            filename = getProjectRelativeFileName(otherfile);
                            node = projectXml.SelectSingleNode(String.Format("/n:Project/n:ItemGroup[n:{1}/@Include = '{0}']", filename, filetype), namespaceManager);

                            if (node != null)
                                break;
                        }

                        if (node == null)
                        {
                            log4net.ILog log = log4net.LogManager.GetLogger(typeof(VSProject));
                            log.WarnFormat("Resource file '{0}' could not be added to project '{1}', because no existing file found in project.", file.File.Name, file.FileGroup.Container.Project.Name);
                        }
                        else
                        {
                            var embeddedResource = projectXml.CreateElement(filetype.ToString(), defaultnamespace);
                            embeddedResource.SetAttribute("Include", getProjectRelativeFileName(file));
                            node.AppendChild(embeddedResource);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                log4net.ILog log = log4net.LogManager.GetLogger(typeof(VSProject));
                log.Error("Resource file could not be added to the project.", e);
            }
        }