internal MFSolution LoadSolutionProj(string solutionProjFile, string path)
        {
            MFSolution sol = new MFSolution();
            Project proj;
            string fullpath = ExpandEnvVars(solutionProjFile, path);

            string codebase = "";
            string codebasetype = "";
            string processor = "";

            try
            {
                proj = LoadProject(fullpath);

                path = Path.GetDirectoryName(fullpath);

                // load solution libraries

                LoadLibraries(Path.Combine(path, "DeviceCode"));

                Dictionary<string, string> tbl = new Dictionary<string, string>();
                tbl["PLATFORM"] = "Name";
                tbl["PlatformGuid"] = "Guid";

                LoadStringProps(proj, sol, tbl);

                foreach (ProjectItemGroupElement big in proj.Xml.ItemGroups)
                {
                    foreach (ProjectItemElement bi in big.Items)
                    {
                        MFBuildFile bf = new MFBuildFile();
                        bf.File = bi.Include;
                        bf.ItemName = bi.ItemType;
                        bf.Condition = bi.Condition;

                        sol.Items.Add(bf);
                    }
                }

                foreach (ResolvedImport imp in proj.Imports)
                {
                    if (imp.ImportedProject.FullPath.ToLower().Contains("\\devicecode\\targets\\"))
                    {
                        Processor proc = LoadProcessorProj(imp.ImportedProject.FullPath, "");

                        if (proc != null)
                        {
                            sol.Processor = new MFComponent(MFComponentType.Processor, proc.Name, proc.Guid, proc.ProjectPath);
                        }
                    }
                }

                if (sol.Processor == null || string.IsNullOrEmpty(sol.Processor.Name))
                {
                    foreach (ProjectProperty prop in proj.Properties)
                    {
                        if (prop.IsImported)
                        {
                            if (prop.Name == "TARGETPROCESSOR")
                            {
                                Processor proc = m_helper.FindProcessorByName(prop.EvaluatedValue);
                                if (proc != null)
                                {
                                    sol.Processor = new MFComponent(MFComponentType.Processor, proc.Name, proc.Guid);
                                }
                                else
                                {
                                    foreach (ProjectImportElement imp in proj.Xml.Imports)
                                    {
                                        if (imp.Project.ToUpper().Contains("\\DEVICECODE\\TARGETS\\"))
                                        {
                                            proc = LoadProcessorProj(imp.Project, "");
                                            break;
                                        }
                                    }
                                }

                                if (proc == null)
                                {
                                    sol.Processor = new MFComponent(MFComponentType.Processor, prop.EvaluatedValue);
                                    sol.Processor.Guid = "";
                                }
                                else
                                {
                                    sol.Processor = new MFComponent(MFComponentType.Processor, proc.Name, proc.Guid, proc.ProjectPath);
                                }
                            }
                        }
                    }
                }

                foreach (ProjectPropertyGroupElement pg in proj.Xml.PropertyGroups)
                {
                    foreach (ProjectPropertyElement bp in pg.Properties)
                    {
                        string cond = CombineConditionals(pg.Condition, bp.Condition);

                        switch (bp.Name)
                        {
                            case "Description":
                                sol.Description = bp.Value;
                                break;
                            case "Documentation":
                                sol.Documentation = bp.Value;
                                break;
                            case "INSTRUCTION_SET":
                                ISA isa = m_helper.FindISAByName(bp.Value);
                                if (isa == null)
                                {
                                    sol.DefaultISA = new MFComponent(MFComponentType.ISA, bp.Value);
                                }
                                else
                                {
                                    sol.DefaultISA = new MFComponent(MFComponentType.ISA, isa.Name, isa.Guid);
                                }
                                break;
                            case "PLATFORM":
                            case "TARGETPLATFORM":
                                sol.Name = bp.Value;
                                break;
                            case "PlatformGuid":
                                sol.Guid = bp.Value;
                                break;
                            case "TARGETPROCESSOR":
                                Processor proc = m_helper.FindProcessorByName(bp.Value);
                                if (proc != null)
                                {
                                    sol.Processor = new MFComponent(MFComponentType.Processor, proc.Name, proc.Guid);
                                }
                                else
                                {
                                    processor = bp.Value;
                                }
                                break;
                            //obsolete props (moved to processor settings)
                            case "PLATFORM_FAMILY":
                            case "ARM_TYPE":
                            case "MDK_DEVICE_TYPE":
                            case "CPUName":
                                break;
                            case "TARGETCODEBASE":
                                codebase = bp.Value;
                                break;
                            case "TARGETCODEBASETYPE":
                                codebasetype = bp.Value;
                                break;
                            default:
                                MFProperty prop = new MFProperty();
                                prop.Name = bp.Name;
                                prop.Value = bp.Value;
                                prop.Condition = cond;
                                sol.Properties.Add(prop);
                                break;
                        }
                    }
                }

                // for legacy settings files
                if (sol.Processor == null)
                {
                    string procFile = Path.Combine(Environment.GetEnvironmentVariable("SPOCLIENT"), "DeviceCode\\Targets\\" + codebasetype + "\\" + codebase + "\\" + processor + ".settings");

                    if (File.Exists(procFile))
                    {
                        Processor proc = LoadProcessorProj(procFile, "");

                        sol.Processor = new MFComponent(MFComponentType.Processor, proc.Name, proc.Guid);
                    }
                    else // delay load
                    {
                        sol.Processor = new MFComponent(MFComponentType.Processor, processor);
                        sol.Processor.Guid = "";
                    }
                }

                if (string.IsNullOrEmpty(sol.Name)) sol.Name = Path.GetFileNameWithoutExtension(solutionProjFile);
                if (string.IsNullOrEmpty(sol.Guid)) sol.Guid = System.Guid.NewGuid().ToString("B");

                sol.ProjectPath = ConvertPathToEnv(solutionProjFile);

                foreach (string subdir in Directory.GetDirectories(Path.GetDirectoryName(fullpath)))
                {
                    if (subdir.TrimEnd().ToUpper().EndsWith("DEVICECODE")) continue;

                    foreach (string projFile in Directory.GetFiles(subdir, "*.proj"))
                    {
                        MFProject mfproj = LoadProjectProj(projFile, Path.GetDirectoryName(projFile));

                        if (mfproj != null) sol.Projects.Add(mfproj);
                    }
                }

                // load platform selector file for memory data
                string platSelectorFile = Path.Combine(path, "platform_selector.h");
                if (File.Exists(platSelectorFile))
                {
                    string data = "";

                    using (TextReader tr = File.OpenText(platSelectorFile))
                    {
                        data = tr.ReadToEnd();
                    }


                    sol.SystemClockSpeed = ParseHexInt(data, "SYSTEM_CLOCK_HZ");
                    sol.SlowClockSpeed = ParseHexInt(data, "SLOW_CLOCKS_PER_SECOND");

                    Regex rx = null;
                    Match m = null;

                    if (sol.SlowClockSpeed == -1)
                    {
                        rx = new Regex("\\sSLOW_CLOCKS_PER_SECOND\\s+SYSTEM_CLOCK_HZ");
                        if (rx.IsMatch(data))
                        {
                            sol.SlowClockSpeed = sol.SystemClockSpeed;
                        }
                    }

                    sol.RamBase = ParseHexInt(data, "SRAM1_MEMORY_Base");
                    sol.RamLength = ParseHexInt(data, "SRAM1_MEMORY_Size");
                    sol.FlashBase = ParseHexInt(data, "FLASH_MEMORY_Base");
                    sol.FlashLength = ParseHexInt(data, "FLASH_MEMORY_Size");

                    rx = new Regex("#define\\s+DEBUGGER_PORT\\s+([\\w\\d_]+)", RegexOptions.IgnoreCase);
                    m = rx.Match(data);
                    if (m.Success)
                    {
                        sol.DebuggerPort = m.Groups[1].Value;
                    }
                    else
                    {
                        sol.DebuggerPort = "COM1";
                    }

                    rx = new Regex("\\sRUNTIME_MEMORY_PROFILE__([\\w]+)");
                    m = rx.Match(data);
                    if (m.Success)
                    {
                        sol.MemoryProfile = m.Groups[1].Value;
                    }
                    else
                    {
                        sol.MemoryProfile = "medium";
                    }
                }

                MFSolution dbSol = m_helper.FindSolutionByName(sol.Name);

                if (null == dbSol)
                {
                    m_helper.DefaultInventory.Solutions.Add(sol);
                }
                else
                {
                    sol = dbSol;
                }
            }
            catch(Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Error: Exception in load solution " + e.Message);
                sol = null;
            }

            return sol;
        }
        internal MFProject LoadProjectProj(string projFile, string path)
        {
            MFProject mfproj = new MFProject();
            Project proj;
            string fullpath = ExpandEnvVars(projFile, path);

            List<MFComponent> driverLibCheck = new List<MFComponent>();

            try
            {
                proj = LoadProject(fullpath);

                path = Path.GetDirectoryName(fullpath);

                mfproj.ProjectPath = ConvertPathToEnv(projFile);

                Dictionary<string, string> tbl = new Dictionary<string, string>();
                tbl["AssemblyName"] = "Name";
                tbl["MFSettingsFile"] = "SettingsFile";
                tbl["ProjectGuid"] = "Guid";

                LoadStringProps(proj, mfproj, tbl);

                foreach (ProjectPropertyGroupElement pg in proj.Xml.PropertyGroups)
                {
                    foreach (ProjectPropertyElement bp in pg.Properties)
                    {
                        string cond = CombineConditionals(pg.Condition, bp.Condition);

                        switch (bp.Name)
                        {
                            case "AssemblyName":
                            case "MFSettingsFile":
                            case "ProjectGuid":
                            case "Description":
                            case "Documentation":
                                // handled by loadstringprops
                                break;
                            case "IsClrProject":
                                mfproj.IsClrProject = Boolean.Parse(bp.Value);
                                break;
                            case "EXEScatterFileDefinition":
                                {
                                    MFBuildFile file = new MFBuildFile();

                                    file.Condition = cond;
                                    file.File = bp.Value;
                                    file.ItemName = bp.Name;

                                    mfproj.ScatterFile = file;
                                }
                                break;
                            default:
                                {
                                    MFProperty prop = new MFProperty();
                                    prop.Name = bp.Name;
                                    prop.Value = bp.Value;
                                    prop.Condition = cond;
                                    mfproj.Properties.Add(prop);
                                }
                                break;
                        }
                    }
                }

                LoadCompileItems(proj, mfproj, path);

                Dictionary<string, MFComponent> libLookup = new Dictionary<string, MFComponent>();
                foreach (ProjectItemGroupElement big in proj.Xml.ItemGroups)
                {
                    foreach (ProjectItemElement bi in big.Items)
                    {
                        string cond = CombineConditionals(big.Condition, bi.Condition);

                        switch (bi.ItemType)
                        {
                            case "RequiredProjects":
                                string ext = Path.GetExtension(bi.Include).ToUpper();
                                if (ext == ".FEATUREPROJ" || ext == ".LIBCATPROJ")
                                {
                                    System.Diagnostics.Debug.Assert(false, ".FeatureProj and .LibCatProj files can only be imported");
                                }
                                else if (ext == ".PROJ")
                                {
                                    Library lib = m_helper.FindLibraryByProject(ExpandEnvVars(bi.Include, path));
                                    MFComponent comp = null;

                                    if (lib == null)
                                    {
                                        lib = LoadLibraryProj(bi.Include, path);
                                    }

                                    if (lib != null)
                                    {
                                        if (libLookup.ContainsKey(lib.Guid.ToLower()))
                                        {
                                            comp = libLookup[lib.Guid.ToLower()];

                                            if (string.IsNullOrEmpty(comp.Conditional))
                                            {
                                                comp.Conditional = cond;
                                            }
                                            break;
                                        }

                                        comp = new MFComponent(MFComponentType.Library, lib.Name, lib.Guid, bi.Include);
                                        comp.Conditional = cond;
                                    }

                                    if (comp != null)
                                    {
                                        mfproj.Libraries.Add(comp);

                                        libLookup[comp.Guid.ToLower()] = comp;
                                    }
                                    else
                                    {
                                        // we should pick this up in the driverlibs/platformlibs
                                        /*
                                        string name = Path.GetFileName(Path.GetDirectoryName(bi.Include));
                                        comp = new MFComponent(MFComponentType.Library, name, System.Guid.NewGuid().ToString("B"), bi.Include);
                                        comp.Conditional = cond;

                                        mfproj.Libraries.Add(comp);

                                        libLookup[comp.Guid.ToLower()] = comp;

                                        Console.WriteLine("Error: Library not found " + bi.Include);
                                        */
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("Warning! Skipping dependency item " + bi.Include);
                                }
                                break;
                            case "InteropFeature":
                                mfproj.InteropFeatures.Add(bi.Include);
                                break;
                            case "PlatformIndependentLibs":
                                goto case "DriverLibs";
                            case "DriverLibs":
                                driverLibCheck.Add(new MFComponent(MFComponentType.Unknown, "", "", bi.Include, cond));
                                break;
                            case "MMP_DAT_CreateDatabase":
                                if (!mfproj.ExtraAssemblies.Contains(bi.Include))
                                {
                                    mfproj.ExtraAssemblies.Add(bi.Include);
                                }
                                break;
                            case "FastCompileCPPFile":
                            case "Compile":
                            case "HFiles":
                            case "IncludePaths":
                                // handled by LoadCompileItems
                                break;

                            // todo: do we want to get rid of subdirectories?
                            //case "SubDirectories":
                            //break;

                            default:
                                {
                                    MFBuildFile f = new MFBuildFile();
                                    f.Condition = cond;
                                    f.File = bi.Include;
                                    f.ItemName = bi.ItemType;
                                    mfproj.OtherFiles.Add(f);
                                }
                                break;
                        }
                    }
                }

                Hashtable featLookup = new Hashtable();

                foreach (ProjectImportElement imp in proj.Xml.Imports)
                {
                    string ext = Path.GetExtension(imp.Project).ToUpper();

                    if (ext == ".FEATUREPROJ")
                    {
                        Feature feat = LoadFeatureProj(imp.Project, path);
                        MFComponent comp = null;

                        if (feat == null)
                        {
                            feat = m_helper.FindFeatureByName(Path.GetFileNameWithoutExtension(imp.Project));
                        }

                        if (feat == null)
                        {
                            string name = Path.GetFileNameWithoutExtension(imp.Project);
                            comp = new MFComponent(MFComponentType.Feature, name, System.Guid.NewGuid().ToString("B"), imp.Project);
                            comp.Conditional = imp.Condition;

                            mfproj.Features.Add(comp);

                            featLookup.Add(comp.Guid.ToLower(), comp);

                            //Console.WriteLine("Error: Feature not found " + imp.Project);
                        }
                        else if(!featLookup.ContainsKey(feat.Guid.ToLower()))
                        {
                            comp = new MFComponent(MFComponentType.Feature, feat.Name, feat.Guid, imp.Project);
                            comp.Conditional = imp.Condition;

                            mfproj.Features.Add(comp);

                            featLookup.Add(feat.Guid.ToLower(), comp);
                        }
                    }
                    else if (ext == ".LIBCATPROJ")
                    {
                        LibraryCategory libcat = LoadLibraryCategoryProj(imp.Project, path);
                        MFComponent comp = null;

                        if (libcat == null)
                        {
                            libcat = m_helper.FindLibraryCategoryByName(Path.GetFileNameWithoutExtension(imp.Project));
                        }

                        if (libcat != null)
                        {
                            comp = new MFComponent(MFComponentType.LibraryCategory, libcat.Name, libcat.Guid, imp.Project);
                            comp.Conditional = imp.Condition;

                            mfproj.LibraryCategories.Add(comp);
                        }
                        else
                        {
                            string name = Path.GetFileNameWithoutExtension(imp.Project);
                            comp = new MFComponent(MFComponentType.LibraryCategory, name, System.Guid.NewGuid().ToString("B"), imp.Project);
                            comp.Conditional = imp.Condition;

                            mfproj.LibraryCategories.Add(comp);

                            Console.WriteLine("Error: LibraryCategory not found " + imp.Project);
                        }
                    }
                }


                ScatterfileWrapper sw = new ScatterfileWrapper(mfproj);
                string scatter = "";

                if (mfproj.ScatterFile != null && !string.IsNullOrEmpty(mfproj.ScatterFile.File))
                {
                    string tmp = ExpandEnvVars(mfproj.ScatterFile.File, "");
                    if (File.Exists(tmp))
                    {
                        scatter = tmp;
                    }
                }

                if (scatter == "")
                {
                    foreach (string scatterfile in Directory.GetFiles(Path.GetDirectoryName(projFile), "scatter*.xml"))
                    {
                        if (scatterfile.ToLower().Contains("ram_functions")) continue;
                        if (scatterfile.ToLower().Contains("_gcc.")) continue;

                        List<MemoryMap> maps = sw.LoadFromFile(scatterfile);

                        if(maps != null && maps.Count > 0)
                        {
                            mfproj.MemoryMap = maps[0];
                        }
                    }
                }
                else
                {
                    // todo add support for GCC?
                    if (!scatter.ToLower().Contains("_gcc"))
                    {
                        mfproj.MemoryMap = sw.LoadFromFile(scatter)[0];
                    }
                }

                foreach (ProjectTargetElement targ in proj.Xml.Targets)
                {
                    mfproj.Targets.Add(targ);
                }

                foreach(MFComponent comp in driverLibCheck)
                {
                    Library lib = m_helper.FindLibraryByFile(comp.ProjectPath);

                    if (lib == null)
                    {
                        lib = m_helper.FindLibraryByName(Path.GetFileNameWithoutExtension(comp.ProjectPath));
                    }

                    if (lib == null)
                    {
                        mfproj.Libraries.Add(comp);

                        libLookup[comp.Guid.ToLower()] = comp;

                        Console.WriteLine("Warning: Library not found " + comp.ProjectPath + ". Delay loading...");
                    }
                }

            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Error: loading project file: " + fullpath + "\r\n", e.Message);
                mfproj = null;
            }

            return mfproj;
        }
        internal void LoadTargetFile(BuildTool tool, string fileName)
        {
            Project proj;
            string fullpath = ExpandEnvVars(fileName, "");

            try
            {
                proj = LoadProject(fullpath);

                foreach (ProjectImportElement import in proj.Xml.Imports)
                {
                    if (string.IsNullOrEmpty(import.Condition))
                    {
                        LoadTargetFile(tool, ExpandVars(import.Project, Path.GetDirectoryName(fileName)));
                    }
                }

                Regex expISA = new Regex(@"'\$\(INSTRUCTION_SET\)'=='", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);

                foreach (ProjectPropertyGroupElement pg in proj.Xml.PropertyGroups)
                {
                    if (expISA.IsMatch(pg.Condition))
                    {
                        ISA isa = LoadISASettings(pg);
                        if (isa != null)
                        {
                            tool.SupportedISAs.Add(isa);
                        }
                        continue;
                    }

                    tool.BuildOptions = LoadToolChainOptions(pg);

                    foreach (ProjectPropertyElement bp in pg.Properties)
                    {
                        string cond = CombineConditionals(pg.Condition, bp.Condition);

                        switch (bp.Name)
                        {
                            case "BuildToolName":
                                tool.Name = bp.Value;
                                break;
                            case "Documentation":
                                tool.Documentation = bp.Value;
                                break;
                            case "BuildToolGuid":
                                tool.Guid = bp.Value;
                                break;
                            case ObjExtFlag:
                                tool.ObjExt = bp.Value;
                                break;
                            case LibExtFlag:
                                tool.LibExt = bp.Value;
                                break;
                            case ExeExtFlag:
                                tool.BinExt = bp.Value;
                                break;

                            case CCompilerTag:
                                tool.CCompiler.Exec = RemoveWrapper(bp.Value);
                                break;
                            case CppCompilerTag:
                                tool.CppCompiler.Exec = RemoveWrapper(bp.Value);
                                break;
                            case AsmCompilerTag:
                                tool.AsmCompiler.Exec = RemoveWrapper(bp.Value);
                                break;
                            case ArchiverTag:
                                tool.Archiver.Exec = RemoveWrapper(bp.Value);
                                break;
                            case LinkerTag:
                                tool.Linker.Exec = RemoveWrapper(bp.Value);
                                break;
                            case FromElfTag:
                                tool.FromELF.Exec = RemoveWrapper(bp.Value);
                                break;
                            case ToolWrapperTag:
                            case AdsWrapperTag:
                            case AdiWrapperTag:
                            case ArcWrapperTag:
                                tool.BuildToolWrapper = RemoveWrapper(bp.Value);
                                break;
                            case PKUI_CpuNamesTag:
                                {
                                    List<string> pts = (List<string>)this.DeserializeXml(bp.Value, typeof(List<string>));
                                    tool.SupportedCpuNames.AddRange(pts);
                                }
                                break;
                            case "ProcessorTypes":
                            case CpuNamesTag:
                                {
                                    foreach (string sType in bp.Value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                                    {
                                        tool.SupportedCpuNames.Add(sType);
                                    }
                                }
                                break;
                            case PKUI_ISAsTag:
                                {
                                    List<ISA> isas = (List<ISA>)this.DeserializeXml(bp.Value, typeof(List<ISA>));
                                    tool.SupportedISAs.AddRange(isas);
                                }
                                break;
                            case ISAsTag:
                                {
                                    //legacy
                                    if (bp.Value.Contains(";"))
                                    {
                                        foreach (string sISA in bp.Value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                                        {
                                            ISA isa = new ISA();
                                            isa.Name = sISA;
                                            isa.Guid = System.Guid.NewGuid().ToString("B");

                                            tool.SupportedISAs.Add(isa);
                                        }
                                    }
                                }
                                break;

                            default:
                                {
                                    MFProperty prop = new MFProperty();
                                    prop.Name = bp.Name;
                                    prop.Value = bp.Value;
                                    prop.Condition = cond;

                                    tool.Properties.Add(prop);
                                }
                                break;
                        }
                    }
                }

                foreach (ProjectItemGroupElement big in proj.Xml.ItemGroups)
                {
                    foreach (ProjectItemElement bi in big.Items)
                    {
                        string cond = CombineConditionals(big.Condition, bi.Condition);

                        MFProperty prop = new MFProperty();
                        prop.Name = bi.ItemType;
                        prop.Value = bi.Include;
                        prop.Condition = cond;

                        tool.Items.Add(prop);
                    }
                }

                foreach (ProjectTargetElement targ in proj.Xml.Targets)
                {
                    switch (targ.Name)
                    {
                        case AdiAsmTargetTag:
                        case ArmAsmTargetTag:
                        case ArcAsmTargetTag:
                        case AsmCompilerTargetTag:
                            tool.AsmCompiler.Conditional = targ.Condition;
                            tool.AsmCompiler.Description = AsmCompilerTag;
                            LoadTargetTasks(targ, tool.BuildOptions.EnvironmentVariables, tool.AsmCompiler, tool.BuildOptions.AsmFlags, tool.BuildOptions.CommonFlags);
                            break;
                        case AdiCCompilerTargetTag:
                        case ArmCCompilerTargetTag:
                        case ArcCCompilerTargetTag:
                        case CCompilerTargetTag:
                            tool.CCompiler.Conditional = targ.Condition;
                            tool.CCompiler.Description = CCompilerTag;
                            LoadTargetTasks(targ, tool.BuildOptions.EnvironmentVariables, tool.CCompiler, tool.BuildOptions.CFlags, tool.BuildOptions.C_CppFlags, tool.BuildOptions.CommonFlags);
                            break;
                        case AdiCppCompilerTargetTag:
                        case ArmCppCompilerTargetTag:
                        case ArcCppCompilerTargetTag:
                        case CppCompilerTargetTag:
                            tool.CppCompiler.Conditional = targ.Condition;
                            tool.CppCompiler.Description = CppCompilerTag;
                            LoadTargetTasks(targ, tool.BuildOptions.EnvironmentVariables, tool.CppCompiler, tool.BuildOptions.CppFlags, tool.BuildOptions.C_CppFlags, tool.BuildOptions.CommonFlags);
                            break;
                        case AdiLibTargetTag:
                        case ArmLibTargetTag:
                        case ArcLibTargetTag:
                        case LibTargetTag:
                            tool.Archiver.Conditional = targ.Condition;
                            tool.Archiver.Description = ArchiverTag;
                            LoadTargetTasks(targ, tool.BuildOptions.EnvironmentVariables, tool.Archiver, tool.BuildOptions.ArchiverFlags);
                            break;
                        case AdiExeTargetTag:
                        case ArmExeTargetTag:
                        case ArcExeTargetTag:
                        case ExeTargetTag:
                            tool.Linker.Conditional = targ.Condition;
                            tool.Linker.Description = LinkerTag;
                            LoadTargetTasks(targ, tool.BuildOptions.EnvironmentVariables, tool.Linker, tool.BuildOptions.LinkerFlags);
                            break;
                        default:
                            MiscBuildTool misc = new MiscBuildTool();
                            misc.BuildTool.Conditional = targ.Condition;
                            misc.BuildTool.Exec = targ.Name;
                            misc.BuildTool.Description = targ.Name;
                            misc.Name = targ.Name;
                            LoadTargetTasks(targ, misc.EnvironmentVariables, misc.BuildTool, misc.BuildToolOptions);
                            tool.MiscTools.Add(misc);
                            break;
                    }
                }

                BuildToolDefine[] tools = new BuildToolDefine[]
            {
                tool.Archiver,
                tool.AsmCompiler,
                tool.CCompiler,
                tool.CppCompiler,
                tool.Linker,
                tool.FromELF,
            };

                //first time to determine path
                foreach (BuildToolDefine td in tools)
                {
                    ExtractToolPath(tool, td.Exec);
                }
                //second time to remove path from exec command
                foreach (BuildToolDefine td in tools)
                {
                    td.Exec = ExtractToolPath(tool, td.Exec);
                }

                tool.ProjectPath = ConvertPathToEnv(fileName);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Error: loading target file: " + fullpath + "\r\n", e.Message);
            }
        }
        internal Library LoadLibraryProj(string libProjFile, string path, bool fForceReload)
        {
            Project proj;
            string fullpath = ExpandEnvVars(libProjFile, path);
            Library lib = null;

            try
            {
                lib = m_helper.FindLibraryByProject(fullpath);
                Library dbLib = null;

                if (!fForceReload)
                {
                    if (lib != null)
                    {
                        return lib;
                    }
                }

                if (!File.Exists(fullpath))
                {
                    return null;
                }

                if (lib == null)
                {
                    lib = new Library();
                }


                proj = LoadProject(fullpath);

                path = Path.GetDirectoryName(fullpath);

                lib.ProjectPath = ConvertPathToEnv(fullpath);

                if (fullpath.ToUpper().Contains("\\CLR\\"))
                {
                    lib.Level = LibraryLevel.CLR;
                }
                else if (fullpath.ToUpper().Contains("\\SUPPORT\\"))
                {
                    lib.Level = LibraryLevel.Support;
                }
                else if (fullpath.ToUpper().Contains("\\PAL\\"))
                {
                    lib.Level = LibraryLevel.PAL;
                }
                else
                {
                    lib.Level = LibraryLevel.HAL;
                }

                if (Path.GetFileName(fullpath).ToUpper().Contains("_STUB") ||
                    fullpath.ToUpper().Contains("\\STUBS"))
                {
                    lib.IsStub = true;
                }

                Dictionary<string, string> tbl = new Dictionary<string, string>();
                tbl["AssemblyName"] = "Name";
                tbl["ProjectGuid"] = "Guid";

                LoadStringProps(proj, lib, tbl);

                if (!fForceReload)
                {
                    dbLib = m_helper.FindLibrary(lib.Guid);

                    if (dbLib != null)
                    {
                        if (!string.Equals(dbLib.Name, lib.Name, StringComparison.InvariantCultureIgnoreCase))
                        {
                            System.Diagnostics.Debug.WriteLine("WARNING!!! Loaded library name doesn't match database library (possible bad project file)");
                            System.Diagnostics.Debug.WriteLine(dbLib.Name + " != " + lib.Name);
                        }
                        return dbLib;
                    }

                    dbLib = m_helper.FindLibraryByName(lib.Name);
                    if (dbLib != null) return dbLib;
                }

                if (string.IsNullOrEmpty(lib.LibraryFile)) lib.LibraryFile = lib.Name + ".$(LIB_EXT)";
                if (string.IsNullOrEmpty(lib.ManifestFile)) lib.ManifestFile = lib.LibraryFile + ".manifest";

                foreach (ProjectPropertyGroupElement pg in proj.Xml.PropertyGroups)
                {
                    foreach (ProjectPropertyElement bp in pg.Properties)
                    {
                        string cond = CombineConditionals(pg.Condition, bp.Condition);

                        switch (bp.Name)
                        {
                            /*
                        case "OutputType":
                            // don't allow projects to be loaded as library
                            if (0 == string.Compare(bp.Value.Trim(), "Executable", true))
                            {
                                return null;
                            }
                            break;
                            */
                            case "Version":
                                string[] vers = bp.Value.Split('.');
                                if (vers != null)
                                {
                                    if (vers.Length > 0) lib.Version.Major = vers[0];
                                    if (vers.Length > 1) lib.Version.Minor = vers[1];
                                    if (vers.Length > 2) lib.Version.Revision = vers[2];
                                    if (vers.Length > 3) lib.Version.Build = vers[3];
                                }
                                break;
                            case "PlatformIndependentBuild":
                                {
                                    bool fPlatIndep = false;
                                    bool.TryParse(bp.Value, out fPlatIndep);
                                    lib.PlatformIndependent = fPlatIndep;
                                }
                                break;
                            default:
                                {
                                    MFProperty prop = new MFProperty();
                                    prop.Name = bp.Name;
                                    prop.Value = bp.Value;
                                    prop.Condition = cond;
                                    lib.Properties.Add(prop);
                                }
                                break;
                        }
                    }
                }

                if (string.IsNullOrEmpty(lib.Name))
                {
                    string dirName = Path.GetFileName(Path.GetDirectoryName(fullpath));
                    if (string.Compare(dirName, "GlobalLock") == 0)
                    {
                        lib.Name = dirName;
                    }
                    else
                    {
                        return null;
                    }
                }


                LoadCompileItems(proj, lib, path);

                if (string.IsNullOrEmpty(lib.Guid))
                {
                    lib.Guid = System.Guid.NewGuid().ToString("B");
                }

                foreach (ProjectItemGroupElement big in proj.Xml.ItemGroups)
                {
                    foreach (ProjectItemElement bi in big.Items)
                    {
                        string cond = CombineConditionals(big.Condition, bi.Condition);

                        switch (bi.ItemType)
                        {
                            case "RequiredProjects":
                                if (bi.Include.Trim().ToUpper().EndsWith(".PROJ"))
                                {
                                    Library lib2 = LoadLibraryProj(bi.Include, path);

                                    if (lib2 != null)
                                    {
                                        lib.Dependencies.Add(new MFComponent(MFComponentType.Library, lib2.Name, lib2.Guid, bi.Include));
                                    }
                                    else
                                    {
                                        System.Diagnostics.Debug.WriteLine("Warning! unknown library " + bi.Include);
                                        //System.Diagnostics.Debug.Assert(false);
                                    }
                                }
                                break;
                            case "LibraryCategories":
                                LibraryCategory libCat = LoadLibraryCategoryProj(bi.Include, path);
                                lib.Dependencies.Add(new MFComponent(MFComponentType.LibraryCategory, libCat.Name, libCat.Guid, bi.Include, cond));
                                break;
                            case "FastCompileCPPFile":
                            case "Compile":
                            case "HFiles":
                            case "IncludePaths":
                                // handled by LoadCompileItems
                                break;

                            case "SubDirectories":
                                break;

                            default:
                                {
                                    MFBuildFile f = new MFBuildFile();
                                    f.Condition = cond;
                                    f.File = bi.Include;
                                    f.ItemName = bi.ItemType;
                                    lib.OtherFiles.Add(f);
                                }
                                break;
                        }
                    }
                }

                if (lib.IsStub && lib.LibraryCategory != null && !string.IsNullOrEmpty(lib.LibraryCategory.Guid))
                {
                    LibraryCategory lc = m_helper.FindLibraryCategory(lib.LibraryCategory.Guid);
                    if (lc != null)
                    {
                        lc.StubLibrary = new MFComponent(MFComponentType.Library, lib.Name, lib.Guid, lib.ProjectPath);

                        if (lc.Level != LibraryLevel.CLR && lc.Level != LibraryLevel.Support && lc.Templates.Count == 0)
                        {
                            lc.Templates.Clear();

                            ApiTemplate api = new ApiTemplate();
                            api.FilePath = ConvertPathToEnv(fullpath);
                            lc.Templates.Add(api);

                            foreach (MFBuildFile bf in lib.SourceFiles)
                            {
                                api = new ApiTemplate();
                                api.FilePath = ConvertPathToEnv(Path.Combine(path, bf.File));
                                lc.Templates.Add(api);
                            }
                            foreach (MFBuildFile bf in lib.HeaderFiles)
                            {
                                if (Path.IsPathRooted(MsBuildWrapper.ExpandEnvVars(bf.File,"")) || bf.File.Contains("..")) continue;

                                api = new ApiTemplate();
                                api.FilePath = ConvertPathToEnv(Path.Combine(path, bf.File));
                                lc.Templates.Add(api);
                            }
                            foreach (MFBuildFile bf in lib.FastCompileFiles)
                            {
                                api = new ApiTemplate();
                                api.FilePath = ConvertPathToEnv(Path.Combine(path, bf.File));
                                lc.Templates.Add(api);
                            }
                        }

                    }
                }

                foreach (ProjectTargetElement targ in proj.Xml.Targets)
                {
                    lib.Targets.Add(targ);
                }

                foreach (ProjectImportElement imp in proj.Xml.Imports)
                {
                    switch (Path.GetExtension(imp.Project).ToUpper().Trim())
                    {
                        case ".LIBCATPROJ":
                            LibraryCategory lc = LoadLibraryCategoryProj(imp.Project, path);
                            if (lc != null)
                            {
                                MFComponent cmp = new MFComponent(MFComponentType.LibraryCategory, lc.Name, lc.Guid, lc.ProjectPath);
                                lib.Dependencies.Add(cmp);
                            }
                            else
                            {
                                System.Diagnostics.Debug.Assert(false);
                            }
                            break;
                    }
                }

                m_helper.AddLibraryToInventory(lib, false, m_helper.DefaultInventory);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Error: loading Library file: " + fullpath + "\r\n", e.Message);
                lib = null;
            }

            return lib;
        }
 public void CopyTo(MFProperty dest)
 {
     CopyHelper.CopyTo(this, dest);
 }