Base class for all project classes.
        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);
        }
Exemple #2
0
        protected VcConfigurationBase(XmlElement elem, ProjectBase parentProject, DirectoryInfo outputDir)
            : base(parentProject)
        {
            if (elem == null) {
                throw new ArgumentNullException("elem");
            }

            // output directory override (if specified)
            _outputDir = outputDir;

            // get name of configuration (also contains the targeted platform)
            _name = elem.GetAttribute("Name");

            XmlNodeList tools = elem.GetElementsByTagName("Tool");
            foreach (XmlElement toolElem in tools) {
                string toolName = toolElem.GetAttribute("Name");
                Hashtable htToolSettings = CollectionsUtil.CreateCaseInsensitiveHashtable();

                foreach(XmlAttribute attr in toolElem.Attributes) {
                    if (attr.Name != "Name") {
                        htToolSettings[attr.Name] = attr.Value;
                    }
                }

                Tools[toolName] = htToolSettings;
            }
        }
        public ManagedWrapperReference(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, GacCache gacCache, ProjectSettings projectSettings)
            : base(xmlDefinition, referencesResolver, parent, gacCache)
        {
            if (projectSettings == null) {
                throw new ArgumentNullException("projectSettings");
            }

            _projectSettings = projectSettings;

            // determine name of wrapper reference
            XmlAttribute wrapperNameAttribute = XmlDefinition.Attributes["Name"];
            if (wrapperNameAttribute != null) {
                _name = wrapperNameAttribute.Value;
            }

            // determine wrapper tool
            XmlAttribute toolAttribute = XmlDefinition.Attributes["WrapperTool"];
            if (toolAttribute == null) {
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                    "Wrapper tool for reference \"{0}\" in project \"{1}\" could"
                    + " not be determined.", Name, Parent.Name),
                    Location.UnknownLocation);
            }
            _wrapperTool = toolAttribute.Value;

            // determine if there's a primary interop assembly for the typelib
            _primaryInteropAssembly = GetPrimaryInteropAssembly();

            // determine filename of wrapper assembly
            _wrapperAssembly = ResolveWrapperAssembly();
        }
 public ManagedProjectReference(ProjectBase project, ProjectBase parent, bool isPrivateSpecified, bool isPrivate)
     : base(project.ReferencesResolver, parent)
 {
     _project = project;
     _isPrivateSpecified = isPrivateSpecified;
     _isPrivate = isPrivate;
 }
Exemple #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConfigurationBase" /> 
        /// class with the given <see cref="ProjectBase" />.
        /// </summary>
        /// <param name="project">The project of the configuration.</param>
        protected ConfigurationBase(ProjectBase project) {
            if (project == null) {
                throw new ArgumentNullException("project");
            }

            _project = project;
            _extraOutputFiles = CollectionsUtil.CreateCaseInsensitiveHashtable();
        }
        public MSBuildProjectReference(
            ReferencesResolver referencesResolver, ProjectBase parent,
            ProjectBase project, bool isPrivateSpecified, bool isPrivate)

            :base(referencesResolver, parent) {
            _helper = new MSBuildReferenceHelper(isPrivateSpecified, isPrivate);
            _project = project;
        }
Exemple #7
0
        protected FileReferenceBase(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, GacCache gacCache) : base(referencesResolver, parent) {
            if (xmlDefinition == null) {
                throw new ArgumentNullException("xmlDefinition");
            }
            if (gacCache == null) {
                throw new ArgumentNullException("gacCache");
            }

            _xmlDefinition = xmlDefinition;
            _gacCache = gacCache;
        }
 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);
 }
 public MSBuildAssemblyReference(XmlElement xe, ReferencesResolver referencesResolver, ProjectBase parent, GacCache gacCache, string name, string priv, string hintpath)
     : base(new DummyXmlElement(xe.OwnerDocument), referencesResolver, parent, gacCache)
 {
     if (name.Contains(",")) {
         //fully specified reference. Hmmm - just ignore it for now.
         name = name.Split(',')[0];
         if (hintpath.Length == 0)  //hintpath workaround
             hintpath = "." + Path.DirectorySeparatorChar + name + ".dll";
     }
     _name = name;
     _helper = new MSBuildReferenceHelper(priv, false);
     _hintpath = hintpath;
     _assemblyFile = ResolveAssemblyReference();
 }
        public ManagedAssemblyReference(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, GacCache gacCache) : base(xmlDefinition, referencesResolver, parent, gacCache) {
            XmlAttribute privateAttribute = xmlDefinition.Attributes["Private"];
            if (privateAttribute != null) {
                _isPrivateSpecified = true;
                _isPrivate = bool.Parse(privateAttribute.Value);
            }

            // determine name of reference
            XmlAttribute assemblyNameAttribute = XmlDefinition.Attributes["AssemblyName"];
            if (assemblyNameAttribute != null) {
                _name = assemblyNameAttribute.Value;
            }

            _assemblyFile = ResolveAssemblyReference();
        }
