コード例 #1
0
        /// <summary>Loads a <see cref="VsProjectReference"/> from a <see cref="ProjectItem"/>. </summary>
        /// <param name="project">The parent project. </param>
        /// <param name="projectItem">The <see cref="ProjectItem"/>. </param>
        /// <returns>The <see cref="VsProjectReference"/>. </returns>
        public static VsProjectReference Load(VsProject project, ProjectItem projectItem)
        {
            var path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(project.Path), projectItem.EvaluatedInclude);
            path = System.IO.Path.GetFullPath(path);

            var name = projectItem.Metadata.Single(m => m.Name == "Name").EvaluatedValue;

            return new VsProjectReference(path, name);
        }
コード例 #2
0
ファイル: AssemblyReference.cs プロジェクト: sggeng/MyToolkit
        private void LoadHintPath(VsProject project, ProjectItem projectItem)
        {
            HintPath = projectItem.Metadata.Any(m => m.Name == "HintPath") ? projectItem.Metadata.Single(m => m.Name == "HintPath").EvaluatedValue : null;
            if (HintPath != null)
            {
                var packagesPath = project.NuGetPackagesPath;
                if (HintPath.StartsWith(packagesPath))
                {
                    var startIndex = packagesPath.Length;
                    var endIndex = HintPath.IndexOf("\\", startIndex, StringComparison.InvariantCulture);
                    if (endIndex != -1)
                    {
                        IsNuGetReference = true;

                        var isVersionPart = true;
                        var nuGetPackageVersion = string.Empty;
                        var nuGetPackage = string.Empty;

                        var segments = HintPath.Substring(startIndex, endIndex - startIndex).Split('.');
                        foreach (var segment in segments.Reverse())
                        {
                            if (isVersionPart)
                            {
                                int number = 0;
                                if (int.TryParse(segment, out number))
                                {
                                    nuGetPackageVersion = segment + "." + nuGetPackageVersion;
                                }
                                else
                                {
                                    nuGetPackage = segment;
                                    isVersionPart = false;
                                }
                            }
                            else
                                nuGetPackage = segment + "." + nuGetPackage;
                        }

                        NuGetPackageName = nuGetPackage.Trim('.');
                        NuGetPackageVersion = nuGetPackageVersion.Trim('.');
                    }
                }
            }
        }
コード例 #3
0
ファイル: AssemblyReference.cs プロジェクト: sggeng/MyToolkit
        /// <summary>Initializes a new instance of the <see cref="AssemblyReference" /> class.</summary>
        /// <param name="project">The project.</param>
        /// <param name="projectItem">The raw name.</param>
        internal AssemblyReference(VsProject project, ProjectItem projectItem)
        {
            ProjectItem = projectItem;

            var array = ProjectItem.EvaluatedInclude.Split(',');

            _name = array[0];
            _version = "Any";

            LoadHintPath(project, projectItem);

            foreach (var tuple in array.Skip(1)
                .Select(n => n.Trim().Split('='))
                .Select(n => new Tuple<string, string>(n[0], n[1])))
            {
                switch (tuple.Item1)
                {
                    case "Version":
                        _version = tuple.Item2;
                        break;
                }
            }
        }
コード例 #4
0
ファイル: VsProject.cs プロジェクト: sggeng/MyToolkit
 /// <summary>Checks whether both projects are loaded from the same file. </summary>
 /// <param name="project">The other project. </param>
 /// <returns>true when both projects are loaded from the same file. </returns>
 public bool IsSameProject(VsProject project)
 {
     return Id == project.Id;
 }
コード例 #5
0
ファイル: VsProject.cs プロジェクト: sggeng/MyToolkit
 /// <summary>Checks whether this project references the given project. </summary>
 /// <param name="project">The project. </param>
 /// <returns>True when the given project is referenced. </returns>
 public bool IsReferencingProject(VsProject project)
 {
     return ProjectReferences.Any(p => p.IsSameProject(project));
 }
コード例 #6
0
 /// <summary>Checks whether both projects are loaded from the same file. </summary>
 /// <param name="project">The other project. </param>
 /// <returns>true when both projects are loaded from the same file. </returns>
 public bool IsSameProject(VsProject project)
 {
     return(Id == project.Id);
 }
コード例 #7
0
 /// <summary>Checks whether this project references the given project. </summary>
 /// <param name="project">The project. </param>
 /// <returns>True when the given project is referenced. </returns>
 public bool IsReferencingProject(VsProject project)
 {
     return(ProjectReferences.Any(p => p.IsSameProject(project)));
 }