Example #1
0
        public static ProjectFileModel FromXmlNode(XmlNode xmlNode)
        {
            var xElement = xmlNode.ToXElement();

            var projectFile = ProjectFileModel.FromXElement(xElement);

            return(projectFile);
        }
Example #2
0
        public static ProjectFileModel New(string sdkValue = ProjectFileXmlValues.MicrosoftNetSDK)
        {
            var projectElement = ProjectXElementOperations.CreateProjectElement(sdkValue);

            var projectFile = ProjectFileModel.FromXElement(projectElement);

            return(projectFile);
        }
Example #3
0
        public static ProjectFileModel FromFile(string projectFilePath)
        {
            var xElement = XElement.Load(projectFilePath);

            var projectFile = ProjectFileModel.FromXElement(xElement);

            return(projectFile);
        }
        public static Version GetVersion(this ProjectFileModel projectFile)
        {
            var versionStr = projectFile.GetPropertyValue(ProjectFileXmlElementNames.Version);

            var version = Version.Parse(versionStr);

            return(version);
        }
        public static bool HasProjectReferenceItemGroup(this ProjectFileModel projectFile)
        {
            var output = projectFile.ProjectElement.Value.Elements()
                         .Where(x => ProjectFileModelExtensions.IsProjectReferenceItemGroup(x))
                         .Any();

            return(output);
        }
        public static PropertyGroupXElement AcquirePropertyGroup(this ProjectFileModel projectFile)
        {
            var propertyGroup = projectFile.ProjectElement.Value.AcquireElement(ProjectFileXmlElementNames.PropertyGroup).AsPropertyGroup();

            propertyGroup.ProjectElement = projectFile.ProjectElement;

            return(propertyGroup);
        }
        public static ProjectFileModel AddPackageReference(this ProjectFileModel projectFile, string packageName, Version packageVersion)
        {
            var packageReferenceItemGroup = projectFile.AcquirePackageReferenceItemGroup();

            packageReferenceItemGroup.AddPackageReference(packageName, packageVersion);

            return(projectFile);
        }
Example #8
0
 public static void Serialize(string projectFilePath, ProjectFileModel projectFile, bool overwrite = true)
 {
     using (var fileStream = FileStreamHelper.NewWrite(projectFilePath, overwrite))
         using (var xmlWriter = XmlWriterHelper.New(fileStream))
         {
             projectFile.ProjectElement.Value.Save(xmlWriter);
         }
 }
        public static ProjectFileModel RemovePackageReference(this ProjectFileModel projectFile, string packageName)
        {
            var packageReferenceItemGroup = projectFile.AcquirePackageReferenceItemGroup();

            packageReferenceItemGroup.RemovePackageReference(packageName);

            return(projectFile);
        }
        public static ProjectFileModel AddProjectReference(this ProjectFileModel projectFile, string projectFilePath, string dependencyProjectFilePath)
        {
            var dependencyProjectRelativeFilePath = ProjectFileUtilities.GetProjectDirectoryRelativeFilePath(projectFilePath, dependencyProjectFilePath);

            projectFile.AddProjectReference(dependencyProjectRelativeFilePath);

            return(projectFile);
        }
        public static ProjectFileModel RemoveProjectReference(this ProjectFileModel projectFile, string projectFileRelativeFilePath)
        {
            var projectReferenceItemGroup = projectFile.AcquireProjectReferenceItemGroup();

            projectReferenceItemGroup.RemoveProjectReference(projectFileRelativeFilePath);

            return(projectFile);
        }
        public static IEnumerable <string> GetProjectReferenceDependencyFilePaths(this ProjectFileModel projectFileModel, string projectFilePath)
        {
            var projectDirectoryPath = PathUtilities.GetDirectoryPath(projectFilePath);

            var output = projectFileModel.GetProjectReferenceDependencyFilePathsForProjectDirectory(projectDirectoryPath);

            return(output);
        }
Example #13
0
        public static ProjectXElement AsProject(this XElement xElement, ProjectFileModel projectFile)
        {
            var projectElement = xElement.AsProject();

            projectElement.ProjectFile = projectFile;

            return(projectElement);
        }
        public static ProjectReferenceItemGroupXElement GetProjectReferenceItemGroup(this ProjectFileModel projectFile)
        {
            var output = projectFile.ProjectElement.Value.Elements()
                         .Where(x => ProjectFileModelExtensions.IsProjectReferenceItemGroup(x))
                         .Single()
                         .AsProjectReferenceItemGroup();

            return(output);
        }
Example #15
0
        public static ProjectFileModel FromXElement(XElement xElement)
        {
            var projectElement = xElement.AsProject();

            var projectFile = new ProjectFileModel(projectElement);

            projectElement.ProjectFile = projectFile;

            return(projectFile);
        }