Exemple #11
0
        public VcAssemblyReference(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, GacCache gacCache) : base(xmlDefinition, referencesResolver, parent, gacCache) {
            XmlAttribute privateAttribute = xmlDefinition.Attributes["CopyLocal"];
            if (privateAttribute != null) {
                _isPrivateSpecified = true;
                _isPrivate = bool.Parse(privateAttribute.Value);
            }

            // determine name of reference by taking filename part of relative
            // path, without extension
            XmlAttribute relativePathAttribute = XmlDefinition.Attributes["RelativePath"];
            if (relativePathAttribute != null) {
                _name = Path.GetFileNameWithoutExtension(relativePathAttribute.Value);
            }

            _assemblyFile = ResolveAssemblyReference();
        }
Exemple #12
0
        public VcWrapperReference(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, GacCache gacCache) : base(xmlDefinition, referencesResolver, parent, gacCache) {
            // determine name of type library
            _name = GetTypeLibraryName(GetTypeLibrary());

            // determine wrapper tool
            XmlAttribute toolAttribute = XmlDefinition.Attributes["WrapperTool"];
            if (toolAttribute == null) {
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                    "Wrapper tool for reference \"{0}\" in project \"{1}\" could"
                    + " not be determined.", Name, Parent.Name), 
                    Location.UnknownLocation);
            }
            _wrapperTool = toolAttribute.Value;

            // determine if there's a primary interop assembly for the typelib
            _primaryInteropAssembly = GetPrimaryInteropAssembly();

            // determine filename of wrapper assembly
            _wrapperAssembly = ResolveWrapperAssembly();
        }
Exemple #13
0
 /// <summary>
 /// Determines whether a <see cref="ProjectBase"/> is in the collection.
 /// </summary>
 /// <param name="item">The <see cref="ProjectBase"/> to locate in the collection.</param> 
 /// <returns>
 /// <see langword="true" /> if <paramref name="item"/> is found in the 
 /// collection; otherwise, <see langword="false" />.
 /// </returns>
 public bool Contains(ProjectBase item)
 {
     return base.List.Contains(item);
 }
Exemple #14
0
 /// <summary>
 /// Adds a <see cref="ProjectBase"/> to the end of the collection.
 /// </summary>
 /// <param name="item">The <see cref="ProjectBase"/> to be added to the end of the collection.</param> 
 /// <returns>The position into which the new element was inserted.</returns>
 public int Add(ProjectBase item)
 {
     return base.List.Add(item);
 }
 public ManagedProjectReference(ProjectBase project, ProjectBase parent, bool isPrivateSpecified, bool isPrivate) : base(project.ReferencesResolver, parent)
 {
     _project            = project;
     _isPrivateSpecified = isPrivateSpecified;
     _isPrivate          = isPrivate;
 }
        public ManagedWrapperReference(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, GacCache gacCache, ProjectSettings projectSettings) : base(xmlDefinition, referencesResolver, parent, gacCache)
        {
            if (projectSettings == null)
            {
                throw new ArgumentNullException("projectSettings");
            }

            _projectSettings = projectSettings;

            // determine name of wrapper reference
            XmlAttribute wrapperNameAttribute = XmlDefinition.Attributes["Name"];

            if (wrapperNameAttribute != null)
            {
                _name = wrapperNameAttribute.Value;
            }

            // determine wrapper tool
            XmlAttribute toolAttribute = XmlDefinition.Attributes["WrapperTool"];

            if (toolAttribute == null)
            {
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                       "Wrapper tool for reference \"{0}\" in project \"{1}\" could"
                                                       + " not be determined.", Name, Parent.Name),
                                         Location.UnknownLocation);
            }
            _wrapperTool = toolAttribute.Value;

            // determine if there's a primary interop assembly for the typelib
            _primaryInteropAssembly = GetPrimaryInteropAssembly();

            // determine filename of wrapper assembly
            _wrapperAssembly = ResolveWrapperAssembly();
        }
Exemple #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WrapperReferenceBase"/> class.
 /// </summary>
 /// <param name="xmlDefinition">The XML definition.</param>
 /// <param name="referencesResolver">The references resolver.</param>
 /// <param name="parent">The parent.</param>
 /// <param name="gacCache">The gac cache.</param>
 protected WrapperReferenceBase(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, GacCache gacCache)
     : base(xmlDefinition, referencesResolver, parent, gacCache)
 {
 }
Exemple #18
0
        protected VcConfigurationBase(string configName, ProjectBase parentProject, DirectoryInfo outputDir)
            : base(parentProject)
        {
            _name = configName;

            // set output directory (if specified)
            _outputDir = outputDir;
        }
Exemple #19
0
 public override ProjectReferenceBase CreateProjectReference(ProjectBase project, bool isPrivateSpecified, bool isPrivate)
 {
     return new MSBuildProjectReference(ReferencesResolver, this, project, isPrivateSpecified, isPrivate);
 }
