Beispiel #1
0
        public void Reference(Project project, IFile file)
        {
            if (!_fs.FileExists(file.Fullpath))
            {
                Console.WriteLine("Could not reference unexisting project {0}", file.Fullpath);
                return;
            }

            if (!tryOpen(project.Content.ToString()))
            {
                return;
            }

            var relativePath = PathExtensions.GetRelativePath(
                project.File,
                file.Fullpath).Replace("/", "\\");

            if (alreadyReferenced(relativePath))
            {
                return;
            }

            var handler = new ProjectHandler();

            handler.Read(file.Fullpath, _getTypesProviderByProject);

            var parent        = getReferenceGroup(project.File);
            var node          = _document.CreateNode(XmlNodeType.Element, "ProjectReference", parent.NamespaceURI);
            var fileAttribute = _document.CreateAttribute("Include");

            fileAttribute.Value = relativePath;
            node.Attributes.Append(fileAttribute);
            node.AppendChild(createNode("Project", "{" + handler.Guid.ToString() + "}", parent));
            node.AppendChild(createNode("Name", Path.GetFileNameWithoutExtension(file.Fullpath), parent));
            parent.AppendChild(node);
            project.SetContent(_document.OuterXml);
        }