Exemple #1
0
 /// <summary>
 /// Logs a message with the given priority.
 /// </summary>
 /// <param name="messageLevel">The message priority at which the specified message is to be logged.</param>
 /// <param name="message">The message to log, containing zero or more format items.</param>
 /// <param name="args">An <see cref="object" /> array containing zero or more objects to format.</param>
 /// <remarks>
 /// The actual logging is delegated to the underlying task.
 /// </remarks>
 protected void Log(Level messageLevel, string message, params object[] args)
 {
     if (SolutionTask != null)
     {
         SolutionTask.Log(messageLevel, message, args);
     }
 }
        public SolutionBase LoadSolution(SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver)
        {
            if (solutionTask.SolutionFile == null)
            {
                return(new GenericSolution(solutionTask, tfc, gacCache, refResolver));
            }
            else
            {
                // determine the solution file format version

                // will hold the content of the solution file
                string fileContents;

                using (StreamReader sr = new StreamReader(solutionTask.SolutionFile.FullName, Encoding.Default, true)) {
                    fileContents = sr.ReadToEnd();
                }

                ISolutionBuildProvider provider = FindProvider(fileContents);
                if (provider != null)
                {
                    return(provider.GetInstance(fileContents, solutionTask, tfc, gacCache, refResolver));
                }
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                       "Solution format of file '{0}' is not supported.", solutionTask.SolutionFile),
                                         Location.UnknownLocation);
            }
        }
Exemple #3
0
 /// <summary>
 /// Logs a message with the given priority.
 /// </summary>
 /// <param name="messageLevel">The message priority at which the specified message is to be logged.</param>
 /// <param name="message">The message to be logged.</param>
 /// <remarks>
 /// The actual logging is delegated to the underlying task.
 /// </remarks>
 protected void Log(Level messageLevel, string message)
 {
     if (SolutionTask != null)
     {
         SolutionTask.Log(messageLevel, message);
     }
 }
Exemple #4
0
 public Resource(ManagedProjectBase project, FileInfo resourceSourceFile, string resourceSourceFileRelativePath, string dependentFile, SolutionTask solutionTask, GacCache gacCache)
 {
     _project                        = project;
     _resourceSourceFile             = resourceSourceFile;
     _resourceSourceFileRelativePath = resourceSourceFileRelativePath;
     _dependentFile                  = dependentFile;
     _solutionTask                   = solutionTask;
     _culture                        = CompilerBase.GetResourceCulture(resourceSourceFile.FullName,
                                                                       dependentFile);
 }
Exemple #5
0
 private SolutionBase(TempFileCollection tfc, SolutionTask solutionTask)
 {
     _htOutputFiles       = CollectionsUtil.CreateCaseInsensitiveHashtable();
     _projectEntries      = new ProjectEntryCollection();
     _htReferenceProjects = CollectionsUtil.CreateCaseInsensitiveHashtable();
     _tfc          = tfc;
     _solutionTask = solutionTask;
     _outputDir    = solutionTask.OutputDir;
     _webMaps      = solutionTask.WebMaps;
 }
Exemple #6
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]);
        }
Exemple #7
0
 protected SolutionBase(SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver) : this(tfc, solutionTask)
 {
     if (solutionTask.SolutionFile != null)
     {
         _file = solutionTask.SolutionFile;
     }
     else
     {
         LoadProjectGuids(new ArrayList(solutionTask.Projects.FileNames), false);
         LoadProjectGuids(new ArrayList(solutionTask.ReferenceProjects.FileNames), true);
         LoadProjects(gacCache, refResolver, CollectionsUtil.CreateCaseInsensitiveHashtable());
     }
 }
        public static SolutionBase LoadSolution(SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver) {
            if (solutionTask.SolutionFile == null) {
                return new GenericSolution(solutionTask, tfc, gacCache, refResolver);
            } else {
                // determine the solution file format version

                // will hold the content of the solution file
                string fileContents;

                using (StreamReader sr = new StreamReader(solutionTask.SolutionFile.FullName, Encoding.Default, true)) {
                    fileContents = sr.ReadToEnd();
                }

                Regex reSolutionFormat = new Regex(@"^\s*Microsoft Visual Studio Solution File, Format Version\s+(?<formatVersion>[0-9]+\.[0-9]+?)", RegexOptions.Singleline);
                MatchCollection matches = reSolutionFormat.Matches(fileContents);

                if (matches.Count == 0) {
                    throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                        "The format version of solution file '{0}' could not"
                        + " be determined.", solutionTask.SolutionFile.FullName), 
                        Location.UnknownLocation);
                } else {
                    string formatVersion = matches[0].Groups["formatVersion"].Value;
                    switch (formatVersion) {
                        case "7.0":
                            return new Rainier.Solution(fileContents, solutionTask, 
                                tfc, gacCache, refResolver);
                        case "8.0":
                            return new Everett.Solution(fileContents, solutionTask, 
                                tfc, gacCache, refResolver);
                        case "9.0":
                            throw new BuildException("Microsoft Visual Studio.NET"
                                + " 2005 solutions are not supported.", 
                                Location.UnknownLocation);
                        default:
                            throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                "Visual Studio Solution format version '{0}' is"
                                + " not supported.", formatVersion), Location.UnknownLocation);
                    }
                }
            }
        }