Exemple #20
0
 protected WrapperReferenceBase(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, GacCache gacCache) : base(xmlDefinition, referencesResolver, parent, gacCache)
 {
 }
Exemple #21
0
        /// <summary>
        /// Converts assembly references to projects to project references, adding
        /// a build dependency.c
        /// </summary>
        /// <param name="project">The <see cref="ProjectBase" /> to analyze.</param>
        /// <param name="solutionConfiguration">The solution configuration that is built.</param>
        /// <param name="builtProjects"><see cref="Hashtable" /> containing list of projects that have been built.</param>
        /// <param name="failedProjects"><see cref="Hashtable" /> containing list of projects that failed to build.</param>
        protected bool FixProjectReferences(ProjectBase project, Configuration solutionConfiguration, Hashtable builtProjects, Hashtable failedProjects)
        {
            // check if the project still has dependencies that have not been
            // built
            if (HasDirtyProjectDependency(project, builtProjects))
            {
                return(false);
            }

            ConfigurationBase projectConfig = project.BuildConfigurations[solutionConfiguration];

            // check if the project actually supports the build configuration
            if (projectConfig == null)
            {
                return(false);
            }

            Log(Level.Verbose, "Fixing up references...");

            ArrayList projectReferences = (ArrayList)
                                          project.References.Clone();

            bool referencesFailedProject = false;

            foreach (ReferenceBase reference in projectReferences)
            {
                AssemblyReferenceBase assemblyReference = reference as
                                                          AssemblyReferenceBase;
                if (assemblyReference == null)
                {
                    // project references and wrappers don't
                    // need to be fixed
                    continue;
                }

                ProjectBase projectRef = null;

                string outputFile = assemblyReference.GetPrimaryOutputFile(
                    solutionConfiguration);
                if (outputFile == null)
                {
                    continue;
                }

                if (_htOutputFiles.Contains(outputFile))
                {
                    // if the reference is an output file of
                    // another build configuration of a project
                    // and this output file wasn't built before
                    // then use the output file for the current
                    // build configuration
                    //
                    // eg. a project file might be referencing the
                    // the debug assembly of a given project as an
                    // assembly reference, but the projects are now
                    // being built in release configuration, so
                    // instead of failing the build we use the
                    // release assembly of that project

                    // Note that this was designed to intentionally
                    // deviate from VS.NET's building strategy.

                    // See "Reference Configuration Matching" at http://nant.sourceforge.net/wiki/index.php/SolutionTask
                    // for why we must always convert file references to project references

                    // If we want a different behaviour, this
                    // should be controlled by a flag

                    projectRef = ProjectEntries[(string)_htOutputFiles[outputFile]].Project;
                }
                else if (_outputDir != null)
                {
                    // if an output directory is set, then the
                    // assembly reference might not have been
                    // resolved during Reference initialization,
                    // as the output file of the project might
                    // not have existed at that time
                    //
                    // this will perform matching on file name
                    // only, so its really tricky (VS.NET does
                    // not support this)

                    string projectOutput = FileUtils.CombinePaths(
                        _outputDir.FullName, Path.GetFileName(
                            outputFile));
                    if (_htOutputFiles.Contains(projectOutput))
                    {
                        projectRef = (ProjectBase)ProjectEntries[
                            (string)_htOutputFiles[projectOutput]].Project;
                    }
                }

                // try matching assembly reference and project on assembly name
                // if the assembly file does not exist
                if (projectRef == null && !System.IO.File.Exists(outputFile))
                {
                    foreach (ProjectEntry projectEntry in ProjectEntries)
                    {
                        // we can only do this for managed projects, as we only have
                        // an assembly name for these
                        ManagedProjectBase managedProject = projectEntry.Project as ManagedProjectBase;
                        if (managedProject == null)
                        {
                            continue;
                        }
                        // check if the assembly names match
                        if (assemblyReference.Name == managedProject.ProjectSettings.AssemblyName)
                        {
                            projectRef = managedProject;
                            break;
                        }
                    }
                }

                if (projectRef != null)
                {
                    if (!referencesFailedProject && failedProjects.ContainsKey(projectRef.Guid))
                    {
                        referencesFailedProject = true;
                    }

                    ProjectReferenceBase projectReference = assemblyReference.
                                                            CreateProjectReference(projectRef);
                    Log(Level.Verbose, "Converted assembly reference to project reference: {0} -> {1}",
                        assemblyReference.Name, projectReference.Name);

                    // remove assembly reference from project
                    project.References.Remove(assemblyReference);

                    // add project reference instead
                    project.References.Add(projectReference);

                    // unless referenced project has already been build, add
                    // referenced project as project dependency
                    if (!builtProjects.Contains(projectReference.Project.Guid))
                    {
                        project.ProjectDependencies.Add(projectReference.Project);
                    }
                }
            }

            return(referencesFailedProject);
        }
