상속: IVsBuildDependency
예제 #1
0
        /// <summary>
        ///     constructor for the ProjectReferenceNode
        /// </summary>
        public ProjectReferenceNode(ProjectNode root, string referencedProjectName, string projectPath,
            string projectReference)
            : base(root)
        {
            Debug.Assert(
                root != null && !string.IsNullOrEmpty(referencedProjectName) && !string.IsNullOrEmpty(projectReference)
                && !string.IsNullOrEmpty(projectPath),
                "Can not add a reference because the input for adding one is invalid.");

            if (projectReference == null)
            {
                throw new ArgumentNullException("projectReference");
            }

            ReferencedProjectName = referencedProjectName;

            var indexOfSeparator = projectReference.IndexOf('|');


            var fileName = string.Empty;

            // Unfortunately we cannot use the path part of the projectReference string since it is not resolving correctly relative pathes.
            if (indexOfSeparator != -1)
            {
                var projectGuid = projectReference.Substring(0, indexOfSeparator);
                referencedProjectGuid = new Guid(projectGuid);
                if (indexOfSeparator + 1 < projectReference.Length)
                {
                    var remaining = projectReference.Substring(indexOfSeparator + 1);
                    indexOfSeparator = remaining.IndexOf('|');

                    if (indexOfSeparator == -1)
                    {
                        fileName = remaining;
                    }
                    else
                    {
                        fileName = remaining.Substring(0, indexOfSeparator);
                    }
                }
            }

            Debug.Assert(!string.IsNullOrEmpty(fileName),
                "Can not add a project reference because the input for adding one is invalid.");

            // Did we get just a file or a relative path?
            var uri = new Uri(projectPath);

            var referenceDir = PackageUtilities.GetPathDistance(ProjectMgr.BaseURI.Uri, uri);

            Debug.Assert(!string.IsNullOrEmpty(referenceDir),
                "Can not add a project reference because the input for adding one is invalid.");

            var justTheFileName = Path.GetFileName(fileName);
            referencedProjectRelativePath = Path.Combine(referenceDir, justTheFileName);

            referencedProjectFullPath = Path.Combine(projectPath, justTheFileName);

            buildDependency = new BuildDependency(ProjectMgr, referencedProjectGuid);
        }
예제 #2
0
        public ProjectReferenceNode(ProjectNode root, ProjectElement element)
            : base(root, element)
        {
            referencedProjectRelativePath = ItemNode.GetMetadata(ProjectFileConstants.Include);
            Debug.Assert(!string.IsNullOrEmpty(referencedProjectRelativePath),
                "Could not retrive referenced project path form project file");

            var guidString = ItemNode.GetMetadata(ProjectFileConstants.Project);

            // Continue even if project setttings cannot be read.
            try
            {
                referencedProjectGuid = new Guid(guidString);

                buildDependency = new BuildDependency(ProjectMgr, referencedProjectGuid);
                ProjectMgr.AddBuildDependency(buildDependency);
            }
            finally
            {
                Debug.Assert(referencedProjectGuid != Guid.Empty,
                    "Could not retrive referenced project guidproject file");

                ReferencedProjectName = ItemNode.GetMetadata(ProjectFileConstants.Name);

                Debug.Assert(!string.IsNullOrEmpty(ReferencedProjectName),
                    "Could not retrive referenced project name form project file");
            }

            var uri = new Uri(ProjectMgr.BaseURI.Uri, referencedProjectRelativePath);

            if (uri != null)
            {
                referencedProjectFullPath = Microsoft.VisualStudio.Shell.Url.Unescape(uri.LocalPath, true);
            }
        }