Ejemplo n.º 1
0
        protected ProjectBase LoadProject(SolutionBase solution, TempFileCollection tfc, GacCache gacCache, DirectoryInfo outputDir, string projectFile)
        {
            if (ProjectStack.Contains(projectFile))
            {
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                       "Circular reference to \"{0}\" detected in project \"{1}\".",
                                                       Path.GetFileNameWithoutExtension(projectFile), Parent.Name),
                                         Location.UnknownLocation);
            }

            try {
                ProjectStack.Push(projectFile);

                Log(Level.Verbose, "Loading referenced project '{0}'.", projectFile);
                return(ProjectFactory.LoadProject(solution, SolutionTask, tfc,
                                                  gacCache, ReferencesResolver, outputDir, projectFile));
            } finally {
                ProjectStack.Pop();
            }
        }
Ejemplo n.º 2
0
        private static string GetProjectFileName(string fileName)
        {
            string projectPath = null;

            if (ProjectFactory.IsUrl(fileName))
            {
                // construct uri for project path
                Uri projectUri = new Uri(fileName);

                // get last segment of the uri (which should be the
                // project file itself)
                projectPath = projectUri.LocalPath;
            }
            else
            {
                projectPath = fileName;
            }

            // return filename part
            return(Path.GetFileName(projectPath));
        }
Ejemplo n.º 3
0
        private ProjectBase CreateProject(SolutionBase solution, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver referencesResolver, DirectoryInfo outputDir, string projectPath)
        {
            // determine the filename of the project
            string projectFileName = ProjectFactory.GetProjectFileName(projectPath);

            // determine the extension of the project file
            string projectExt = Path.GetExtension(projectFileName).ToLower(
                CultureInfo.InvariantCulture);

            // fast-skip setup projects since the project files is not XML-based
            if (projectExt == ".vdproj")
            {
                return(null);
            }

            // holds the XML definition of the project
            XmlElement xmlDefinition;

            try {
                XmlDocument doc = LoadProjectXml(projectPath);
                xmlDefinition = doc.DocumentElement;
            } catch (Exception ex) {
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                       "Error loading project '{0}'.", projectPath), Location.UnknownLocation,
                                         ex);
            }

            IProjectBuildProvider provider = FindProvider(projectExt, xmlDefinition);

            if (provider != null)
            {
                return(provider.GetInstance(solution, projectPath, xmlDefinition,
                                            solutionTask, tfc, gacCache, referencesResolver, outputDir));
            }

            // either the project file is invalid or we don't support it
            throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                   "Project '{0}' is invalid or not supported (at this time).",
                                                   projectPath), Location.UnknownLocation);
        }
Ejemplo n.º 4
0
        public static string LoadGuid(string fileName)
        {
            // check if a project with specified file is already cached
            if (_cachedProjects.ContainsKey(fileName))
            {
                // return the guid of the cached project
                return(((ProjectBase)_cachedProjects[fileName]).Guid);
            }

            string projectFileName = ProjectFactory.GetProjectFileName(fileName);
            string projectExt      = Path.GetExtension(projectFileName).ToLower(
                CultureInfo.InvariantCulture);

            // check if GUID of project is already cached
            if (!_cachedProjectGuids.Contains(fileName))
            {
                if (projectExt == ".vbproj" || projectExt == ".csproj" || projectExt == ".vjsproj")
                {
                    // add project GUID to cache
                    _cachedProjectGuids[fileName] = ManagedProjectBase.LoadGuid(fileName);
                }
                else if (projectExt == ".vcproj")
                {
                    // add project GUID to cache
                    _cachedProjectGuids[fileName] = VcProject.LoadGuid(fileName);
                }
                else
                {
                    throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                           "Unknown project file extension '{0}'.", projectExt,
                                                           Location.UnknownLocation));
                }
            }

            // return project GUID from cache
            return((string)_cachedProjectGuids[fileName]);
        }
Ejemplo n.º 5
0
        private static ProjectBase CreateProject(SolutionBase solution, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver referencesResolver, DirectoryInfo outputDir, string projectPath)
        {
            // determine the filename of the project
            string projectFileName = ProjectFactory.GetProjectFileName(projectPath);

            // determine the extension of the project file
            string projectExt = Path.GetExtension(projectFileName).ToLower(
                CultureInfo.InvariantCulture);

            // holds the XML definition of the project
            XmlElement xmlDefinition;

            try {
                XmlDocument doc = LoadProjectXml(projectPath);
                xmlDefinition = doc.DocumentElement;
            } catch (Exception ex) {
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                       "Error loading project '{0}'.", projectPath), Location.UnknownLocation,
                                         ex);
            }

            // first identify project based on known file extensions
            switch (projectExt)
            {
            case ".vbproj":
                return(new VBProject(solution, projectPath, xmlDefinition,
                                     solutionTask, tfc, gacCache, referencesResolver,
                                     outputDir));

            case ".csproj":
                return(new CSharpProject(solution, projectPath, xmlDefinition,
                                         solutionTask, tfc, gacCache, referencesResolver,
                                         outputDir));

            case ".vjsproj":
                return(new JSharpProject(solution, projectPath, xmlDefinition,
                                         solutionTask, tfc, gacCache, referencesResolver,
                                         outputDir));

            case ".vcproj":
                return(new VcProject(solution, projectPath, xmlDefinition,
                                     solutionTask, tfc, gacCache, referencesResolver,
                                     outputDir));
            }

            // next, identify project based on XML definition
            if (VBProject.IsSupported(xmlDefinition))
            {
                return(new VBProject(solution, projectPath, xmlDefinition,
                                     solutionTask, tfc, gacCache, referencesResolver, outputDir));
            }
            else if (CSharpProject.IsSupported(xmlDefinition))
            {
                return(new CSharpProject(solution, projectPath, xmlDefinition,
                                         solutionTask, tfc, gacCache, referencesResolver, outputDir));
            }
            else if (JSharpProject.IsSupported(xmlDefinition))
            {
                return(new JSharpProject(solution, projectPath, xmlDefinition,
                                         solutionTask, tfc, gacCache, referencesResolver, outputDir));
            }
            else if (VcProject.IsSupported(xmlDefinition))
            {
                return(new VcProject(solution, projectPath, xmlDefinition,
                                     solutionTask, tfc, gacCache, referencesResolver, outputDir));
            }

            // either the project file is invalid or we don't support it
            throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                   "Project '{0}' is invalid or not supported (at this time).",
                                                   projectPath), Location.UnknownLocation);
        }
Ejemplo n.º 6
0
 protected static XmlDocument LoadXmlDocument(string fileName)
 {
     return(ProjectFactory.LoadProjectXml(fileName));
 }