Exemple #22
0
        protected void GetDependenciesFromProjects(Configuration solutionConfiguration)
        {
            Log(Level.Verbose, "Gathering additional dependencies...");

            // first get all of the output files
            foreach (ProjectEntry projectEntry in ProjectEntries)
            {
                ProjectBase project = projectEntry.Project;

                if (project == null)
                {
                    // skip projects that are not loaded/supported
                    continue;
                }

                foreach (ConfigurationBase projectConfig in project.ProjectConfigurations.Values)
                {
                    string projectOutputFile = projectConfig.OutputPath;
                    if (projectOutputFile != null)
                    {
                        _htOutputFiles[projectOutputFile] = project.Guid;
                    }
                }
            }

            // if one of output files resides in reference search path - circle began
            // we must build project with that outputFile before projects referencing it
            // (similar to project dependency) VS.NET 7.0/7.1 do not address this problem

            // build list of output which reside in such folders
            Hashtable outputsInAssemblyFolders = CollectionsUtil.CreateCaseInsensitiveHashtable();

            foreach (DictionaryEntry de in _htOutputFiles)
            {
                string outputfile = (string)de.Key;
                string folder     = Path.GetDirectoryName(outputfile);

                if (_solutionTask.AssemblyFolderList.Contains(folder))
                {
                    outputsInAssemblyFolders[Path.GetFileName(outputfile)] =
                        (string)de.Value;
                }
            }

            // build the dependency list
            foreach (ProjectEntry projectEntry in ProjectEntries)
            {
                ProjectBase project = projectEntry.Project;

                if (project == null)
                {
                    // skip projects that are not loaded/supported
                    continue;
                }

                // check if project actually supports the build configuration
                ConfigurationBase projectConfig = project.BuildConfigurations[solutionConfiguration];
                if (projectConfig == null)
                {
                    continue;
                }

                // ensure output directory exists. VS creates output directories
                // before it starts compiling projects
                if (!projectConfig.OutputDir.Exists)
                {
                    projectConfig.OutputDir.Create();
                    projectConfig.OutputDir.Refresh();
                }

                foreach (ReferenceBase reference in project.References)
                {
                    ProjectReferenceBase projectReference = reference as ProjectReferenceBase;
                    if (projectReference != null)
                    {
                        project.ProjectDependencies.Add(projectReference.Project);
                    }
                    else
                    {
                        string outputFile = reference.GetPrimaryOutputFile(
                            solutionConfiguration);
                        // if we reference an assembly in an AssemblyFolder
                        // that is an output directory of another project,
                        // then add dependency on that project
                        if (outputFile == null)
                        {
                            continue;
                        }

                        string dependencyGuid = (string)outputsInAssemblyFolders[Path.GetFileName(outputFile)];
                        if (dependencyGuid == null)
                        {
                            continue;
                        }

                        ProjectEntry dependencyEntry = ProjectEntries[dependencyGuid];
                        if (dependencyEntry != null && dependencyEntry.Project != null)
                        {
                            project.ProjectDependencies.Add(dependencyEntry.Project);
                        }
                    }
                }
            }
        }