Exemple #9
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);
        }
Exemple #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProjectBase" /> class.
        /// </summary>
        protected ProjectBase(XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection temporaryFiles, GacCache gacCache, ReferencesResolver referencesResolver, DirectoryInfo outputDir)
        {
            if (xmlDefinition == null)
            {
                throw new ArgumentNullException("xmlDefinition");
            }
            if (solutionTask == null)
            {
                throw new ArgumentNullException("solutionTask");
            }
            if (temporaryFiles == null)
            {
                throw new ArgumentNullException("temporaryFiles");
            }
            if (gacCache == null)
            {
                throw new ArgumentNullException("gacCache");
            }
            if (referencesResolver == null)
            {
                throw new ArgumentNullException("referencesResolver");
            }

            _projectConfigurations = new ConfigurationDictionary();
            _buildConfigurations   = new ConfigurationDictionary();
            _extraOutputFiles      = CollectionsUtil.CreateCaseInsensitiveHashtable();

            // ensure the specified project is actually supported by this project
            VerifyProjectXml(xmlDefinition);

            _solutionTask   = solutionTask;
            _temporaryFiles = temporaryFiles;
            _outputDir      = outputDir;
            _gacCache       = gacCache;
            _refResolver    = referencesResolver;
            _productVersion = DetermineProductVersion(xmlDefinition);
        }
Exemple #11
0
        /// <summary>
        /// Is called each time a regular expression match is found during a
        /// <see cref="M:Regex.Replace(string, MatchEvaluator)" /> operation.
        /// </summary>
        /// <param name="m">The <see cref="Match" /> resulting from a single regular expression match during a <see cref="M:Regex.Replace(string, MatchEvaluator)" />.</param>
        /// <returns>
        /// The expanded <see cref="Match" />.
        /// </returns>
        /// <exception cref="BuildException">The macro is not supported.</exception>
        /// <exception cref="NotImplementedException">Expansion of a given macro is not yet implemented.</exception>
        private string EvaluateMacro(Match m)
        {
            string macro = m.Groups[1].Value;

            // expand using solution level macro's
            string expandedMacro = SolutionTask.ExpandMacro(macro);

            if (expandedMacro != null)
            {
                return(expandedMacro);
            }

            // expand using project level macro's
            expandedMacro = Parent.ExpandMacro(macro);
            if (expandedMacro != null)
            {
                return(expandedMacro);
            }

            throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                   "Macro \"{0}\", used by assembly reference \"{1}\" in project"
                                                   + " \"{2}\" is not supported in assembly references.", macro,
                                                   Name, Parent.Name), Location.UnknownLocation);
        }
Exemple #12
0
 public GenericSolution(SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver) : base(solutionTask, tfc, gacCache, refResolver)
 {
 }
 public SolutionBase GetInstance(string solutionContent, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver)
 {
     return(new WhidbeySolution(solutionContent, solutionTask, tfc, gacCache, refResolver));
 }
