Пример #1
1
        public ManagedProjectReference(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, SolutionBase solution, TempFileCollection tfc, GacCache gacCache, DirectoryInfo outputDir)
            : base(referencesResolver, parent)
        {
            if (xmlDefinition == null) {
                throw new ArgumentNullException("xmlDefinition");
            }
            if (solution == null) {
                throw new ArgumentNullException("solution");
            }
            if (tfc == null) {
                throw new ArgumentNullException("tfc");
            }
            if (gacCache == null) {
                throw new ArgumentNullException("gacCache");
            }

            XmlAttribute privateAttribute = xmlDefinition.Attributes["Private"];
            if (privateAttribute != null) {
                _isPrivateSpecified = true;
                _isPrivate = bool.Parse(privateAttribute.Value);
            }

            // determine path of project file
            string projectFile = solution.GetProjectFileFromGuid(
                xmlDefinition.GetAttribute("Project"));

            // load referenced project
            _project = LoadProject(solution, tfc, gacCache, outputDir, projectFile);
        }
Пример #2
0
        public MSBuildProject(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir)
            : base(xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir)
        {
            string cfgname = solutionTask.Configuration;
            string platform = solutionTask.Platform;

            _msbuild = MSBuildEngine.CreateMSEngine(solutionTask);
            _msproj = new Microsoft.Build.BuildEngine.Project(_msbuild);
            _msproj.FullFileName = projectPath;
            _msproj.LoadXml(xmlDefinition.OuterXml);
            _msproj.GlobalProperties.SetProperty("Configuration", cfgname);
            SetPlatform (platform);
            if (outputDir != null) _msproj.GlobalProperties.SetProperty("OutputPath", outputDir.FullName);

            //evaluating
            _guid = _msproj.GetEvaluatedProperty("ProjectGuid");
            _projectDirectory = new DirectoryInfo(_msproj.GetEvaluatedProperty("ProjectDir"));
            _projectPath = _msproj.GetEvaluatedProperty("ProjectPath");

            ProjectEntry projectEntry = solution.ProjectEntries [_guid];
            if (projectEntry != null && projectEntry.BuildConfigurations != null) {
                foreach (ConfigurationMapEntry ce in projectEntry.BuildConfigurations) {
                    Configuration projectConfig = ce.Value;
                    ProjectConfigurations[projectConfig] = new MSBuildConfiguration(this, _msproj, projectConfig);
                }
            } else {
                Configuration projectConfig = new Configuration (cfgname, platform);
                ProjectConfigurations[projectConfig] = new MSBuildConfiguration(this, _msproj, projectConfig);
            }

            //references
            _references = new ArrayList();
            Microsoft.Build.BuildEngine.BuildItemGroup refs = _msproj.GetEvaluatedItemsByName("Reference");
            foreach (Microsoft.Build.BuildEngine.BuildItem r in refs) {
                string rpath = r.FinalItemSpec;
                string priv = r.GetMetadata("Private");
                string hintpath = r.GetMetadata("HintPath");

                ReferenceBase reference = new MSBuildAssemblyReference(
                    xmlDefinition, ReferencesResolver, this, gacCache,
                    rpath, priv, hintpath);
                _references.Add(reference);
            }
            refs = _msproj.GetEvaluatedItemsByName("ProjectReference");
            foreach (Microsoft.Build.BuildEngine.BuildItem r in refs) {
                string pguid = r.GetMetadata("Project");
                string pname = r.GetMetadata("Name");
                string rpath = r.FinalItemSpec;
                string priv = r.GetMetadata("Private");
                ReferenceBase reference = new MSBuildProjectReference(
                    ReferencesResolver, this, solution, tfc, gacCache, outputDir,
                    pguid, pname, rpath, priv);
                _references.Add(reference);
            }
        }
Пример #3
0
 public MSBuildProjectReference(
     ReferencesResolver referencesResolver, ProjectBase parent,
     SolutionBase solution, TempFileCollection tfc,
     GacCache gacCache, DirectoryInfo outputDir,
     string pguid, string pname, string rpath, string priv)
     
     : base(referencesResolver, parent) {
     _helper = new MSBuildReferenceHelper(priv, true);
     string projectFile = solution.GetProjectFileFromGuid(pguid);
     _project = LoadProject(solution, tfc, gacCache, outputDir, projectFile);
 }