Exemple #23
0
        /// <summary>
        /// Loads the projects from the file system and stores them in an
        /// instance variable.
        /// </summary>
        /// <param name="gacCache"><see cref="GacCache" /> instance to use to determine whether an assembly is located in the Global Assembly Cache.</param>
        /// <param name="refResolver"><see cref="ReferencesResolver" /> instance to use to determine location and references of assemblies.</param>
        /// <param name="explicitProjectDependencies">TODO</param>
        /// <exception cref="BuildException">A project GUID in the solution file does not match the actual GUID of the project in the project file.</exception>
        protected void LoadProjects(GacCache gacCache, ReferencesResolver refResolver, Hashtable explicitProjectDependencies)
        {
            Log(Level.Verbose, "Loading projects...");

            FileSet excludes = _solutionTask.ExcludeProjects;

            foreach (ProjectEntry projectEntry in ProjectEntries)
            {
                string projectPath = projectEntry.Path;
                string projectGuid = projectEntry.Guid;

                // determine whether project is on case-sensitive filesystem,
                bool caseSensitive = PlatformHelper.IsVolumeCaseSensitive(projectPath);

                // indicates whether the project should be skipped (excluded)
                bool skipProject = false;

                // check whether project should be excluded from build
                foreach (string excludedProjectFile in excludes.FileNames)
                {
                    if (string.Compare(excludedProjectFile, projectPath, !caseSensitive, CultureInfo.InvariantCulture) == 0)
                    {
                        Log(Level.Verbose, "Excluding project '{0}'.",
                            projectPath);
                        // do not load project
                        skipProject = true;
                        // we have a match, so quit looking
                        break;
                    }
                }

                if (skipProject)
                {
                    // remove dependencies for excluded projects
                    if (explicitProjectDependencies.ContainsKey(projectGuid))
                    {
                        explicitProjectDependencies.Remove(projectGuid);
                    }

                    // project was excluded, move on to next project
                    continue;
                }

                Log(Level.Verbose, "Loading project '{0}'.", projectPath);
                ProjectBase p = _solutionTask.ProjectFactory.LoadProject(this, _solutionTask,
                                                                         _tfc, gacCache, refResolver, _outputDir, projectPath);
                if (p == null)
                {
                    Log(Level.Warning, "Project '{0}' is of unsupported type. Skipping.", projectPath);
                    // skip the project
                    continue;
                }
                if (p.Guid == null || p.Guid.Length == 0)
                {
                    p.Guid = FindGuidFromPath(projectPath);
                }

                // add project to entry
                projectEntry.Project = p;

                // set project build configuration
                SetProjectBuildConfiguration(projectEntry);
            }

            // add explicit dependencies (as set in VS.NET) to individual projects
            foreach (DictionaryEntry dependencyEntry in explicitProjectDependencies)
            {
                string    projectGuid  = (string)dependencyEntry.Key;
                Hashtable dependencies = (Hashtable)dependencyEntry.Value;

                ProjectEntry projectEntry = ProjectEntries[projectGuid];
                if (projectEntry == null)
                {
                    throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                           "Dependencies for project \'{0}\' could not be analyzed."
                                                           + " Project is not included.", projectGuid),
                                             Location.UnknownLocation);
                }

                ProjectBase project = projectEntry.Project;

                // make sure project is loaded
                if (project == null)
                {
                    throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                           "Dependencies for project \'{0}\' could not be analyzed."
                                                           + " Project is not loaded.", projectGuid),
                                             Location.UnknownLocation);
                }

                foreach (string dependentProjectGuid in dependencies.Keys)
                {
                    ProjectEntry dependentEntry = ProjectEntries[dependentProjectGuid];
                    if (dependentEntry == null || dependentEntry.Project == null)
                    {
                        Log(Level.Warning, "Project \"{0}\": ignored dependency"
                            + " on project \"{1}\", which is not included.",
                            project.Name, dependentProjectGuid);
                        continue;
                    }

                    project.ProjectDependencies.Add(dependentEntry.Project);
                }
            }
        }
Exemple #24
0
        public bool Compile(Configuration solutionConfiguration)
        {
            Hashtable htProjectsDone   = CollectionsUtil.CreateCaseInsensitiveHashtable();
            Hashtable htFailedProjects = CollectionsUtil.CreateCaseInsensitiveHashtable();
            ArrayList failedProjects   = new ArrayList();
            bool      success          = true;

            GetDependenciesFromProjects(solutionConfiguration);

            while (true)
            {
                bool compiledThisRound = false;

                foreach (ProjectEntry projectEntry in ProjectEntries)
                {
                    ProjectBase project = projectEntry.Project;

                    if (project == null)
                    {
                        // mark project done
                        htProjectsDone[projectEntry.Guid] = null;

                        // skip projects that are not loaded/supported
                        continue;
                    }

                    if (htProjectsDone.Contains(project.Guid))
                    {
                        continue;
                    }

                    bool failed = htFailedProjects.Contains(project.Guid);
                    if (!failed)
                    {
                        // attempt to convert assembly references to project
                        // references
                        //
                        // this might affect the build order as it can add
                        // project dependencies
                        if (FixProjectReferences(project, solutionConfiguration, htProjectsDone, htFailedProjects))
                        {
                            // mark project failed if it references a project that
                            // failed to build
                            //
                            // this can only happen when assembly reference was
                            // was fixed to a project reference (that already failed
                            // to build before the fix-up)
                            failed = true;

                            // avoid running through the fix-up next time
                            htFailedProjects[project.Guid] = null;
                        }
                    }

                    if (!HasDirtyProjectDependency(project, htProjectsDone))
                    {
                        try {
                            if (!_htReferenceProjects.Contains(project.Guid) && (failed || !project.Compile(solutionConfiguration)))
                            {
                                if (!failed)
                                {
                                    Log(Level.Error, "Project '{0}' failed!", project.Name);
                                    Log(Level.Error, "Continuing build with non-dependent projects.");
                                    failedProjects.Add(project.Name);
                                }

                                success = false;
                                htFailedProjects[project.Guid] = null;

                                // mark the projects referencing this one as failed
                                foreach (ProjectEntry entry in ProjectEntries)
                                {
                                    ProjectBase dependentProject = entry.Project;
                                    if (dependentProject == null)
                                    {
                                        // skip projects that are not loaded/supported
                                    }
                                    // if the project depends on the failed
                                    // project, then also mark it failed
                                    if (dependentProject.ProjectDependencies.Contains(project))
                                    {
                                        htFailedProjects[dependentProject.Guid] = null;
                                    }
                                }
                            }
                        } catch (BuildException) {
                            // Re-throw build exceptions
                            throw;
                        } catch (Exception e) {
                            throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                                   "Unexpected error while compiling project '{0}'", project.Name),
                                                     Location.UnknownLocation, e);
                        }

                        compiledThisRound = true;

                        // mark project done
                        htProjectsDone[project.Guid] = null;
                    }
                }

                if (ProjectEntries.Count == htProjectsDone.Count)
                {
                    break;
                }
                if (!compiledThisRound)
                {
                    throw new BuildException("Circular dependency detected.", Location.UnknownLocation);
                }
            }

            if (failedProjects.Count > 0)
            {
                Log(Level.Error, string.Empty);
                Log(Level.Error, "Solution failed to build!  Failed projects were:");
                foreach (string projectName in failedProjects)
                {
                    Log(Level.Error, "  - " + projectName);
                }
            }

            return(success);
        }
        public ManagedAssemblyReference(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, GacCache gacCache) : base(xmlDefinition, referencesResolver, parent, gacCache)
        {
            XmlAttribute privateAttribute = xmlDefinition.Attributes["Private"];

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

            // determine name of reference
            XmlAttribute assemblyNameAttribute = XmlDefinition.Attributes["AssemblyName"];

            if (assemblyNameAttribute != null)
            {
                _name = assemblyNameAttribute.Value;
            }

            _assemblyFile = ResolveAssemblyReference();
        }
