public void TestSerializationEvent()
        {
            Event x1 = CreateObject <Event>().WithName("Eve").WithDimension(DimensionLength);

            x1.Formula         = CreateObject <ConstantFormula>().WithDimension(DimensionLength).WithValue(1.0);
            x1.ParentContainer = C0;

            EventAssignment ea1 = CreateObject <EventAssignment>().WithName("Eva").WithDimension(DimensionLength);

            ea1.UseAsValue = true;
            ea1.Formula    = CreateObject <ConstantFormula>().WithDimension(DimensionLength).WithValue(23.4);
            ea1.ObjectPath = ObjectPathFactory.CreateAbsoluteObjectPath(P);
            x1.AddAssignment(ea1);
            ea1.ResolveChangedEntity();

            IEvent x2 = SerializeAndDeserialize(x1);

            x2.ParentContainer = C0;

            var refResolver = new ReferencesResolver();

            refResolver.ResolveReferencesIn(x2);

            AssertForSpecs.AreEqualEvent(x2, x1);
        }
Ejemplo n.º 2
0
        public MSBuildProjectReference(
            ReferencesResolver referencesResolver, ProjectBase parent,
            ProjectBase project, bool isPrivateSpecified, bool isPrivate)

            : base(referencesResolver, parent)
        {
            _helper  = new MSBuildReferenceHelper(isPrivateSpecified, isPrivate);
            _project = project;
        }
Ejemplo n.º 3
0
        public void TestComplexModelContainer()
        {
            Model x1 = _model as Model;

            Assert.IsNotNull(x1);

            Model x2          = SerializeAndDeserialize(x1);
            var   refResolver = new ReferencesResolver();

            refResolver.ResolveReferencesIn(x2);
            AssertForSpecs.AreEqualModel(x1, x2);
        }
Ejemplo n.º 4
0
        public MSBuildProjectReference(
            ReferencesResolver referencesResolver, ProjectBase parent,
            SolutionBase solution, TempFileCollection tfc,
            GacCache gacCache, DirectoryInfo outputDir,
            string pguid, string pname, string rpath, string priv)

            : base(referencesResolver, parent)
        {
            _helper = new MSBuildReferenceHelper(priv, true);
            string projectFile = solution.GetProjectFileFromGuid(pguid);

            _project = LoadProject(solution, tfc, gacCache, outputDir, projectFile);
        }
Ejemplo n.º 5
0
        public void TestComplexSimulation()
        {
            //CONTEXT
            ModelCoreSimulation x1 = _simulation as ModelCoreSimulation;

            Assert.IsNotNull(x1);

            //ACT
            IModelCoreSimulation x2 = SerializeAndDeserialize(x1);
            var refResolver         = new ReferencesResolver();

            refResolver.ResolveReferencesIn(x2.Model);
            //ASSERT
            AssertForSpecs.AreEqualSimulation(x2, x1);
        }
 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();
 }
Ejemplo n.º 7
0
        public MSBuildProject(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir)
            : base(xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir)
        {
            string cfgname  = solutionTask.Configuration;
            string platform = solutionTask.Platform;

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

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

            ProjectEntry projectEntry = solution.ProjectEntries [_guid];

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

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

                ReferenceBase reference = new MSBuildAssemblyReference(
                    xmlDefinition, ReferencesResolver, this, gacCache,
                    rpath, priv, hintpath);
                _references.Add(reference);
            }
            refs = _msproj.GetEvaluatedItemsByName("ProjectReference");
            foreach (Microsoft.Build.BuildEngine.BuildItem r in refs)
            {
                string        pguid     = r.GetMetadata("Project");
                string        pname     = r.GetMetadata("Name");
                string        rpath     = r.FinalItemSpec;
                string        priv      = r.GetMetadata("Private");
                ReferenceBase reference = new MSBuildProjectReference(
                    ReferencesResolver, this, solution, tfc, gacCache, outputDir,
                    pguid, pname, rpath, priv);
                _references.Add(reference);
            }
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
 public SolutionBase GetInstance(string solutionContent, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver)
 {
     return(new Solution(solutionContent, solutionTask, tfc, gacCache, refResolver));
 }
Ejemplo n.º 10
0
 public SolutionBase GetInstance(string solutionContent, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver)
 {
     return new Solution(solutionContent, solutionTask, tfc, gacCache, refResolver);
 }
Ejemplo n.º 11
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>[^|]+)\|?(?<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);
        }
Ejemplo n.º 12
0
 public ProjectBase GetInstance(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir)
 {
     return(new MSBuildProject(solution, projectPath, xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir));
 }
Ejemplo n.º 13
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);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Executes the task.
        /// </summary>
        /// <exception cref="BuildException">
        /// Project build failed.
        /// </exception>
        protected override void ExecuteTask()
        {
            Log(Level.Info, "Starting solution build.");

            if (SolutionFile != null)
            {
                if (!SolutionFile.Exists)
                {
                    throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                           "Couldn't find solution file '{0}'.", SolutionFile.FullName),
                                             Location);
                }
            }

            if (Projects.FileNames.Count > 0)
            {
                Log(Level.Verbose, "Included projects:");
                foreach (string projectFile in Projects.FileNames)
                {
                    Log(Level.Verbose, " - {0}", projectFile);
                }
            }

            if (ReferenceProjects.FileNames.Count > 0)
            {
                Log(Level.Verbose, "Reference projects:");
                foreach (string projectFile in ReferenceProjects.FileNames)
                {
                    Log(Level.Verbose, " - {0}", projectFile);
                }
            }

            string basePath = null;

            try {
                using (TempFileCollection tfc = new TempFileCollection()) {
                    // store the temp dir so we can clean it up later
                    basePath = tfc.BasePath;

                    // ensure temp directory exists
                    if (!Directory.Exists(tfc.BasePath))
                    {
                        Directory.CreateDirectory(tfc.BasePath);
                    }

                    // create temporary domain
                    PermissionSet tempDomainPermSet = new PermissionSet(PermissionState.Unrestricted);

                    AppDomain temporaryDomain = AppDomain.CreateDomain("temporaryDomain", AppDomain.CurrentDomain.Evidence,
                                                                       AppDomain.CurrentDomain.SetupInformation, tempDomainPermSet);

                    try {
                        ReferencesResolver referencesResolver =
                            ((ReferencesResolver)temporaryDomain.CreateInstanceFrom(Assembly.GetExecutingAssembly().Location,
                                                                                    typeof(ReferencesResolver).FullName).Unwrap());

                        using (GacCache gacCache = new GacCache(this.Project)) {
                            SolutionBase sln = SolutionFactory.LoadSolution(this,
                                                                            tfc, gacCache, referencesResolver);
                            if (!sln.Compile(_configuration))
                            {
                                throw new BuildException("Project build failed.", Location);
                            }
                        }
                    } finally {
                        // unload temporary domain
                        AppDomain.Unload(temporaryDomain);
                    }
                }
            } finally {
                if (basePath != null && Directory.Exists(basePath))
                {
                    Log(Level.Debug, "Cleaning up temp folder '{0}'.", basePath);

                    // delete temporary directory and all files in it
                    DeleteTask deleteTask = new DeleteTask();
                    deleteTask.Project = Project;
                    deleteTask.Parent  = this;
                    deleteTask.InitializeTaskConfiguration();
                    deleteTask.Directory = new DirectoryInfo(basePath);
                    deleteTask.Threshold = Level.None; // no output in build log
                    deleteTask.Execute();
                }
            }
        }
Ejemplo n.º 16
0
 protected override void Context()
 {
     sut = new ReferencesResolver();
 }