Пример #4
0
        public ProjectBase LoadProject(SolutionBase solution, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver referencesResolver, DirectoryInfo outputDir, string path)
        {
            // check if this a new project
            if (!_cachedProjects.Contains(path))
            {
                ProjectBase project = CreateProject(solution, solutionTask,
                                                    tfc, gacCache, referencesResolver, outputDir, path);
                _cachedProjects[path] = project;
            }

            return((ProjectBase)_cachedProjects[path]);
        }
Пример #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VBProject"/> class.
        /// </summary>
        /// <param name="solution">The solution.</param>
        /// <param name="projectPath">The project path.</param>
        /// <param name="xmlDefinition">The XML definition.</param>
        /// <param name="solutionTask">The solution task.</param>
        /// <param name="tfc">The TFC.</param>
        /// <param name="gacCache">The gac cache.</param>
        /// <param name="refResolver">The reference resolver.</param>
        /// <param name="outputDir">The output dir.</param>
        public VBProject(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir)
            : base(solution, projectPath, xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir)
        {
            _imports = new NamespaceImportCollection();

            // process namespace imports
            XmlNodeList imports = xmlDefinition.SelectNodes("//Imports/Import");
            foreach (XmlElement import in imports) {
                XmlAttribute nsAttribute = import.Attributes["Namespace"];
                if (nsAttribute != null) {
                    string nameSpace = nsAttribute.Value.ToString(
                        CultureInfo.InvariantCulture);
                    _imports.Add(new NamespaceImport(nameSpace));
                }
            }
        }
Пример #6
0
        public VBProject(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir) : base(solution, projectPath, xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir)
        {
            _imports = new NamespaceImportCollection();

            // process namespace imports
            XmlNodeList imports = xmlDefinition.SelectNodes("//Imports/Import");

            foreach (XmlElement import in imports)
            {
                XmlAttribute nsAttribute = import.Attributes["Namespace"];
                if (nsAttribute != null)
                {
                    string nameSpace = nsAttribute.Value.ToString(
                        CultureInfo.InvariantCulture);
                    _imports.Add(new NamespaceImport(nameSpace));
                }
            }
        }
Пример #7
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();
            }
        }
Пример #8
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);
        }
Пример #9
0
 public ProjectBase GetInstance(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir) {
     return new MSBuildProject(solution, projectPath, xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir);
 }
Пример #10
0
 public ProjectBase GetInstance(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir)
 {
     return(new VBProject(solution, projectPath, xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir));
 }