Exemple #26
0
 protected ReferenceBase(ReferencesResolver referencesResolver, ProjectBase parent)
 {
     _referencesResolver = referencesResolver;
     _parent = parent;
 }
Exemple #27
0
        /// <summary>
        /// Converts assembly references to projects to project references, adding
        /// a build dependency.c
        /// </summary>
        /// <param name="project">The <see cref="ProjectBase" /> to analyze.</param>
        /// <param name="solutionConfiguration">The solution configuration that is built.</param>
        /// <param name="builtProjects"><see cref="Hashtable" /> containing list of projects that have been built.</param>
        /// <param name="failedProjects"><see cref="Hashtable" /> containing list of projects that failed to build.</param>
        protected bool FixProjectReferences(ProjectBase project, Configuration solutionConfiguration, Hashtable builtProjects, Hashtable failedProjects)
        {
            // check if the project still has dependencies that have not been
            // built
            if (HasDirtyProjectDependency(project, builtProjects)) {
                return false;
            }

            ConfigurationBase projectConfig = project.BuildConfigurations[solutionConfiguration];

            // check if the project actually supports the build configuration
            if (projectConfig == null) {
                return false;
            }

            Log(Level.Verbose, "Fixing up references...");

            ArrayList projectReferences = (ArrayList)
                project.References.Clone();

            bool referencesFailedProject = false;

            foreach (ReferenceBase reference in projectReferences) {
                AssemblyReferenceBase assemblyReference = reference as
                    AssemblyReferenceBase;
                if (assemblyReference == null) {
                    // project references and wrappers don't
                    // need to be fixed
                    continue;
                }

                ProjectBase projectRef = null;

                string outputFile = assemblyReference.GetPrimaryOutputFile(
                    solutionConfiguration);
                if (outputFile == null) {
                    continue;
                }

                if (_htOutputFiles.Contains(outputFile)) {
                    // if the reference is an output file of
                    // another build configuration of a project
                    // and this output file wasn't built before
                    // then use the output file for the current
                    // build configuration
                    //
                    // eg. a project file might be referencing the
                    // the debug assembly of a given project as an
                    // assembly reference, but the projects are now
                    // being built in release configuration, so
                    // instead of failing the build we use the
                    // release assembly of that project

                    // Note that this was designed to intentionally
                    // deviate from VS.NET's building strategy.

                    // See "Reference Configuration Matching" at http://nant.sourceforge.net/wiki/index.php/SolutionTask
                    // for why we must always convert file references to project references

                    // If we want a different behaviour, this
                    // should be controlled by a flag

                    projectRef = ProjectEntries[(string) _htOutputFiles[outputFile]].Project;
                } else if (_outputDir != null) {
                    // if an output directory is set, then the
                    // assembly reference might not have been
                    // resolved during Reference initialization,
                    // as the output file of the project might
                    // not have existed at that time
                    //
                    // this will perform matching on file name
                    // only, so its really tricky (VS.NET does
                    // not support this)

                    string projectOutput = FileUtils.CombinePaths(
                        _outputDir.FullName, Path.GetFileName(
                        outputFile));
                    if (_htOutputFiles.Contains(projectOutput)) {
                        projectRef = (ProjectBase) ProjectEntries[
                            (string) _htOutputFiles[projectOutput]].Project;
                    }
                }

                // try matching assembly reference and project on assembly name
                // if the assembly file does not exist
                if (projectRef == null && !System.IO.File.Exists(outputFile)) {
                    foreach (ProjectEntry projectEntry in ProjectEntries) {
                        // we can only do this for managed projects, as we only have
                        // an assembly name for these
                        ManagedProjectBase managedProject = projectEntry.Project as ManagedProjectBase;
                        if (managedProject == null) {
                            continue;
                        }
                        // check if the assembly names match
                        if (assemblyReference.Name == managedProject.ProjectSettings.AssemblyName) {
                            projectRef = managedProject;
                            break;
                        }
                    }
                }

                if (projectRef != null) {
                    if (!referencesFailedProject && failedProjects.ContainsKey(projectRef.Guid)) {
                        referencesFailedProject = true;
                    }

                    ProjectReferenceBase projectReference = assemblyReference.
                        CreateProjectReference(projectRef);
                    Log(Level.Verbose, "Converted assembly reference to project reference: {0} -> {1}",
                        assemblyReference.Name, projectReference.Name);

                    // remove assembly reference from project
                    project.References.Remove(assemblyReference);

                    // add project reference instead
                    project.References.Add(projectReference);

                    // unless referenced project has already been build, add
                    // referenced project as project dependency
                    if (!builtProjects.Contains(projectReference.Project.Guid)) {
                        project.ProjectDependencies.Add(projectReference.Project);
                    }
                }
            }

            return referencesFailedProject;
        }
 public ProjectReferenceBase CreateProjectReference(ProjectBase project)
 {
     return project.CreateProjectReference(project, IsPrivateSpecified,
         IsPrivate);
 }