Example #16
0
        public static ProjectFileModel NewNetStandardLibrary()
        {
            var projectFile = ProjectFileModel.New()
                              .AcquirePropertyGroup()
                              .SetTargetFramework(TargetFramework.NetStandard_2_0)
                              .SetVersion(Version.Parse("0.0.1"))
                              .SetGenerateDocumentationFile(true)
                              .SetNoWarnStandard()
                              .ProjectFile()
            ;

            return(projectFile);
        }
        public static IEnumerable <Tuple <string, Version> > GetPackageReferences(this ProjectFileModel projectFile)
        {
            if (projectFile.HasPackageReferenceItemGroup())
            {
                var packageReferenceItemGroup = projectFile.GetPackageReferenceItemGroup();

                var packageReferences = packageReferenceItemGroup.GetPackageReferences();
                return(packageReferences);
            }
            else
            {
                return(Enumerable.Empty <Tuple <string, Version> >());
            }
        }
        public static IEnumerable <string> GetProjectReferenceRelativePaths(this ProjectFileModel projectFile)
        {
            if (projectFile.HasProjectReferenceItemGroup())
            {
                var projectReferenceItemGroup = projectFile.GetProjectReferenceItemGroup();

                var projectReferenceRelativePaths = projectReferenceItemGroup.GetProjectReferenceRelativePaths();
                return(projectReferenceRelativePaths);
            }
            else
            {
                return(Enumerable.Empty <string>());
            }
        }
        public static bool HasProperty(this ProjectFileModel projectFile, string propertyElementName)
        {
            var hasPropertyGroup = projectFile.HasPropertyGroup();

            if (!hasPropertyGroup)
            {
                return(false);
            }

            var propertyGroup = projectFile.GetPropertyGroup();

            var output = propertyGroup.HasProperty(propertyElementName);

            return(output);
        }
        private static IEnumerable <string> GetProjectReferenceDependencyFilePathsRecursive_Internal(this ProjectFileModel projectFileModel, string projectFilePath, HashSet <string> pathAccumulator)
        {
            var dependencyProjectFilePaths = projectFileModel.GetProjectReferenceDependencyFilePaths(projectFilePath);

            foreach (var dependencyProjectFilePath in dependencyProjectFilePaths)
            {
                if (!pathAccumulator.Contains(dependencyProjectFilePath))
                {
                    pathAccumulator.Add(dependencyProjectFilePath);
                    yield return(dependencyProjectFilePath);
                }

                var dependencyProjectFile = ProjectFileSerialization.Deserialize(dependencyProjectFilePath);

                var dependencyDependencyProjectFilePaths = dependencyProjectFile.GetProjectReferenceDependencyFilePathsRecursive(dependencyProjectFilePath);
                foreach (var dependencyDependencyProjectFilePath in dependencyDependencyProjectFilePaths)
                {
                    if (!pathAccumulator.Contains(dependencyDependencyProjectFilePath))
                    {
                        pathAccumulator.Add(dependencyDependencyProjectFilePath);
                        yield return(dependencyDependencyProjectFilePath);
                    }
                }
            }
        }
        public static IEnumerable <string> GetProjectReferenceDependencyFilePathsRecursive(this ProjectFileModel projectFileModel, string projectFilePath)
        {
            var pathAccumulator = new HashSet <string>();

            var output = projectFileModel.GetProjectReferenceDependencyFilePathsRecursive_Internal(projectFilePath, pathAccumulator);

            return(output);
        }
        /// <summary>
        /// The project reference relative file paths are relative to the project directory, not file path.
        /// </summary>
        public static IEnumerable <string> GetProjectReferenceDependencyFilePathsForProjectDirectory(this ProjectFileModel projectFileModel, string projectDirectoryPath)
        {
            var projectReferenceRelativeFilePaths = projectFileModel.GetProjectReferenceRelativePaths();

            var projectReferenceFilePaths = ProjectFileUtilities.GetProjectReferenceDependencyFilePathsForProjectDirectory(projectDirectoryPath, projectReferenceRelativeFilePaths);

            return(projectReferenceFilePaths);
        }
 public static void SetPropertyValue(this ProjectFileModel projectFile, string propertyElementName, string value)
 {
     projectFile.AcquirePropertyGroup().SetPropertyValue(propertyElementName, value);
 }
 public static void SetPropertyValue(this ProjectFileModel projectFile, XmlNodeName propertyName, string value)
 {
     projectFile.SetPropertyValue(propertyName.Value, value);
 }
        public static string GetPropertyValue(this ProjectFileModel projectFile, string propertyElementName)
        {
            var value = projectFile.GetPropertyGroup().GetPropertyValue(propertyElementName);

            return(value);
        }
        public static void SetPackageReferenceVersion(this ProjectFileModel projectFile, string packageName, Version packageVersion)
        {
            var packageReferenceItemGroup = projectFile.AcquirePackageReferenceItemGroup();

            packageReferenceItemGroup.SetPackageReferenceVersion(packageName, packageVersion);
        }
 public static void Save(this ProjectFileModel projectFile, string projectFilePath)
 {
     ProjectFileSerialization.Serialize(projectFilePath, projectFile);
 }
        public static string GetPropertyValue(this ProjectFileModel projectFile, XmlNodeName propertyName)
        {
            var value = projectFile.GetPropertyValue(propertyName.Value);

            return(value);
        }
        public static ProjectReferenceItemGroupXElement AcquireProjectReferenceItemGroup(this ProjectFileModel projectFile)
        {
            var projectXElement = projectFile.ProjectElement.Value;

            var projectReferenceItemGroup = projectXElement.Elements()
                                            .AcquireSingle(
                (x) => ProjectFileModelExtensions.IsProjectReferenceItemGroup(x),
                () => projectXElement.AddElement(ProjectFileXmlElementNames.ItemGroup))
                                            .AsProjectReferenceItemGroup(projectFile)
            ;

            return(projectReferenceItemGroup);
        }
        public static void SetVersion(this ProjectFileModel projectFile, Version version)
        {
            var versionString = version.ToStringProjectFileStandard();

            projectFile.SetPropertyValue(ProjectFileXmlElementNames.Version, versionString);
        }