Пример #11
0
        public VcProject(SolutionBase solution, string projectPath, XmlElement xmlDefinition, 
                SolutionTask solutionTask, 
                TempFileCollection tfc, 
                GacCache gacCache, 
                ReferencesResolver refResolver, 
                DirectoryInfo outputDir)
            : base(xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir)
        {
            if (projectPath == null) {
                throw new ArgumentNullException("projectPath");
            }

            _references = new ArrayList();
            _clArgMap = VcArgumentMap.CreateCLArgumentMap();
            _linkerArgMap = VcArgumentMap.CreateLinkerArgumentMap();
            _midlArgMap = VcArgumentMap.CreateMidlArgumentMap();
            _projectPath = FileUtils.GetFullPath(projectPath);

            _name = xmlDefinition.GetAttribute("Name");
            _guid = xmlDefinition.GetAttribute("ProjectGUID");

            XmlNodeList configurationNodes = xmlDefinition.SelectNodes("//Configurations/Configuration");
            foreach (XmlElement configElem in configurationNodes) {
                VcProjectConfiguration config = new VcProjectConfiguration(configElem, this, OutputDir);
                ProjectConfigurations[new Configuration (config.Name, config.PlatformName)] = config;
            }

            XmlNodeList references = xmlDefinition.SelectNodes("//References/child::*");
            foreach (XmlElement referenceElem in references) {
                ReferenceBase reference = CreateReference(solution, referenceElem);
                _references.Add(reference);
            }

            XmlNodeList fileNodes = xmlDefinition.SelectNodes("//File");
            _projectFiles = new ArrayList(fileNodes.Count);
            foreach (XmlElement fileElem in fileNodes) {
                string parentName = Name;

                // determine name of parent
                if (fileElem.ParentNode != null && fileElem.ParentNode.Name == "Filter") {
                    XmlNode filterName = fileElem.ParentNode.Attributes.GetNamedItem("Name");
                    if (filterName != null) {
                        parentName = filterName.Value;
                    }
                }

                string relPath = fileElem.GetAttribute("RelativePath");

                Hashtable htFileConfigurations = null;

                XmlNodeList fileConfigList = fileElem.GetElementsByTagName("FileConfiguration");
                if (fileConfigList.Count > 0) {
                    htFileConfigurations = CollectionsUtil.CreateCaseInsensitiveHashtable(fileConfigList.Count);
                    foreach (XmlElement fileConfigElem in fileConfigList) {
                        Configuration fileConfig = Configuration.Parse (
                            fileConfigElem.GetAttribute("Name"));
                        VcProjectConfiguration projectConfig = (VcProjectConfiguration) ProjectConfigurations[fileConfig];
                        htFileConfigurations[projectConfig.Name] = new VcFileConfiguration(
                            relPath, parentName, fileConfigElem, projectConfig, outputDir);
                    }
                }

                // TODO: refactor this together with the Build methods

                // we'll always create a file configuration for IDL and res
                // files as macro's in the configuration properties for these
                // files will always need to be expanded on the file level
                string ext = Path.GetExtension(relPath).ToLower(CultureInfo.InvariantCulture);
                switch (ext) {
                    case ".idl":
                    case ".odl":
                    case ".rc":
                        // ensure there's a file configuration for each project
                        // configuration
                        foreach (VcProjectConfiguration projectConfig in ProjectConfigurations.Values) {
                            // if file configuration for project config existed
                            // in project file, then skip this project config
                            if (htFileConfigurations != null && htFileConfigurations.ContainsKey(projectConfig.Name)) {
                                continue;
                            }

                            // lazy initialize hashtable
                            if (htFileConfigurations == null) {
                                htFileConfigurations = CollectionsUtil.CreateCaseInsensitiveHashtable();
                            }

                            // create the file configuration
                            htFileConfigurations[projectConfig.Name] = new
                                VcFileConfiguration(relPath, parentName, projectConfig, outputDir);
                        }
                        break;
                }

                if (htFileConfigurations != null) {
                    _projectFiles.Add(htFileConfigurations);
                } else {
                    _projectFiles.Add(relPath);
                }
            }
        }
Пример #12
0
        protected virtual ReferenceBase CreateReference(SolutionBase solution, XmlElement xmlDefinition)
        {
            if (solution == null) {
                throw new ArgumentNullException("solution");
            }
            if (xmlDefinition == null) {
                throw new ArgumentNullException("xmlDefinition");
            }

            switch (xmlDefinition.Name) {
                case "ProjectReference":
                    // project reference
                    return new VcProjectReference(xmlDefinition, ReferencesResolver,
                        this, solution, solution.TemporaryFiles, GacCache,
                        OutputDir);
                case "AssemblyReference":
                    // assembly reference
                    return new VcAssemblyReference(xmlDefinition, ReferencesResolver,
                        this, GacCache);
                case "ActiveXReference":
                    // ActiveX reference
                    return new VcWrapperReference(xmlDefinition, ReferencesResolver,
                        this, GacCache);
                default:
                    throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                        "\"{0}\" reference not supported.", xmlDefinition.Name),
                        Location.UnknownLocation);
            }
        }
Пример #13
0
        /// <summary>
        /// Creates the reference.
        /// </summary>
        /// <param name="solution">The solution.</param>
        /// <param name="xmlDefinition">The XML definition.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">
        /// solution
        /// or
        /// xmlDefinition
        /// </exception>
        protected virtual ReferenceBase CreateReference(SolutionBase solution, XmlElement xmlDefinition)
        {
            if (solution == null) {
                throw new ArgumentNullException("solution");
            }
            if (xmlDefinition == null) {
                throw new ArgumentNullException("xmlDefinition");
            }

            if (xmlDefinition.Attributes["Project"] != null) {
                return new ManagedProjectReference(xmlDefinition, ReferencesResolver, this,
                    solution, ProjectSettings.TemporaryFiles, GacCache, OutputDir);
            } else if (xmlDefinition.Attributes["WrapperTool"] != null) {
                // wrapper
                return new ManagedWrapperReference(xmlDefinition, ReferencesResolver,
                    this, GacCache, ProjectSettings);
            } else {
                // assembly reference
                return new ManagedAssemblyReference(xmlDefinition, ReferencesResolver,
                    this, GacCache);
            }
        }