Exemple #14
0
        public Solution(string solutionContent, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver) : base(solutionTask, tfc, gacCache, refResolver)
        {
            Regex           reProjects     = new Regex(@"Project\(\""(?<package>\{.*?\})\"".*?\""(?<name>.*?)\"".*?\""(?<project>.*?)\"".*?\""(?<guid>.*?)\""(?<all>[\s\S]*?)EndProject", RegexOptions.Multiline);
            MatchCollection projectMatches = reProjects.Matches(solutionContent);

            Hashtable explicitProjectDependencies = CollectionsUtil.CreateCaseInsensitiveHashtable();

            foreach (Match projectMatch in projectMatches)
            {
                string project = projectMatch.Groups["project"].Value;
                string guid    = projectMatch.Groups["guid"].Value;

                // translate partial project path or URL to absolute path
                string fullProjectPath = TranslateProjectPath(solutionTask.SolutionFile.DirectoryName,
                                                              project);

                // check if project file actually exists
                if (!System.IO.File.Exists(fullProjectPath))
                {
                    throw CreateProjectDoesNotExistException(fullProjectPath);
                }

                bool isEnterpriseTemplateProject = ManagedProjectBase.IsEnterpriseTemplateProject(fullProjectPath);
                if (isEnterpriseTemplateProject)
                {
                    RecursiveLoadTemplateProject(fullProjectPath);
                }
                else
                {
                    // add project entry to collection
                    ProjectEntries.Add(new ProjectEntry(guid, fullProjectPath));
                }

                // set-up project dependencies
                Regex           reDependencies    = new Regex(@"^\s+(?<guid>\{[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}\})\s+=\s+(?<dep>\{[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}\})", RegexOptions.Multiline);
                MatchCollection dependencyMatches = reDependencies.Matches(projectMatch.Value);

                foreach (Match dependencyMatch in dependencyMatches)
                {
                    string dependency = dependencyMatch.Groups["dep"].Value;
                    // bug #1534864: an Enterprise Template project actually
                    // defines dependencies for the projects it contains, and
                    // is not added as a project itself
                    //
                    // Note: for non-ET projects both the "guid" and "dep" group
                    // have the same value, which is the guid of the project
                    // that the project containing the dependencies section
                    // depends upon
                    string projectGuid = isEnterpriseTemplateProject ?
                                         dependencyMatch.Groups["guid"].Value : guid;

                    if (!explicitProjectDependencies.ContainsKey(projectGuid))
                    {
                        explicitProjectDependencies[projectGuid] = CollectionsUtil.CreateCaseInsensitiveHashtable();
                    }
                    ((Hashtable)explicitProjectDependencies[projectGuid])[dependency] = null;
                }

                // set-up project configuration
                Regex           reProjectBuildConfig = new Regex(@"^\s+" + guid + @"\.(?<solutionConfiguration>[^|]+)\|?(?<solutionPlatform>[^\.]?)\.Build\.0\s*=\s* (?<projectConfiguration>[^|]+)\|(?<projectPlatform>[\.\w ]+)\s*", RegexOptions.Multiline);
                MatchCollection projectBuildMatches  = reProjectBuildConfig.Matches(solutionContent);

                ProjectEntry projectEntry = ProjectEntries [guid];
                if (projectEntry == null)
                {
                    // TODO: determine if we should report an error if a build
                    // configuration is defined for a project that does not
                    // exist in the solution
                    continue;
                }

                // holds mapping between project configuration(s) and solution(s)
                ConfigurationMap buildConfigurations = new ConfigurationMap(
                    projectBuildMatches.Count);

                for (int i = 0; i < projectBuildMatches.Count; i++)
                {
                    Match         projectBuildMatch  = projectBuildMatches [i];
                    string        solutionConfigName = projectBuildMatch.Groups["solutionConfiguration"].Value;
                    string        solutionPlatform   = projectBuildMatch.Groups["solutionPlatform"].Value;
                    string        projectConfigName  = projectBuildMatch.Groups["projectConfiguration"].Value;
                    string        projectPlatform    = projectBuildMatch.Groups["projectPlatform"].Value;
                    Configuration solutionConfig     = new Configuration(
                        solutionConfigName, solutionPlatform);
                    Configuration projectConfig = new Configuration(
                        projectConfigName, projectPlatform);
                    buildConfigurations [solutionConfig] = projectConfig;
                }

                // add map to corresponding project entry
                projectEntry.BuildConfigurations = buildConfigurations;
            }

            LoadProjectGuids(new ArrayList(solutionTask.Projects.FileNames), false);
            LoadProjectGuids(new ArrayList(solutionTask.ReferenceProjects.FileNames), true);
            LoadProjects(gacCache, refResolver, explicitProjectDependencies);
        }
Exemple #15
0
 public static ProjectFactory Create(SolutionTask solutionTask)
 {
     return(new ProjectFactory(solutionTask));
 }
Exemple #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProjectFactory" />
 /// class.
 /// </summary>
 private ProjectFactory(SolutionTask solutionTask)
 {
     _cachedProjects     = CollectionsUtil.CreateCaseInsensitiveHashtable();
     _cachedProjectGuids = CollectionsUtil.CreateCaseInsensitiveHashtable();
     _cachedProjectXml   = CollectionsUtil.CreateCaseInsensitiveHashtable();
 }
Exemple #17
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);
            }
        }