Exemple #29
0
 /// <summary>
 /// Copies the entire collection to a compatible one-dimensional array, starting at the specified index of the target array.        
 /// </summary>
 /// <param name="array">The one-dimensional array that is the destination of the elements copied from the collection. The array must have zero-based indexing.</param> 
 /// <param name="index">The zero-based index in <paramref name="array"/> at which copying begins.</param>
 public void CopyTo(ProjectBase[] array, int index)
 {
     base.List.CopyTo(array, index);
 }
Exemple #30
0
        protected FileReferenceBase(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, GacCache gacCache) : base(referencesResolver, parent)
        {
            if (xmlDefinition == null)
            {
                throw new ArgumentNullException("xmlDefinition");
            }
            if (gacCache == null)
            {
                throw new ArgumentNullException("gacCache");
            }

            _xmlDefinition = xmlDefinition;
            _gacCache      = gacCache;
        }
Exemple #31
0
 /// <summary>
 /// Inserts a <see cref="ProjectBase"/> into the collection at the specified index.
 /// </summary>
 /// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param>
 /// <param name="item">The <see cref="ProjectBase"/> to insert.</param>
 public void Insert(int index, ProjectBase item)
 {
     base.List.Insert(index, item);
 }
 protected ProjectReferenceBase(ReferencesResolver referencesResolver, ProjectBase parent)
     : base(referencesResolver, parent)
 {
 }
Exemple #33
0
 public abstract ProjectReferenceBase CreateProjectReference(
     ProjectBase project, bool isPrivateSpecified, bool isPrivate);
Exemple #34
0
 /// <summary>
 /// Determines whether any of the project dependencies of the specified
 /// project still needs to be built.
 /// </summary>
 /// <param name="project">The <see cref="ProjectBase" /> to analyze.</param>
 /// <param name="builtProjects"><see cref="Hashtable" /> containing list of projects that have been built.</param>
 /// <returns>
 /// <see langword="true" /> if one of the project dependencies has not
 /// yet been built; otherwise, <see langword="false" />.
 /// </returns>
 private bool HasDirtyProjectDependency(ProjectBase project, Hashtable builtProjects)
 {
     foreach (ProjectBase projectDependency in project.ProjectDependencies) {
         if (!builtProjects.ContainsKey(projectDependency.Guid)) {
             return true;
         }
     }
     return false;
 }
        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);
        }
Exemple #36
0
 /// <summary>
 /// Retrieves the index of a specified <see cref="ProjectBase"/> object in the collection.
 /// </summary>
 /// <param name="item">The <see cref="ProjectBase"/> object for which the index is returned.</param> 
 /// <returns>
 /// The index of the specified <see cref="ProjectBase"/>. If the <see cref="ProjectBase"/> is not currently a member of the collection, it returns -1.
 /// </returns>
 public int IndexOf(ProjectBase item)
 {
     return base.List.IndexOf(item);
 }
Exemple #37
0
 protected ReferenceBase(ReferencesResolver referencesResolver, ProjectBase parent)
 {
     _referencesResolver = referencesResolver;
     _parent             = parent;
 }
Exemple #38
0
 /// <summary>
 /// Removes a member from the collection.
 /// </summary>
 /// <param name="item">The <see cref="ProjectBase"/> to remove from the collection.</param>
 public void Remove(ProjectBase item)
 {
     base.List.Remove(item);
 }