Пример #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ManagedProjectBase"/> class.
        /// </summary>
        /// <param name="solution">The solution.</param>
        /// <param name="projectPath">The project path.</param>
        /// <param name="xmlDefinition">The XML definition.</param>
        /// <param name="solutionTask">The solution task.</param>
        /// <param name="tfc">The TFC.</param>
        /// <param name="gacCache">The gac cache.</param>
        /// <param name="refResolver">The reference resolver.</param>
        /// <param name="outputDir">The output dir.</param>
        /// <exception cref="System.ArgumentNullException">
        /// projectPath
        /// or
        /// xmlDefinition
        /// </exception>
        protected ManagedProjectBase(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir)
            : base(xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir)
        {
            if (projectPath == null) {
                throw new ArgumentNullException("projectPath");
            }

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

            _references = new ArrayList();
            _neutralResources = new ArrayList();
            _localizedResources = new ArrayList();
            _sourceFiles = CollectionsUtil.CreateCaseInsensitiveHashtable();
            _projectPath = projectPath;
            _projectLocation = DetermineProjectLocation(xmlDefinition);

            if (!IsWebProject) {
                _projectDirectory = new FileInfo(projectPath).Directory;
            } else {
                string projectDirectory = projectPath.Replace(":", "_");
                projectDirectory = projectDirectory.Replace("/", "_");
                projectDirectory = projectDirectory.Replace("\\", "_");
                _projectDirectory = new DirectoryInfo(FileUtils.CombinePaths(
                    TemporaryFiles.BasePath, projectDirectory));

                // ensure project directory exists
                if (!_projectDirectory.Exists) {
                    _projectDirectory.Create();
                    _projectDirectory.Refresh();
                }

                _webProjectBaseUrl = projectPath.Substring(0, projectPath.LastIndexOf("/"));
            }

            _projectSettings = new ProjectSettings(xmlDefinition, (XmlElement)
                xmlDefinition.SelectSingleNode("//Build/Settings"), this);

            XmlNodeList nlConfigurations = xmlDefinition.SelectNodes("//Config");
            foreach (XmlElement elemConfig in nlConfigurations) {
                ConfigurationSettings cs = new ConfigurationSettings(this, elemConfig, OutputDir);
                ProjectConfigurations[Configuration.Parse(cs.Name)] = cs;
            }

            XmlNodeList nlReferences = xmlDefinition.SelectNodes("//References/Reference");
            foreach (XmlElement elemReference in nlReferences) {
                ReferenceBase reference = CreateReference(solution, elemReference);
                _references.Add(reference);
            }

            XmlNodeList nlFiles = xmlDefinition.SelectNodes("//Files/Include/File");
            foreach (XmlElement elemFile in nlFiles) {
                string buildAction = StringUtils.ConvertEmptyToNull(elemFile.GetAttribute("BuildAction"));
                string sourceFile;

                if (!String.IsNullOrEmpty(elemFile.GetAttribute("Link"))) {
                    sourceFile = FileUtils.GetFullPath(FileUtils.CombinePaths(
                        ProjectDirectory.FullName, elemFile.GetAttribute("Link")));
                } else {
                    sourceFile = FileUtils.GetFullPath(FileUtils.CombinePaths(
                        ProjectDirectory.FullName, elemFile.GetAttribute("RelPath")));
                }

                if (IsWebProject) {
                    WebDavClient wdc = new WebDavClient(new Uri(_webProjectBaseUrl));
                    wdc.DownloadFile(sourceFile, elemFile.Attributes["RelPath"].Value);

                    switch (buildAction) {
                        case "Compile":
                            _sourceFiles[sourceFile] = null;
                            break;
                        case "EmbeddedResource":
                            RegisterEmbeddedResource(sourceFile, elemFile);
                            break;
                        case null:
                            if (string.Compare(Path.GetExtension(sourceFile), FileExtension, true, CultureInfo.InvariantCulture) == 0) {
                                _sourceFiles[sourceFile] = null;
                            }
                            break;
                    }
                } else {
                    switch (buildAction) {
                        case "Compile":
                            _sourceFiles[sourceFile] = null;
                            break;
                        case "EmbeddedResource":
                            RegisterEmbeddedResource(sourceFile, elemFile);
                            break;
                        case null:
                            if (string.Compare(Path.GetExtension(sourceFile), FileExtension, true, CultureInfo.InvariantCulture) == 0) {
                                _sourceFiles[sourceFile] = null;
                            }
                            break;
                    }

                    // check if file is "App.config" (using case-insensitive comparison)
                    if (string.Compare("App.config", elemFile.GetAttribute("RelPath"), true, CultureInfo.InvariantCulture) == 0) {
                        // App.config is only an output file for executable projects
                        if (ProjectSettings.OutputType == ManagedOutputType.Executable || ProjectSettings.OutputType == ManagedOutputType.WindowsExecutable) {
                            ExtraOutputFiles[sourceFile] = ProjectSettings.OutputFileName
                                + ".config";
                        }
                    }
                }
            }
        }