Exemple #18
0
        public Solution(string solutionContent, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver) : base(solutionTask, tfc, gacCache, refResolver)
        {
            Regex           reProjects     = new Regex(@"Project\(\""(?<package>\{.*?\})\"".*?\""(?<name>.*?)\"".*?\""(?<project>.*?)\"".*?\""(?<guid>.*?)\""(?<all>[\s\S]*?)EndProject", RegexOptions.Multiline);
            MatchCollection projectMatches = reProjects.Matches(solutionContent);

            Hashtable explicitProjectDependencies = CollectionsUtil.CreateCaseInsensitiveHashtable();

            foreach (Match projectMatch in projectMatches)
            {
                string project = projectMatch.Groups["project"].Value;
                string guid    = projectMatch.Groups["guid"].Value;

                // translate partial project path or URL to absolute path
                string fullProjectPath = TranslateProjectPath(solutionTask.SolutionFile.DirectoryName,
                                                              project);

                // check if project file actually exists
                if (!System.IO.File.Exists(fullProjectPath))
                {
                    throw CreateProjectDoesNotExistException(fullProjectPath);
                }

                if (ManagedProjectBase.IsEnterpriseTemplateProject(fullProjectPath))
                {
                    RecursiveLoadTemplateProject(fullProjectPath);
                }
                else
                {
                    // add project path to collection
                    ProjectEntries.Add(new ProjectEntry(guid, fullProjectPath));
                }

                // set-up project dependencies
                Regex           reDependencies    = new Regex(@"^\s+" + guid + @"\.[0-9]+ = (?<dep>\{\S*\}?)\s*$", RegexOptions.Multiline);
                MatchCollection dependencyMatches = reDependencies.Matches(solutionContent);

                foreach (Match dependencyMatch in dependencyMatches)
                {
                    string dependency = dependencyMatch.Groups["dep"].Value;

                    if (!explicitProjectDependencies.ContainsKey(guid))
                    {
                        explicitProjectDependencies[guid] = CollectionsUtil.CreateCaseInsensitiveHashtable();
                    }
                    ((Hashtable)explicitProjectDependencies[guid])[dependency] = null;
                }

                // set-up project configuration
                Regex           reProjectBuildConfig = new Regex(@"^\s+" + guid + @"\.(?<solutionConfiguration>[^|]+)\.Build\.0\s*=\s*(?<projectConfiguration>[^|]+)\|\s*\S*", RegexOptions.Multiline);
                MatchCollection projectBuildMatches  = reProjectBuildConfig.Matches(solutionContent);

                // initialize hashtable that will hold the project build configurations
                Hashtable projectBuildConfiguration = CollectionsUtil.CreateCaseInsensitiveHashtable();

                if (projectBuildMatches.Count > 0)
                {
                    foreach (Match projectBuildMatch in projectBuildMatches)
                    {
                        string solutionConfiguration = projectBuildMatch.Groups["solutionConfiguration"].Value;
                        string projectConfiguration  = projectBuildMatch.Groups["projectConfiguration"].Value;
                        projectBuildConfiguration[solutionConfiguration] = projectConfiguration;
                    }
                }

                // add project build configuration, this signals that project was
                // loaded in context of solution file
                ProjectBuildConfigurations[guid] = projectBuildConfiguration;
            }

            LoadProjectGuids(new ArrayList(solutionTask.Projects.FileNames), false);
            LoadProjectGuids(new ArrayList(solutionTask.ReferenceProjects.FileNames), true);
            LoadProjects(gacCache, refResolver, explicitProjectDependencies);
        }
Exemple #19
0
        public WhidbeySolution(string solutionContent, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver)
            : base(solutionTask, tfc, gacCache, refResolver)
        {
            Regex           reProjects     = new Regex(@"Project\(\""(?<package>\{.*?\})\"".*?\""(?<name>.*?)\"".*?\""(?<project>.*?)\"".*?\""(?<guid>.*?)\""(?<all>[\s\S]*?)EndProject", RegexOptions.Multiline);
            MatchCollection projectMatches = reProjects.Matches(solutionContent);

            Hashtable explicitProjectDependencies = CollectionsUtil.CreateCaseInsensitiveHashtable();

            foreach (Match projectMatch in projectMatches)
            {
                string project = projectMatch.Groups["project"].Value;
                string guid    = projectMatch.Groups["guid"].Value;
                string package = projectMatch.Groups["package"].Value;

                // bug #1732361: skip solution folders
                if (package == SolutionFolder_GUID)
                {
                    continue;
                }

                // translate partial project path or URL to absolute path
                string fullProjectPath = TranslateProjectPath(solutionTask.SolutionFile.DirectoryName,
                                                              project);

                if (ManagedProjectBase.IsEnterpriseTemplateProject(fullProjectPath))
                {
                    RecursiveLoadTemplateProject(fullProjectPath);
                }
                else
                {
                    // add project entry to collection
                    ProjectEntries.Add(new ProjectEntry(guid, fullProjectPath));
                }

                // set-up project dependencies
                Regex           reDependencies    = new Regex(@"^\s+(?<guid>\{[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}\})\s+=\s+(?<dep>\{[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}\})", RegexOptions.Multiline);
                MatchCollection dependencyMatches = reDependencies.Matches(projectMatch.Value);

                foreach (Match dependencyMatch in dependencyMatches)
                {
                    string dependency = dependencyMatch.Groups["dep"].Value;

                    if (!explicitProjectDependencies.ContainsKey(guid))
                    {
                        explicitProjectDependencies[guid] = CollectionsUtil.CreateCaseInsensitiveHashtable();
                    }
                    ((Hashtable)explicitProjectDependencies[guid])[dependency] = null;
                }

                // set-up project configuration
                Regex           reProjectBuildConfig = new Regex(@"^\s+" + Regex.Escape(guid) + @"\.(?<solutionConfiguration>[^|]+)\|(?<solutionPlatform>[^.]+)\.Build\.0\s*=\s*(?<projectConfiguration>[^|]+)\|(?<projectPlatform>[\.\w ]+)\s*", RegexOptions.Multiline);
                MatchCollection projectBuildMatches  = reProjectBuildConfig.Matches(solutionContent);

                ProjectEntry projectEntry = ProjectEntries [guid];
                if (projectEntry == null)
                {
                    // TODO: determine if we should report an error if a build
                    // configuration is defined for a project that does not
                    // exist in the solution
                    continue;
                }

                // holds mapping between project configuration(s) and solution(s)
                ConfigurationMap buildConfigurations = new ConfigurationMap(
                    projectBuildMatches.Count);

                for (int i = 0; i < projectBuildMatches.Count; i++)
                {
                    Match         projectBuildMatch  = projectBuildMatches [i];
                    string        solutionConfigName = projectBuildMatch.Groups["solutionConfiguration"].Value;
                    string        solutionPlatform   = projectBuildMatch.Groups["solutionPlatform"].Value;
                    string        projectConfigName  = projectBuildMatch.Groups["projectConfiguration"].Value;
                    string        projectPlatform    = projectBuildMatch.Groups["projectPlatform"].Value;
                    Configuration solutionConfig     = new Configuration(
                        solutionConfigName, solutionPlatform);
                    Configuration projectConfig = new Configuration(
                        projectConfigName, projectPlatform);
                    buildConfigurations [solutionConfig] = projectConfig;
                }

                // add map to corresponding project entry
                projectEntry.BuildConfigurations = buildConfigurations;
            }

            LoadProjectGuids(new ArrayList(solutionTask.Projects.FileNames), false);
            LoadProjectGuids(new ArrayList(solutionTask.ReferenceProjects.FileNames), true);
            LoadProjects(gacCache, refResolver, explicitProjectDependencies);
        }
Exemple #20
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));
                }
            }
        }
