Exemple #1
0
        public void PropertyTests()
        {
            TagPropertyCollection tpc = new TagPropertyCollection();

            tpc.LoadEnvironmentVariables();

            Assert.That(tpc, Is.All.Not.Null);

            Assert.That(tpc["PATH"], Is.Not.Null);

            Assert.That(tpc.ExpandProperties("$(Path)"), Is.EqualTo(Environment.GetEnvironmentVariable("PATH")));

            Assert.That(TagBatchDefinition.IsTagItemType(typeof(Microsoft.Build.Framework.ITaskItem)), Is.True);
            Assert.That(TagBatchDefinition.IsTagItemType(typeof(string)), Is.True);
            Assert.That(TagBatchDefinition.IsTagItemType(typeof(ITagItem)), Is.True);
            Assert.That(TagBatchDefinition.IsTagItemType(typeof(int)), Is.False);
        }
        private void ParseProjectFile(string fullConfiguration, Project parentProject)
        {
            if (_parsed)
            {
                return;
            }

            _parsed = true;
            TagPropertyCollection tpc = new TagPropertyCollection();

            string[] items = fullConfiguration.Split('|');
            ProjectConfiguration = items[0];
            ProjectPlatform      = items[1];

            tpc.Set("PlatformName", ProjectPlatform);
            tpc.Set("ConfigurationName", ProjectConfiguration);

            Solution solution = parentProject as Solution;

            if (solution != null)
            {
                tpc.Set("SolutionDir", QQnPath.NormalizePath(solution.ProjectPath, true));
                tpc.Set("SolutionPath", QQnPath.NormalizePath(solution.ProjectFile));
                tpc.Set("SolutionName", solution.ProjectName);
                tpc.Set("SolutionFileName", Path.GetFileName(ProjectFile));
            }

            tpc.Set("ProjectDir", QQnPath.NormalizePath(ProjectPath, true));
            tpc.Set("ProjectPath", QQnPath.NormalizePath(ProjectFile));
            tpc.Set("ProjectName", ProjectName);
            tpc.Set("ProjectFileName", Path.GetFileName(ProjectFile));
            tpc.Set("ProjectExt", Path.GetExtension(ProjectFile));

            using (StreamReader sr = File.OpenText(ProjectFile))
            {
                XPathDocument doc = new XPathDocument(sr);

                XPathNavigator dn = doc.CreateNavigator();

                TargetName = dn.SelectSingleNode("/VisualStudioProject").GetAttribute("Name", "");
                tpc.Set("TargetName", TargetName);
                tpc.Set("ProjectName", TargetName);

                XPathNavigator config   = dn.SelectSingleNode("//Configurations/Configuration[@Name='" + FullProjectConfiguration + "']");
                XPathNavigator compiler = config.SelectSingleNode("Tool[@Name='VCCLCompilerTool']");
                XPathNavigator linker   = config.SelectSingleNode("Tool[@Name='VCLinkerTool']");

                if (string.IsNullOrEmpty(TargetName) || config == null || compiler == null)
                {
                    TargetName = null;
                    return;                     // No .Net assembly output
                }

                OutputPath = tpc.ExpandProperties(config.GetAttribute("OutputDirectory", ""));
                tpc.Set("OutDir", QQnPath.NormalizePath(GetFullPath(OutputPath), true));

                string intPath = tpc.ExpandProperties(config.GetAttribute("IntermediateDirectory", ""));
                intPath = GetFullPath(intPath);
                tpc.Set("IntDir", QQnPath.NormalizePath(intPath, true));

                ProjectOutput.BaseDirectory = ProjectPath;

                switch (int.Parse(config.GetAttribute("ConfigurationType", "").Trim(), NumberStyles.None))
                {
                case 1:
                    TargetExt = ".exe";
                    break;

                case 4:
                    TargetExt = ".lib";
                    linker    = config.SelectSingleNode("Tool[@Name='VCLibrarianTool']");
                    break;

                case 2:
                default:
                    TargetExt = ".dll";
                    break;
                }

                tpc.Set("TargetExt", TargetExt);

                string tp = linker.GetAttribute("OutputFile", "");

                if (!string.IsNullOrEmpty(tp))
                {
                    tp = tpc.ExpandProperties(tp);

                    if (!string.IsNullOrEmpty(tp))
                    {
                        tp = EnsureRelativePath(tp);

                        TargetName = Path.GetFileNameWithoutExtension(tp);
                        TargetExt  = Path.GetExtension(tp);
                        tpc.Set("TargetExt", TargetExt);

                        if (!string.Equals(TargetPath, tp, StringComparison.OrdinalIgnoreCase))
                        {
                            TargetPath = tp;                             // Only set the override if the construction was not ok
                        }
                    }
                }

                if (!File.Exists(GetFullPath(TargetPath)) || linker == null)
                {
                    TargetName = null;
                    return;                     // Something went wrong.. Check project format
                }

                string mc = config.GetAttribute("ManagedExtensions", "");
                if (!string.IsNullOrEmpty(mc))
                {
                    switch (int.Parse(mc.Trim(), NumberStyles.None))
                    {
                    case 0:
                        break;                                 // No clr?

                    case 1:
                    default:
                        IsAssembly = QQnPath.IsAssemblyFile(TargetPath);
                        break;
                    }
                }

                string value = TargetPath;
                ProjectOutput.Add(new TargetItem(value, value, TargetType.Item));

                if (string.Equals(compiler.GetAttribute("GenerateXMLDocumentationFiles", ""), "true", StringComparison.OrdinalIgnoreCase))
                {
                    string xmlFile = Path.ChangeExtension(value, ".xml");

                    if (File.Exists(GetFullPath(xmlFile)))
                    {
                        ProjectOutput.Add(new TargetItem(xmlFile, xmlFile, TargetType.Item));
                    }
                }

                if (string.Equals(linker.GetAttribute("GenerateDebugInformation", ""), "true", StringComparison.OrdinalIgnoreCase))
                {
                    string pdbFile = Path.ChangeExtension(value, ".pdb");

                    if (File.Exists(GetFullPath(pdbFile)))
                    {
                        ProjectOutput.Add(new TargetItem(pdbFile, pdbFile, TargetType.Item));
                    }
                }

                if (!string.IsNullOrEmpty(value = linker.GetAttribute("KeyFile", "")))
                {
                    KeyFile = EnsureRelativePath(tpc.ExpandProperties(value));
                }

                if (!string.IsNullOrEmpty(value = linker.GetAttribute("KeyContainer", "")))
                {
                    KeyContainer = value;
                }

                FindContentAndScripts(doc);
            }
        }
Exemple #3
0
        public override string ToString(TagBatchInstance instance)
        {
            TagPropertyCollection tpc = instance.Context.Properties;

            return(tpc.Contains(PropertyName) ? tpc[PropertyName].ExpandedValue() : "");
        }