コード例 #1
0
        /// <summary>
        /// Gets the references.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="references">The references.</param>
        /// <param name="projectReferences">The project references.</param>
        private void GetReferences(Microsoft.Build.Evaluation.Project project, ref IList<VSProjectReference> references, ref IList<VSProjectReference> projectReferences)
        {
            foreach (ProjectItem projectItem in project.AllEvaluatedItems)
            {
                if (projectItem.ItemType == REFERENCE || projectItem.ItemType == PROJECT_REFERENCE)
                {
                    VSProjectReference reference = new VSProjectReference();
                    reference.Include = projectItem.EvaluatedInclude;

                    if (projectItem.ItemType == PROJECT_REFERENCE)
                    {
                        reference.IsProjectReference = true;
                        reference.ProjectReferenceId = new Guid(projectItem.GetMetadataValue(PROJECT_REFERENCE_ID));
                        projectReferences.Add(reference);
                    }
                    else
                    {
                        reference.HintPath = projectItem.GetMetadataValue(REFERENCE_HINT_PATH);

                        if (reference.HintPath == string.Empty)
                            reference.HintPath = null;
                        
                        references.Add(reference);
                    }
                }
            }
        }
コード例 #2
0
        private static IList<VSProjectReference> GetReferences(XmlDocument xmlDocument, string xpath, bool isProjectReference)
        {
            XmlNamespaceManager namespaceManager = GetNamespaceManager(xmlDocument);
            XmlNodeList nodeList = xmlDocument.SelectNodes(xpath, namespaceManager);

            List<VSProjectReference> references = new List<VSProjectReference>();
            if (nodeList != null)
            {
                foreach (XmlNode node in nodeList)
                {
                    string include = SelectAttributeValue(node, "Include");
                    string hintPath = null;
                    Guid? projectReferenceId = null;
                    foreach (XmlNode childNode in node.ChildNodes)
                    {
                        if (childNode.Name == "HintPath")
                        {
                            hintPath = childNode.InnerXml;
                        }
                        else if (childNode.Name == "Project")
                        {
                            projectReferenceId = new Guid(childNode.InnerXml);
                        }
                    }

                    VSProjectReference reference = new VSProjectReference();
                    reference.Include = include;
                    reference.HintPath = hintPath;
                    reference.IsProjectReference = isProjectReference;
                    reference.ProjectReferenceId = projectReferenceId.GetValueOrDefault();
                    references.Add(reference);
                }
            }
            return references;
        }
コード例 #3
0
 /// <summary>
 /// Parses the silverlight references.
 /// </summary>
 /// <param name="referenceList">The reference list.</param>
 /// <returns></returns>
 public static IList<VSProjectReference> ParseSilverlightReferences(string referenceList)
 {
     List<VSProjectReference> references = new List<VSProjectReference>();
     if (!string.IsNullOrEmpty(referenceList))
     {
         string[] projectNodes = referenceList.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
         foreach (string projectNode in projectNodes)
         {
             string[] nodes = projectNode.Split("|".ToCharArray());
             if (nodes.Length >= 2)
             {
                 VSProjectReference reference = new VSProjectReference();
                 reference.HintPath = nodes[1];
                 reference.IsSilverlightReference = true;
                 reference.ProjectReferenceId = new Guid(nodes[0]);
                 references.Add(reference);
             }
         }
     }
     return references;
 }
コード例 #4
0
        private void ResolveProject(ProjectSetup projectSetup, ProjectLoader projectLoader, VSProject project, VSProjectReference reference, List<VSProject> referencedProjects)
        {
            VSProject vsProject;
            if (reference.IsProjectReference)
            {
                // resolve by ID
                vsProject = projectLoader.GetProjectById(reference.ProjectReferenceId);
            }
            else if (reference.IsSilverlightReference)
            {
                vsProject = projectLoader.GetProjectById(reference.ProjectReferenceId);
            }
            else
            {
                // resolve by output path
                vsProject = projectLoader.GetProjectByOutput(reference.ResolvedHintPath);
            }

            if (vsProject != null)
            {
                referencedProjects.Add(vsProject);
            }
            else
            {
                // fall back scenario, check assembly name in current project output path
                string outputDirectory = Path.GetDirectoryName(project.ResolvedOutput) ?? ".";
                string currentFolderAssembly = Path.Combine(outputDirectory, reference.ResolvedInclude) + ".dll";
                vsProject = projectLoader.GetProjectByOutput(currentFolderAssembly);

                if (vsProject== null)
                {
                    currentFolderAssembly = Path.Combine(outputDirectory, reference.ResolvedInclude) + ".exe";
                    vsProject = projectLoader.GetProjectByOutput(currentFolderAssembly);
                }

                if (vsProject == null)
                {
                    if (projectSetup.WhenReferenceNotResolved == ProjectSetupBehavior.Fail)
                    {
                        throw new SolutionGeneratorException(
                            "Reference {0} was not resolved. {3}Project {1}. {3}Expected location = {2}{3}",
                            reference.ResolvedInclude, project.ProjectFileLocation, reference.ResolvedHintPath, Environment.NewLine);
                    }
                    if (projectSetup.WhenReferenceNotResolved == ProjectSetupBehavior.Warn)
                    {
                        Logger.Warn(
                            "Reference {0} was not resolved. {3}Project {1}. {3}Expected location = {2}{3}",
                            reference.ResolvedInclude, project.ProjectFileLocation, reference.ResolvedHintPath, Environment.NewLine);
                    }
                }
                else
                {
                    if (projectSetup.WhenReferenceResolvedInDifferentLocation == ProjectSetupBehavior.Fail)
                    {
                        throw new SolutionGeneratorException(
                            "Reference {0} was not resolved. {4}Project {1}. {4}Expected location = {2}{4}However it was found in project output folder {3}.{4}",
                            reference.ResolvedInclude, project.ProjectFileLocation, reference.ResolvedHintPath, outputDirectory, Environment.NewLine);
                    }
                    if (projectSetup.WhenReferenceResolvedInDifferentLocation == ProjectSetupBehavior.Warn)
                    {
                        Logger.Warn(
                            "Reference {0} was not resolved. {4}Project {1}. {4}Expected location = {2}{4}However it was found in project output folder {3}.{4}",
                            reference.ResolvedInclude, project.ProjectFileLocation, reference.ResolvedHintPath, outputDirectory, Environment.NewLine);
                    }
                }
            }
        }