Exemple #21
0
 public RosarioSolution(string solutionContent, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver)
     : base(solutionContent, solutionTask, tfc, gacCache, refResolver)
 {
 }
Exemple #22
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)
 {
 }
        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);
            }
        }
Exemple #24
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));
 }
        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);
        }
Exemple #26
0
        public ConfigurationSettings(ManagedProjectBase project, XmlElement elemConfig, DirectoryInfo outputDir) : base(project)
        {
            _settings = new ArrayList();
            if (outputDir == null)
            {
                _relativeOutputDir = elemConfig.Attributes["OutputPath"].Value;
                if (!_relativeOutputDir.EndsWith(Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture)))
                {
                    _relativeOutputDir = _relativeOutputDir + Path.DirectorySeparatorChar;
                }
                _outputDir = new DirectoryInfo(FileUtils.CombinePaths(
                                                   project.ProjectDirectory.FullName,
                                                   _relativeOutputDir));
            }
            else
            {
                _relativeOutputDir = outputDir.FullName;
                if (!_relativeOutputDir.EndsWith(Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture)))
                {
                    _relativeOutputDir = _relativeOutputDir + Path.DirectorySeparatorChar;
                }
                _outputDir = outputDir;
            }

            _name = elemConfig.GetAttribute("Name");

            string documentationFile = elemConfig.GetAttribute("DocumentationFile");

            if (!StringUtils.IsNullOrEmpty(documentationFile))
            {
                // to match VS.NET, the XML Documentation file will be output
                // in the project directory, and only later copied to the output
                // directory
                string xmlDocBuildFile = FileUtils.CombinePaths(project.ProjectDirectory.FullName,
                                                                documentationFile);

                // add compiler option to build XML Documentation file
                _settings.Add(@"/doc:""" + xmlDocBuildFile + @"""");

                // 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);
            }

            // determine whether we need to register project output for use with
            // COM components
            _registerForComInterop = string.Compare(elemConfig.GetAttribute("RegisterForComInterop"),
                                                    "true", true, CultureInfo.InvariantCulture) == 0;

            SolutionTask.Log(Level.Debug, "Project: {0} Relative Output Path: {1} Output Path: {2} Documentation Path: {3}",
                             Project.Name, _relativeOutputDir, _outputDir.FullName, documentationFile);

            Hashtable htStringSettings  = new Hashtable();
            Hashtable htBooleanSettings = new Hashtable();

            htStringSettings["BaseAddress"] = "/baseaddress:{0}";

            // is only supported by csc (all versions) and vbc (2.0 or higher)
            htStringSettings["FileAlignment"] = "/filealign:{0}";

            htStringSettings["DefineConstants"] = "/define:{0}";

            switch (project.Type)
            {
            case ProjectType.CSharp:
                htStringSettings["WarningLevel"]               = "/warn:{0}";
                htStringSettings["NoWarn"]                     = "/nowarn:{0}";
                htBooleanSettings["IncrementalBuild"]          = "/incremental";
                htBooleanSettings["AllowUnsafeBlocks"]         = "/unsafe";
                htBooleanSettings["CheckForOverflowUnderflow"] = "/checked";
                break;

            case ProjectType.JSharp:
                htStringSettings["WarningLevel"]      = "/warn:{0}";
                htStringSettings["NoWarn"]            = "/nowarn:{0}";
                htBooleanSettings["IncrementalBuild"] = "/incremental";
                break;

            case ProjectType.VB:
                htStringSettings["DefineDebug"]          = "/d:DEBUG={0}";
                htStringSettings["DefineTrace"]          = "/d:TRACE={0}";
                htBooleanSettings["RemoveIntegerChecks"] = "/removeintchecks";
                break;
            }

            htBooleanSettings["DebugSymbols"]          = "/debug";
            htBooleanSettings["TreatWarningsAsErrors"] = "/warnaserror";
            htBooleanSettings["Optimize"] = "/optimize";

            foreach (DictionaryEntry de in htStringSettings)
            {
                string value = elemConfig.GetAttribute(de.Key.ToString());
                if (!StringUtils.IsNullOrEmpty(value))
                {
                    switch (de.Key.ToString())
                    {
                    case "BaseAddress":
                        // vbc and vjs expect the base address to be specified
                        // as a hexadecimal number, csc supports decimal,
                        // hexadecimal, or octal number
                        //
                        // so use hexadecimal as all compiler support this
                        uint intvalue = Convert.ToUInt32(value, CultureInfo.InvariantCulture);
                        value = "0x" + intvalue.ToString("x", CultureInfo.InvariantCulture);
                        break;

                    case "DefineConstants":
                        // vbc fails when the symbol contains spaces
                        value = value.Replace(" ", string.Empty);
                        break;
                    }
                    _settings.Add(string.Format(CultureInfo.InvariantCulture, de.Value.ToString(), value));
                }
            }

            foreach (DictionaryEntry de in htBooleanSettings)
            {
                string value = elemConfig.GetAttribute(de.Key.ToString());
                if (string.Compare(value, "true", true, CultureInfo.InvariantCulture) == 0)
                {
                    _settings.Add(de.Value.ToString() + "+");
                }
                else if (string.Compare(value, "false", true, CultureInfo.InvariantCulture) == 0)
                {
                    _settings.Add(de.Value.ToString() + "-");
                }
            }

            _settings.Add(string.Format(CultureInfo.InvariantCulture, "/out:\"{0}\"", BuildPath));
        }