Пример #15
0
        public ManagedProjectReference(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, SolutionBase solution, TempFileCollection tfc, GacCache gacCache, DirectoryInfo outputDir) : base(referencesResolver, parent)
        {
            if (xmlDefinition == null)
            {
                throw new ArgumentNullException("xmlDefinition");
            }
            if (solution == null)
            {
                throw new ArgumentNullException("solution");
            }
            if (tfc == null)
            {
                throw new ArgumentNullException("tfc");
            }
            if (gacCache == null)
            {
                throw new ArgumentNullException("gacCache");
            }

            XmlAttribute privateAttribute = xmlDefinition.Attributes["Private"];

            if (privateAttribute != null)
            {
                _isPrivateSpecified = true;
                _isPrivate          = bool.Parse(privateAttribute.Value);
            }

            // determine path of project file
            string projectFile = solution.GetProjectFileFromGuid(
                xmlDefinition.GetAttribute("Project"));

            // load referenced project
            _project = LoadProject(solution, tfc, gacCache, outputDir, projectFile);
        }
Пример #16
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);
        }
Пример #17
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 SolutionTask.ProjectFactory.LoadProject(solution,
                    SolutionTask, tfc,  gacCache, ReferencesResolver, outputDir,
                    projectFile);
            } finally {
                ProjectStack.Pop();
            }
        }
Пример #18
0
 public JSharpProject(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir) : base(solution, projectPath, xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir) {
 }
