/// <summary> /// Gets the framework path which best matches the specified version /// </summary> /// <param name="frameworkVersion">The framework version.</param> /// <returns></returns> public static DirectoryInfo GetFrameworkDirectory(Version frameworkVersion) { if (frameworkVersion == null) { throw new ArgumentNullException("frameworkVersion"); } string runtimeDir = QQnPath.NormalizePath(RuntimeEnvironment.GetRuntimeDirectory()); string frameworkDir = Path.GetDirectoryName(runtimeDir); DirectoryInfo dir = new DirectoryInfo(frameworkDir); if (!dir.Exists) { return(null); } if (frameworkVersion.Major == 4 && frameworkVersion.Minor == 5) { frameworkVersion = new Version(4, 0); } DirectoryInfo[] dirs = dir.GetDirectories("v*.*", SearchOption.TopDirectoryOnly); int start = 2; if (frameworkVersion.Build >= 0) { start = 4; } else if (frameworkVersion.Revision >= 0) { start = 3; } for (int i = start; i >= 2; i--) { string name = "v" + frameworkVersion.ToString(i); foreach (DirectoryInfo d in dirs) { if (string.Equals(d.Name, name, StringComparison.InvariantCultureIgnoreCase)) { return(d); } } name += "."; foreach (DirectoryInfo d in dirs) { if (d.Name.StartsWith(name, StringComparison.InvariantCultureIgnoreCase)) { return(d); } } } return(null); }
public void EnsureRelativePath() { Assert.That(QQnPath.EnsureRelativePath("c:\\tools", "c:/tools/t.txt"), Is.EqualTo("t.txt")); Assert.That(QQnPath.EnsureRelativePath("c:\\tools", "c:/t.txt"), Is.EqualTo("..\\t.txt")); Assert.That(QQnPath.EnsureRelativePath("c:\\tools", "t.txt"), Is.EqualTo("t.txt")); Assert.That(QQnPath.EnsureRelativePath("c:\\tools", "\\banaan\\t.txt"), Is.EqualTo("..\\banaan\\t.txt")); string currentDisk = Path.GetPathRoot(Environment.CurrentDirectory); string otherDisk; if (string.Equals(currentDisk, "z:\\", StringComparison.OrdinalIgnoreCase)) { otherDisk = "z:\\"; } else { otherDisk = "c:\\"; } Assert.That(Path.Combine(otherDisk + "tools", "\\t.txt"), Is.EqualTo("\\t.txt"), "Path.Combine works like .Net 2.0"); Assert.That(Path.GetFullPath(Path.Combine(otherDisk + "tools", "\\t.txt")), Is.EqualTo(currentDisk + "t.txt"), "Path.Combine works like .Net 2.0"); Assert.That(QQnPath.Combine(otherDisk + "tools", "\\t.txt"), Is.EqualTo(otherDisk + "t.txt"), "QQnPath combines always relative"); Assert.That(QQnPath.NormalizePath("c:\\", false), Is.EqualTo("c:\\")); }
public override void ApplyProjectDependencies(PackageState state) { if (!state.DontUseProjectDependencies) // Allow disabling for testing { // Add an initial set of dependencies directly from the project files foreach (TBLogConfiguration config in LogFile.Configurations) { foreach (TBLogItem project in config.References.Projects) { string src = QQnPath.NormalizePath(project.FullSrc); foreach (Origin o in state.Origins) { BuildOrigin bo = o as BuildOrigin; if (bo == null) { continue; } if (QQnPath.Equals(bo.ProjectFile, src) && !Dependencies.ContainsKey(o)) { EnsureDependency(o, DependencyType.LinkedTo); } } } } } foreach (TBLogItem item in LogFile.AllProjectOutput) { FileData fd = state.Files[item.FullSrc]; if (!string.IsNullOrEmpty(fd.CopiedFrom)) { FileData src; if (state.Files.TryGetValue(fd.CopiedFrom, out src)) { if (src.Origin != this) { EnsureDependency(src.Origin, item.IsCopy ? DependencyType.Required : DependencyType.LinkedTo); } } } } foreach (TBLogItem item in LogFile.AllContents) { FileData fd = state.Files[item.FullSrc]; if (!string.IsNullOrEmpty(fd.CopiedFrom)) { FileData src; if (state.Files.TryGetValue(fd.CopiedFrom, out src)) { if (src.Origin != this) { EnsureDependency(src.Origin, DependencyType.Required); } } } } }
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); } }
public void NormalizeTest() { Assert.That(QQnPath.NormalizePath("bin\\\\debug\\release\\test.dir\\"), Is.EqualTo("bin\\debug\\release\\test.dir")); Assert.That(QQnPath.NormalizePath("bin\\\\debug\\release\\test.dir\\", false), Is.EqualTo("bin\\debug\\release\\test.dir")); Assert.That(QQnPath.NormalizePath("bin\\\\debug\\release\\test.dir\\", true), Is.EqualTo("bin\\debug\\release\\test.dir\\")); }