예제 #1
0
        void InitializeProperties(ProjectRootElement xml, ProjectInstance parent)
        {
                        #if NET_4_5
            location = xml.Location;
                        #endif
            full_path      = xml.FullPath;
            directory      = string.IsNullOrWhiteSpace(xml.DirectoryPath) ? System.IO.Directory.GetCurrentDirectory() : xml.DirectoryPath;
            DefaultTargets = GetDefaultTargets(xml);
            InitialTargets = xml.InitialTargets.Split(item_target_sep, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToList();

            raw_imports      = new List <ResolvedImport> ();
            item_definitions = new Dictionary <string, ProjectItemDefinitionInstance> ();
            targets          = new Dictionary <string, ProjectTargetInstance> ();
            raw_items        = new List <ProjectItemInstance> ();

            // FIXME: this is likely hack. Test ImportedProject.Properties to see what exactly should happen.
            if (parent != null)
            {
                properties = parent.properties;
            }
            else
            {
                properties = new List <ProjectPropertyInstance> ();

                foreach (DictionaryEntry p in Environment.GetEnvironmentVariables())
                {
                    // FIXME: this is kind of workaround for unavoidable issue that PLATFORM=* is actually given
                    // on some platforms and that prevents setting default "PLATFORM=AnyCPU" property.
                    if (!string.Equals("PLATFORM", (string)p.Key, StringComparison.OrdinalIgnoreCase))
                    {
                        this.properties.Add(new ProjectPropertyInstance((string)p.Key, false, (string)p.Value));
                    }
                }
                foreach (var p in global_properties)
                {
                    this.properties.Add(new ProjectPropertyInstance(p.Key, false, p.Value));
                }
                var tools = projects.GetToolset(tools_version) ?? projects.GetToolset(projects.DefaultToolsVersion);
                foreach (var p in projects.GetReservedProperties(tools, this, xml))
                {
                    this.properties.Add(p);
                }
                foreach (var p in ProjectCollection.GetWellKnownProperties(this))
                {
                    this.properties.Add(p);
                }
            }

            ProcessXml(parent, xml);
        }
예제 #2
0
        string [] GetDefaultTargets(ProjectRootElement xml, bool fromAttribute, bool checkImports)
        {
            if (fromAttribute)
            {
                var ret = xml.DefaultTargets.Split(item_target_sep, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray();
                if (checkImports && ret.Length == 0)
                {
                    foreach (var imp in this.raw_imports)
                    {
                        ret = GetDefaultTargets(imp.ImportedProject, true, false);
                        if (ret.Any())
                        {
                            break;
                        }
                    }
                }
                return(ret);
            }
            else
            {
                if (xml.Targets.Any())
                {
                    return new String [] { xml.Targets.First().Name }
                }
                ;
                if (checkImports)
                {
                    foreach (var imp in this.raw_imports)
                    {
                        var ret = GetDefaultTargets(imp.ImportedProject, false, false);
                        if (ret.Any())
                        {
                            return(ret);
                        }
                    }
                }
                return(new string [0]);
            }
        }

        void InitializeProperties(ProjectRootElement xml)
        {
            location       = xml.Location;
            full_path      = xml.FullPath;
            directory      = string.IsNullOrWhiteSpace(xml.DirectoryPath) ? System.IO.Directory.GetCurrentDirectory() : xml.DirectoryPath;
            InitialTargets = xml.InitialTargets.Split(item_target_sep, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToList();

            raw_imports      = new List <ResolvedImport> ();
            item_definitions = new Dictionary <string, ProjectItemDefinitionInstance> ();
            targets          = new Dictionary <string, ProjectTargetInstance> ();
            raw_items        = new List <ProjectItemInstance> ();

            properties = new Dictionary <string, ProjectPropertyInstance> ();

            foreach (DictionaryEntry p in Environment.GetEnvironmentVariables())
            {
                // FIXME: this is kind of workaround for unavoidable issue that PLATFORM=* is actually given
                // on some platforms and that prevents setting default "PLATFORM=AnyCPU" property.
                if (!string.Equals("PLATFORM", (string)p.Key, StringComparison.OrdinalIgnoreCase))
                {
                    this.properties [(string)p.Key] = new ProjectPropertyInstance((string)p.Key, true, (string)p.Value);
                }
            }
            foreach (var p in global_properties)
            {
                this.properties [p.Key] = new ProjectPropertyInstance(p.Key, false, p.Value);
            }
            var tools = projects.GetToolset(tools_version) ?? projects.GetToolset(projects.DefaultToolsVersion);

            foreach (var p in projects.GetReservedProperties(tools, this, xml))
            {
                this.properties [p.Name] = p;
            }
            foreach (var p in ProjectCollection.GetWellKnownProperties(this))
            {
                this.properties [p.Name] = p;
            }

            ProcessXml(xml);

            DefaultTargets = GetDefaultTargets(xml).ToList();
        }