Пример #19
0
        public MSBuildProject(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir)
            : base(xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir)
        {
            string cfgname = solutionTask.Configuration;
            string platform = solutionTask.Platform;

            _msbuild = MSBuildEngine.CreateMSEngine(solutionTask);
            _msproj = new NAnt.MSBuild.BuildEngine.Project(_msbuild);
            _msproj.FullFileName = projectPath;
            _msproj.LoadXml(xmlDefinition.OuterXml);

            _msproj.GlobalProperties.SetProperty("Configuration", cfgname);

            if (platform.Length > 0) {
                _msproj.GlobalProperties.SetProperty("Platform", platform.Replace(" ", string.Empty));
            }

            if (outputDir != null) {
                _msproj.GlobalProperties.SetProperty("OutputPath", outputDir.FullName);
            }

            bool generateDoc = false;
            //bool targwarnings = true;
            foreach (NAnt.Core.Tasks.PropertyTask property in solutionTask.CustomProperties) {
                string val;
                // expand properties in context of current project for non-dynamic properties
                if (!property.Dynamic) {
                    val = solutionTask.Project.ExpandProperties(property.Value, solutionTask.GetLocation()  );
                } else {
                    val = property.Value;
                }
                switch (property.PropertyName)
                {
                    //if (property.PropertyName == "TargetWarnings") targwarnings = Boolean.Parse(val);
                    case "GenerateDocumentation":
                        generateDoc = Boolean.Parse(val);
                        break;
                    default:
                        _msproj.GlobalProperties.SetProperty(property.PropertyName, val);
                        break;
                }

            }

            //set tools version to the msbuild version we got loaded
            _msproj.ToolsVersion = SolutionTask.Project.TargetFramework.Version.ToString();

            //TODO: honoring project's TargetFrameworkVersion is not working atm. System assemblies are resolved badly
            _msproj.GlobalProperties.SetProperty("TargetFrameworkVersion", "v" + SolutionTask.Project.TargetFramework.Version.ToString());

            //evaluating
            _guid = _msproj.GetEvaluatedProperty("ProjectGuid");
            _projectDirectory = new DirectoryInfo(_msproj.GetEvaluatedProperty("ProjectDir"));
            _projectPath = _msproj.GetEvaluatedProperty("ProjectPath");

            //TODO: honoring project's TargetFrameworkVersion is not working atm. System assemblies are resolved badly
            ////check if we targeting something else and throw a warning
            //if (targwarnings)
            //{
            //    string verString = _msproj.GetEvaluatedProperty("TargetFrameworkVersion");
            //    if (verString != null)
            //    {
            //        if (verString.StartsWith("v")) verString = verString.Substring(1);
            //        Version ver = new Version(verString);
            //        if (!ver.Equals(SolutionTask.Project.TargetFramework.Version))
            //        {
            //            Log(Level.Warning, "Project '{1}' targets framework {0}.", verString, Name);
            //        }
            //    }
            //}

            //project configuration
            ProjectEntry projectEntry = solution.ProjectEntries [_guid];
            if (projectEntry != null && projectEntry.BuildConfigurations != null) {
                foreach (ConfigurationMapEntry ce in projectEntry.BuildConfigurations) {
                    Configuration projectConfig = ce.Value;

                    ProjectConfigurations[projectConfig] = new MSBuildConfiguration(this, _msproj, projectConfig);
                }
            } else {
                Configuration projectConfig = new Configuration (cfgname, platform);
                ProjectConfigurations[projectConfig] = new MSBuildConfiguration(this, _msproj, projectConfig);
            }

            //references
            _references = new ArrayList();
            NAnt.MSBuild.BuildEngine.BuildItemGroup refs = _msproj.GetEvaluatedItemsByName("Reference");
            foreach (NAnt.MSBuild.BuildEngine.BuildItem r in refs) {
                string rpath = r.FinalItemSpec;
                string priv = r.GetMetadata("Private");
                string hintpath = r.GetMetadata("HintPath");
                string ext = r.GetMetadata("ExecutableExtension");

                ReferenceBase reference = new MSBuildAssemblyReference(
                    xmlDefinition, ReferencesResolver, this, gacCache,
                    rpath, priv, hintpath, ext);
                _references.Add(reference);
            }
            refs = _msproj.GetEvaluatedItemsByName("ProjectReference");
            foreach (NAnt.MSBuild.BuildEngine.BuildItem r in refs) {
                string pguid = r.GetMetadata("Project");
                string pname = r.GetMetadata("Name");
                string rpath = r.FinalItemSpec;
                string priv = r.GetMetadata("Private");
                ReferenceBase reference = new MSBuildProjectReference(
                    ReferencesResolver, this, solution, tfc, gacCache, outputDir,
                    pguid, pname, rpath, priv);
                _references.Add(reference);
            }

            if(generateDoc) {
                string xmlDocBuildFile = FileUtils.CombinePaths(OutputPath, this.Name + ".xml");

                //// make sure the output directory for the doc file exists
                //if (!Directory.Exists(Path.GetDirectoryName(xmlDocBuildFile))) {
                //    Directory.CreateDirectory(Path.GetDirectoryName(xmlDocBuildFile));
                //}

                // add built documentation file as extra output file
                ExtraOutputFiles[xmlDocBuildFile] = Path.GetFileName(xmlDocBuildFile);

                _msproj.GlobalProperties.SetProperty("DocumentationFile", xmlDocBuildFile);
            }
        }
Пример #20
0
        public ProjectBase LoadProject(SolutionBase solution, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver referencesResolver, DirectoryInfo outputDir, string path) {
            // check if this a new project
            if (!_cachedProjects.Contains(path)) {
                ProjectBase project = CreateProject(solution, solutionTask, 
                    tfc, gacCache, referencesResolver, outputDir, path);
                _cachedProjects[path] = project;
            }

            return (ProjectBase) _cachedProjects[path];
        }
Пример #21
0
 public JSharpProject(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir) : base(solution, projectPath, xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir)
 {
 }
Пример #22
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);
        }