Exemple #39
0
 /// <summary>
 /// Determines whether a <see cref="ProjectBase"/> is in the collection.
 /// </summary>
 /// <param name="item">The <see cref="ProjectBase"/> to locate in the collection.</param>
 /// <returns>
 /// <see langword="true" /> if <paramref name="item"/> is found in the
 /// collection; otherwise, <see langword="false" />.
 /// </returns>
 public bool Contains(ProjectBase item)
 {
     return(base.List.Contains(item));
 }
Exemple #40
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProjectBaseCollection"/> class
 /// with the specified array of <see cref="ProjectBase"/> instances.
 /// </summary>
 public ProjectBaseCollection(ProjectBase[] value)
 {
     AddRange(value);
 }
Exemple #41
0
 /// <summary>
 /// Retrieves the index of a specified <see cref="ProjectBase"/> object in the collection.
 /// </summary>
 /// <param name="item">The <see cref="ProjectBase"/> object for which the index is returned.</param>
 /// <returns>
 /// The index of the specified <see cref="ProjectBase"/>. If the <see cref="ProjectBase"/> is not currently a member of the collection, it returns -1.
 /// </returns>
 public int IndexOf(ProjectBase item)
 {
     return(base.List.IndexOf(item));
 }
Exemple #42
0
 /// <summary>
 /// Adds the elements of a <see cref="ProjectBase"/> array to the end of the collection.
 /// </summary>
 /// <param name="items">The array of <see cref="ProjectBase"/> elements to be added to the end of the collection.</param> 
 public void AddRange(ProjectBase[] items)
 {
     for (int i = 0; (i < items.Length); i = (i + 1)) {
         Add(items[i]);
     }
 }
        public VcAssemblyReference(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, GacCache gacCache) : base(xmlDefinition, referencesResolver, parent, gacCache)
        {
            XmlAttribute privateAttribute = xmlDefinition.Attributes["CopyLocal"];

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

            // determine name of reference by taking filename part of relative
            // path, without extension
            XmlAttribute relativePathAttribute = XmlDefinition.Attributes["RelativePath"];

            if (relativePathAttribute != null)
            {
                _name = Path.GetFileNameWithoutExtension(relativePathAttribute.Value);
            }

            _assemblyFile = ResolveAssemblyReference();
        }
Exemple #44
0
 public override ProjectReferenceBase CreateProjectReference(ProjectBase project, bool isPrivateSpecified, bool isPrivate)
 {
     return new VcProjectReference(project, this, isPrivateSpecified,
         isPrivate);
 }
Exemple #45
0
 public ProjectReferenceBase CreateProjectReference(ProjectBase project)
 {
     return(project.CreateProjectReference(project, IsPrivateSpecified,
                                           IsPrivate));
 }
Exemple #46
0
 public abstract ProjectReferenceBase CreateProjectReference(
     ProjectBase project, bool isPrivateSpecified, bool isPrivate);
Exemple #47
0
 /// <summary>
 /// Adds a <see cref="ProjectBase"/> to the end of the collection.
 /// </summary>
 /// <param name="item">The <see cref="ProjectBase"/> to be added to the end of the collection.</param>
 /// <returns>The position into which the new element was inserted.</returns>
 public int Add(ProjectBase item)
 {
     return(base.List.Add(item));
 }
Exemple #48
0
 /// <summary>
 /// Inserts a <see cref="ProjectBase"/> into the collection at the specified index.
 /// </summary>
 /// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param>
 /// <param name="item">The <see cref="ProjectBase"/> to insert.</param>
 public void Insert(int index, ProjectBase item)
 {
     base.List.Insert(index, item);
 }
Exemple #49
0
 protected ProjectReferenceBase(ReferencesResolver referencesResolver, ProjectBase parent) : base(referencesResolver, parent)
 {
 }
Exemple #50
0
 /// <summary>
 /// Removes a member from the collection.
 /// </summary>
 /// <param name="item">The <see cref="ProjectBase"/> to remove from the collection.</param>
 public void Remove(ProjectBase item)
 {
     base.List.Remove(item);
 }
        public VcWrapperReference(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, GacCache gacCache) : base(xmlDefinition, referencesResolver, parent, gacCache)
        {
            // determine name of type library
            _name = GetTypeLibraryName(GetTypeLibrary());

            // determine wrapper tool
            XmlAttribute toolAttribute = XmlDefinition.Attributes["WrapperTool"];

            if (toolAttribute == null)
            {
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                       "Wrapper tool for reference \"{0}\" in project \"{1}\" could"
                                                       + " not be determined.", Name, Parent.Name),
                                         Location.UnknownLocation);
            }
            _wrapperTool = toolAttribute.Value;

            // determine if there's a primary interop assembly for the typelib
            _primaryInteropAssembly = GetPrimaryInteropAssembly();

            // determine filename of wrapper assembly
            _wrapperAssembly = ResolveWrapperAssembly();
        }