private void OnExternalProjectFinished(object sender, ExternalProjectFinishedEventArgs e) { if (_solution == null) { return; // Shortcut } ExternalProject ep; if (_solution.ExternalProjects.TryGetValue(e.ProjectFile, out ep)) { ep.ProjectFinished(_solution); return; } // VC Uses temporary project files; look for the real file string dir = Path.GetDirectoryName(e.ProjectFile); string file = Path.GetFileNameWithoutExtension(e.ProjectFile); string ext = Path.GetExtension(e.ProjectFile); string ext2 = Path.GetExtension(file); if (!string.IsNullOrEmpty(ext2) && ext2.StartsWith(".tmp_", StringComparison.OrdinalIgnoreCase)) { // PROJECT.tmp_Win32_Release.VCPROJ -> PROJECT.VCPROJ string realProject = QQnPath.Combine(dir, Path.GetFileNameWithoutExtension(file) + ext); // Try in memory first, as this is always faster than on disk if (_solution.ExternalProjects.TryGetValue(realProject, out ep) && File.Exists(realProject)) { ep.ProjectFinished(_solution); } } }
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 void CreateZipAndTpz() { using (ZipFile zf = ZipFile.Create(QQnPath.Combine(TmpPath, "TestZip.zip"))) { AddSomeFiles(zf); } AssuredStreamCreateArgs assuredArgs = new AssuredStreamCreateArgs(); assuredArgs.StrongNameKey = StrongNameKey.LoadFrom(SnkFile); assuredArgs.FileType = "TPZ-Test"; MultipleStreamCreateArgs mutlArgs = new MultipleStreamCreateArgs(); mutlArgs.VerificationMode = VerificationMode.Full; using (FileStream fileStream = File.Create(QQnPath.Combine(TmpPath, "TestTpz.zip"))) using (AssuredStream assuredStream = new AssuredStream(fileStream, assuredArgs)) using (MultipleStreamWriter msw = new MultipleStreamWriter(assuredStream, mutlArgs)) { using (Stream s = msw.CreateStream()) { s.WriteByte(255); } using (Stream s = msw.CreateStream()) using (ZipFile zf = ZipFile.Create(s)) { AddSomeFiles(zf); } } }
/// <summary> /// Extracts the package to the specified directory /// </summary> /// <param name="directory">The directory.</param> /// <param name="args">The args.</param> public void ExtractTo(string directory, TurtleExtractArgs args) { if (string.IsNullOrEmpty(directory)) { throw new ArgumentNullException("directory"); } else if (args == null) { throw new ArgumentNullException("args"); } if (args.UseDirectoryMap) { using (DirectoryMap dm = DirectoryMap.Get(directory)) { ExtractTo(dm, args); } return; } ExtractFiles(args, delegate(ExtractorEventArgs e) { using (Stream s = File.Create(QQnPath.Combine(directory, e.PackFile.RelativePath))) { QQnPath.CopyStream(e.Stream, s); } }); }
/// <summary> /// Gets log file with the specified name /// </summary> /// <param name="name">The name of the project or the name of the logfile</param> /// <returns></returns> public TBLogFile Get(string name) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } name = QQnPath.EnsureExtension(name, ".tbLog"); if (ContainsKey(name)) { return(this[name]); } if (!string.IsNullOrEmpty(_logPath)) { name = QQnPath.Combine(_logPath, name); } TBLogFile logFile = TBLogFile.Load(name); Add(name, logFile); return(logFile); }
public void GetToolsDirectory_40_ReturnsDirectory() { DirectoryInfo dir = BuildTools.GetBuildToolsDirectory(new Version("4.0")); Assert.That(dir.Name, Is.EqualTo("v4.0.30319")); Assert.That(File.Exists(QQnPath.Combine(dir.FullName, "msbuild.exe")), "MSBuild exists"); }
/// <summary> /// Tries to get the generated metadata item. /// </summary> /// <param name="metaDataName">Name of the meta data.</param> /// <param name="value">The value.</param> /// <returns></returns> bool TryTransformMetaData(string metaDataName, out string value) { int n; switch (metaDataName) { case "FullPath": value = FullPath; return(true); case "RootDir": value = Path.GetPathRoot(QQnPath.Combine(_project.ProjectPath, Include)); return(true); case "Filename": value = Filename; return(true); case "Extension": value = Extension; return(true); case "RelativeDir": n = Include.LastIndexOfAny(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }); value = (n >= 0) ? Include.Substring(0, n + 1) : ""; return(true); case "Directory": value = QQnPath.Combine(_project.ProjectPath, Include); n = value.LastIndexOfAny(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }); value = (n >= 0) ? Include.Substring(0, n + 1) : ""; value = value.Substring(Path.GetPathRoot(value).Length); return(true); case "RecursiveDir": value = ""; return(true); case "Identity": value = Include; return(true); case "ModifiedTime": value = new DirectoryInfo(QQnPath.Combine(_project.ProjectPath, Include)).LastWriteTime.ToString("u"); return(true); case "CreatedTime": value = new DirectoryInfo(QQnPath.Combine(_project.ProjectPath, Include)).CreationTime.ToString("u"); return(true); case "AccessedTime": value = new DirectoryInfo(QQnPath.Combine(_project.ProjectPath, Include)).LastAccessTime.ToString("u"); return(true); default: value = null; return(false); } }
public void BuildExternal() { ProcessStartInfo psi = new ProcessStartInfo(MSBuild, string.Format("/nologo \"{0}\" /v:q /p:Configuration={1} \"/logger:MSBuildLogger,{2};OutputDir={3};Indent=true\"", Solution, OtherConfiguration, Logger, LoggerPath)); psi.UseShellExecute = false; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; psi.CreateNoWindow = true; using (Process p = Process.Start(psi)) { p.WaitForExit(); string output = p.StandardOutput.ReadToEnd(); string err = p.StandardError.ReadToEnd(); Assert.That(err, Is.EqualTo(""), "MSBuild gave no error"); //Assert.That(output, Is.EqualTo(""), "MSBuild gave no output"); Assert.That(p.ExitCode, Is.EqualTo(0), "MSBuild ran successfully"); } Assert.That(File.Exists(QQnPath.Combine(LoggerPath, "QQn.TurtleMSBuild.tbLog")), Is.True, "Logfile created"); XPathDocument doc = new XPathDocument(QQnPath.Combine(LoggerPath, "QQn.TurtleMSBuild.tbLog")); XPathNavigator nav = doc.CreateNavigator(); XmlNamespaceManager nsMgr = new XmlNamespaceManager(nav.NameTable); nsMgr.AddNamespace("tb", "http://schemas.qqn.nl/2007/TurtleBuild/BuildResult"); Assert.That(nav.SelectSingleNode("/tb:TurtleBuildData/tb:Configuration", nsMgr).GetAttribute("outputPath", ""), Is.Not.EqualTo(""), "outputPath is set"); //doc.CreateNavigator().SelectSingleNode(" TBLogFile file = TBLogFile.Load(QQnPath.Combine(LoggerPath, "QQn.TurtleMSBuild.tbLog")); Assert.That(file, Is.Not.Null); Assert.That(file.Configurations.Count, Is.GreaterThanOrEqualTo(1), "Configurations available"); Assert.That(file.Configurations[0].ProjectOutput.Items.Count, Is.GreaterThan(1)); Assert.That(file.Configurations[0].ProjectOutput.Items[0].Container, Is.SameAs(file.Configurations[0].ProjectOutput), "Container is set"); Assert.That(file.Configurations[0].Target.DebugSrc, Is.Not.Null); using (StringWriter sw = new StringWriter()) { using (XmlWriter xw = new XmlTextWriter(sw)) { xw.WriteStartDocument(); xw.WriteStartElement("TurtleBuild", "q:q"); QQn.TurtleUtils.Tokens.Tokenizer.TryWriteXml(new XmlTextWriter(sw), file); xw.WriteEndDocument(); } string text = sw.ToString(); Assert.That(text.Length, Is.GreaterThan(100)); } }
public void CopyResources() { Uri uri = new Uri(typeof(AssemblyUtils).Assembly.CodeBase); string file = uri.LocalPath; string tmpFile = QQnPath.Combine(Path.GetTempPath(), Path.GetFileName(file)); File.Copy(file, tmpFile, true); Assert.That(AssemblyUtils.RefreshVersionInfoFromAttributes(tmpFile, Path.GetFullPath("..\\..\\..\\..\\Libraries\\QQn.TurtleBuildUtils\\QQn.TurtleBuildUtils.snk"), null)); }
public void CalculatePackage(bool useProjectReferences) { string logFile = QQnPath.Combine(LoggerPath, "QQn.TurtleMSBuild.tbLog"); if (!File.Exists(logFile)) { BuildInternal(); } TBLogCache logCollection = new TBLogCache(LoggerPath); logCollection.LoadAll(); PackageArgs args = new PackageArgs(); args.LogCache = logCollection; args.BuildRoot = Path.GetDirectoryName(Solution); args.UseProjectDependencies = useProjectReferences; args.ProjectsToPackage.AddRange(logCollection.KeysAsFullPaths); PackageList newPackages; Assert.That(Packager.TryCreatePackages(args, out newPackages), "Created packages"); Assert.That(newPackages.Count, Is.EqualTo(args.ProjectsToPackage.Count), "All projects packaged"); if (Directory.Exists("f:\\extractor")) { Directory.Delete("f:\\extractor", true); } if (Directory.Exists("f:\\extractor2")) { Directory.Delete("f:\\extractor2", true); } if (!Directory.Exists("f:\\extractor")) { Directory.CreateDirectory("f:\\extractor"); } if (!Directory.Exists("f:\\extractor2")) { Directory.CreateDirectory("f:\\extractor2"); } foreach (TPack p in newPackages) { p.ExtractTo("f:\\extractor"); } foreach (TPack p in newPackages) { p.ExtractTo("f:\\extractor2", true); } }
public BuildOrigin(TBLogFile logFile) { if (logFile == null) { throw new ArgumentNullException("logFile"); } _log = logFile; _projectFile = QQnPath.Combine(logFile.ProjectPath, logFile.Project.File); }
/// <summary> /// Tries to create packages from the specified logfiles; walking dependencies if needed. /// </summary> /// <param name="args">The args.</param> /// <param name="newPackages">The new packages.</param> /// <returns></returns> public static bool TryCreatePackages(PackageArgs args, out PackageList newPackages) { if (args == null) { throw new ArgumentNullException("args"); } PackageState state = new PackageState(args); state.LoadExternalOrigins(); state.CreateBuildOrigins(); state.AddRequirements(); state.CalculateDependencies(); newPackages = new PackageList(); List <TBLogFile> filesToRun = new List <TBLogFile>(state.Logs); while (filesToRun.Count > 0) { int n = 0; for (int i = 0; i < filesToRun.Count; i++) { TBLogFile file = filesToRun[i]; if (state.CanPackage(file)) { filesToRun.RemoveAt(i--); string target = QQnPath.Combine(args.OutputDir, file.Project.Name + ".tpZip"); FileInfo targetInfo = new FileInfo(target); TPack pack; if (targetInfo.Exists && targetInfo.LastWriteTime > file.GetLastWriteTime()) { pack = TPack.OpenFrom(target, VerificationMode.None); state.SetOriginPack(file, pack.Pack); } else { pack = TPack.Create(target, state.CreateDefinition(file)); } newPackages.Add(target, pack); n++; } } if (n == 0) { break; // Can't package anything } } return(true); }
/// <summary> /// Updates the version info in the file header from the attributes defined on the assembly. /// </summary> /// <param name="assemblyFile">The assembly.</param> /// <param name="keyFile">The key file.</param> /// <param name="keyContainer">The key container.</param> /// <returns></returns> public static bool RefreshVersionInfoFromAttributes(string assemblyFile, string keyFile, string keyContainer) { if (string.IsNullOrEmpty(assemblyFile)) { throw new ArgumentNullException("assemblyFile"); } if (!File.Exists(assemblyFile)) { throw new FileNotFoundException("File to update not found", assemblyFile); } else if (!string.IsNullOrEmpty(keyFile) && !File.Exists(keyFile)) { throw new FileNotFoundException("Keyfile not found", keyFile); } string tmpDir = QQnPath.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(tmpDir); try { string tmpName = QQnPath.Combine(tmpDir, Path.GetFileNameWithoutExtension(assemblyFile) + ".dll"); Assembly myAssembly = typeof(AssemblyUtils).Assembly; AppDomainSetup setup = new AppDomainSetup(); setup.ApplicationName = "TB-AttributeRefresher"; setup.ApplicationBase = Path.GetDirectoryName(new Uri(myAssembly.CodeBase).LocalPath); setup.AppDomainInitializer = new AppDomainInitializer(OnRefreshVersionInfo); setup.AppDomainInitializerArguments = new string[] { assemblyFile, tmpDir, tmpName }; AppDomain dom = AppDomain.CreateDomain("AttributeRefresher", myAssembly.Evidence, setup); AppDomain.Unload(dom); // Remove locks if (!File.Exists(tmpName)) { return(false); } return(CopyFileVersionInfo(tmpName, assemblyFile, keyFile, keyContainer)); } finally { if (Directory.Exists(tmpDir)) { Directory.Delete(tmpDir, true); } } }
public virtual void PostParseBuildResult() { if (string.IsNullOrEmpty(TargetPath) || string.IsNullOrEmpty(ProjectPath)) { return; } if ((DebugSrc == null) || (DebugId == null)) { string targetFile = GetFullPath(TargetPath); if (QQnPath.IsAssemblyFile(targetFile) && File.Exists(targetFile)) { DebugReference reference = AssemblyUtils.GetDebugReference(targetFile); if (reference != null) { string pdbSrc = EnsureRelativePath(QQnPath.Combine(ProjectPath, Path.GetDirectoryName(TargetPath), reference.PdbFile)); FileInfo pdbTarget = new FileInfo(Path.GetFullPath(QQnPath.Combine(ProjectPath, Path.GetDirectoryName(TargetPath), Path.GetFileName(pdbSrc)))); if (pdbTarget.Exists) { FileInfo pdbFrom = new FileInfo(GetFullPath(pdbSrc)); if (!pdbFrom.Exists || ((pdbFrom.Length == pdbTarget.Length) && (pdbFrom.LastWriteTime == pdbTarget.LastWriteTime))) { pdbSrc = EnsureRelativePath(pdbTarget.FullName); } } DebugSrc = pdbSrc; DebugId = reference.DebugId; } else { string pdbFile = Path.ChangeExtension(targetFile, ".pdb"); if (ProjectOutput.ContainsKey(pdbFile) && File.Exists(pdbFile)) { pdbFile = EnsureRelativePath(pdbFile); DebugSrc = pdbFile; } } } } }
public void WriteTBLog() { if (TargetName == null) { return; } string outDir = OutputPath; outDir = Parameters.OutputPath ?? GetFullPath(OutputPath); if (!Directory.Exists(outDir)) { Directory.CreateDirectory(outDir); } string atPath = QQnPath.Combine(outDir, ProjectName + ".tbLog"); if (File.Exists(atPath)) { try { using (FileStream fs = File.OpenRead(atPath)) { _previousLog = new XPathDocument(fs); } } catch { _previousLog = null; } } using (StreamWriter sw = new StreamWriter(atPath, false, Encoding.UTF8)) { XmlWriterSettings xs = new XmlWriterSettings(); xs.Indent = Parameters.Indent; using (XmlWriter xw = XmlWriter.Create(sw, xs)) { WriteTBLog(xw, xs.Indent); } } }
/// <summary> /// Calculates the target. /// </summary> /// <param name="pi">The pi.</param> /// <returns></returns> protected string CalculateTarget(ITaskItem pi) { string target = pi.GetMetadata("TargetPath"); if (!string.IsNullOrEmpty(target)) { return(QQnPath.Combine(OutputPath, target)); } string destinationSubDirectory = pi.GetMetadata("DestinationSubDirectory"); string filename = Path.GetFileName(pi.ItemSpec); if (!string.IsNullOrEmpty(destinationSubDirectory)) { return(QQnPath.Combine(OutputPath, destinationSubDirectory, filename)); } else { return(QQnPath.Combine(OutputPath, filename)); } }
private void ParseProjectOutput() { ProjectOutputList items = ProjectOutput; SortedFileList <bool> localCopyItems = new SortedFileList <bool>(); SortedFileList <TargetType> keys = new SortedFileList <TargetType>(); ProjectOutput.BaseDirectory = ProjectPath; localCopyItems.BaseDirectory = ProjectPath; keys.BaseDirectory = ProjectPath; SortedList <string, bool> copyKeys = new SortedList <string, bool>(); foreach (string v in GetParameters("SharedItems", Parameters.SharedItems, "")) { if (!keys.ContainsKey(v)) { keys.Add(v, TargetType.SharedItem); } } foreach (string v in GetParameters("LocalItems", Parameters.LocalItems, "")) { if (!keys.ContainsKey(v)) { keys.Add(v, TargetType.Item); } } foreach (string v in GetParameters("CopyItems", Parameters.LocalItems, "None;Compile;Content;EmbeddedResource")) { if (!copyKeys.ContainsKey(v)) { copyKeys.Add(v, true); } } string primaryTarget = QQnPath.Combine(OutputPath, TargetName + TargetExt); string itemTarget = primaryTarget; items.Add(new TargetItem(itemTarget, QQnPath.Combine(IntermediateOutputPath, TargetName + TargetExt), TargetType.Item)); if (BuildProperties.ContainsKey("_SGenDllCreated") && GetProperty("_SGenDllCreated") == "true" && BuildProperties.ContainsKey("_SGenDllName")) { string dllName = GetProperty("_SGenDllName"); itemTarget = QQnPath.Combine(OutputPath, dllName); items.Add(new TargetItem(itemTarget, QQnPath.Combine(IntermediateOutputPath, dllName), TargetType.Item)); } if (BuildProperties.ContainsKey("_DebugSymbolsProduced") && GetProperty("_DebugSymbolsProduced") == "true") { string pdbName = GetProperty("TargetName") + ".pdb"; DebugSrc = pdbName; itemTarget = QQnPath.Combine(OutputPath, pdbName); items.Add(new TargetItem(itemTarget, QQnPath.Combine(IntermediateOutputPath, pdbName), TargetType.Item)); } foreach (ProjectItem pi in BuildItems) { if (string.IsNullOrEmpty(pi.Include)) { continue; } TargetType type = TargetType.None; switch (pi.Name) { // TODO: Rewrite to a per-language infrastructure case "IntermediateAssembly": case "AddModules": case "DocFileItem": case "IntermediateSatelliteAssembliesWithTargetPath": type = TargetType.Item; break; case "ContentWithTargetPath": case "AllItemsFullPathWithTargetPath": case "ReferenceCopyLocal": string condition; if (pi.TryGetMetaData("CopyToOutputDirectory", out condition)) { switch (condition) { case "Always": case "PreserveNewest": type = TargetType.SharedCopy; break; default: break; } } if (type == TargetType.None) { goto default; } break; case "ReferenceComWrappersToCopyLocal": case "ResolvedIsolatedComModules": case "_DeploymentLooseManifestFile": case "ReferenceCopyLocalPaths": case "NativeReferenceFile": string fusionName = pi.GetMetadata("FusionName"); if (!string.IsNullOrEmpty(fusionName)) { References.Add(new AssemblyReference(fusionName, pi, this)); } type = TargetType.SharedItem; break; default: if (!keys.TryGetValue(pi.Name, out type)) { type = TargetType.None; } break; } if (type != TargetType.None) { string target = CalculateTarget(pi); if (!items.ContainsKey(target)) { items.Add(new TargetItem(EnsureRelativePath(target), EnsureRelativePath(pi.Include), type, pi)); } } if (copyKeys.ContainsKey(pi.Name)) { string copyCondition; if (pi.TryGetMetaData("CopyToOutputDirectory", out copyCondition)) { switch (copyCondition) { case "Always": case "PreserveNewest": { localCopyItems[pi.Include] = true; } break; } } } } foreach (TargetItem ti in items.Values) { if (ti.Type == TargetType.SharedCopy) { if (localCopyItems.ContainsKey(ti.Include)) { ti.Type = TargetType.Copy; } } } }
/// <summary> /// Tries to create a pack. /// </summary> /// <param name="project">The project.</param> /// <param name="pack">The pack.</param> /// <returns></returns> public static bool TryCreatePack(TBLogFile project, out Pack pack) { if (project == null) { throw new ArgumentNullException("project"); } TBLogFile log = project; string projectDir = project.Project.Path; Pack p = new Pack(); p.BaseDir = projectDir; PackContainer projectOutput = p.Containers.AddItem("#ProjectOutput"); TBLogConfiguration config = log.Configurations[0]; if (!string.IsNullOrEmpty(config.OutputPath)) { projectOutput.ContainerDir = config.OutputPath; projectOutput.BaseDir = config.OutputPath; } foreach (TBLogItem item in config.ProjectOutput.Items) { if (item.IsShared) { continue; } PackFile pf = projectOutput.Files.AddItem(QQnPath.MakeRelativePath(projectOutput.BaseDir, QQnPath.Combine(projectDir, item.Src))); pf.StreamName = item.Src; } PackContainer projectContent = p.Containers.AddItem("#ProjectContent"); if (!string.IsNullOrEmpty(config.OutputPath)) { projectContent.ContainerDir = "content/" + log.Project.Name; projectContent.BaseDir = log.ProjectPath; } foreach (TBLogItem item in config.Content.Items) { PackFile pf = projectContent.Files.AddItem(QQnPath.MakeRelativePath(projectContent.BaseDir, QQnPath.Combine(projectDir, item.Src))); pf.StreamName = item.Src; } PackContainer projectScripts = p.Containers.AddItem("#ProjectScripts"); if (!string.IsNullOrEmpty(config.OutputPath)) { projectScripts.ContainerDir = "scripts/" + log.Project.Name; projectScripts.BaseDir = log.Project.Path; } foreach (TBLogItem item in config.Content.Items) { PackFile pf = projectContent.Files.AddItem(QQnPath.MakeRelativePath(projectContent.BaseDir, QQnPath.Combine(projectDir, item.Src))); pf.StreamName = item.Src; } if (config.Target.KeySrc != null) { p.StrongNameKey = StrongNameKey.LoadFrom(QQnPath.Combine(log.Project.Path, config.Target.KeySrc)); } else if (config.Target.KeyContainer != null) { p.StrongNameKey = StrongNameKey.LoadFromContainer(config.Target.KeyContainer, false); } foreach (PackContainer pc in p.Containers) { foreach (PackFile pf in pc.Files) { VerifyUtils.UpdateFile(pf.BaseDir, pf); } } pack = p; return(true); }
public Pack CreateDefinition(TBLogFile file) { BuildOrigin myOrigin = null; foreach (BuildOrigin bo in BuildOrigins) { if (bo.LogFile == file) { myOrigin = bo; break; } } Pack p = new Pack(); TBLogConfiguration config = file.Configurations[0]; TBLogTarget target = config.Target; TBLogAssembly asm = config.Assembly; if (!string.IsNullOrEmpty(target.KeySrc)) { p.StrongNameKey = StrongNameKey.LoadFrom(QQnPath.Combine(file.ProjectPath, target.KeySrc)); } else if (!string.IsNullOrEmpty(target.KeyContainer)) { p.StrongNameKey = StrongNameKey.LoadFromContainer(target.KeyContainer, false); } if (asm != null && !string.IsNullOrEmpty(asm.AssemblyName)) { AssemblyName name = new AssemblyName(asm.AssemblyName); p.Version = name.Version; } PackContainer po = p.Containers.AddItem("#ProjectOutput"); po.ContainerDir = config.OutputPath; po.BaseDir = QQnPath.Combine(file.ProjectPath); foreach (TBLogItem item in file.AllProjectOutput) { if (item.IsShared) { continue; } PackFile pf = po.Files.AddItem(QQnPath.EnsureRelativePath(po.BaseDir, item.FullSrc)); pf.StreamName = item.Src; } PackContainer ct = p.Containers.AddItem("#Content"); ct.ContainerDir = ""; po.BaseDir = file.ProjectPath; foreach (TBLogItem item in file.AllContents) { if (item.IsShared) { continue; } PackFile pf = po.Files.AddItem(QQnPath.EnsureRelativePath(po.BaseDir, item.FullSrc)); } myOrigin.Pack = p; return(p); }
public string GetFullPath(string include) { return(Path.GetFullPath(QQnPath.Combine(ProjectPath, include))); }
public void TestCombine() { string result = QQnPath.Combine("d:\\buildenv\\project", "bin\\release\\", "file.tmp"); Assert.That(result, Is.EqualTo("d:\\buildenv\\project\\bin\\release\\file.tmp")); }
public void MakePackage() { string logFile = QQnPath.Combine(LoggerPath, "QQn.TurtleMSBuild.tbLog"); if (!File.Exists(logFile)) { BuildInternal(); } TBLogFile log = TBLogFile.Load(logFile); Assert.That(!string.IsNullOrEmpty(log.Project.Name)); DebugReference reference = null; foreach (TBLogItem item in log.Configurations[0].ProjectOutput.Items) { if (!item.IsShared && !item.IsCopy) { switch (Path.GetExtension(item.Src).ToUpperInvariant()) { case ".PDB": case ".DLL": if (reference == null) { reference = AssemblyUtils.GetDebugReference(item.FullSrc); Assert.That(reference, Is.Not.Null); Assert.That(reference.PdbFile, Is.Not.Null); } else { DebugReference dr = AssemblyUtils.GetDebugReference(item.FullSrc); Assert.That(dr, Is.Not.Null); // Path does not have to equal; the pdb information contains the sourcepath (obj directory for c# code) Assert.That(Path.GetFileName(dr.PdbFile), Is.EqualTo(Path.GetFileName(reference.PdbFile))); Assert.That(dr.DebugId, Is.EqualTo(reference.DebugId)); } break; } } } Pack pack = null; Assert.That(PackUtils.TryCreatePack(log, out pack)); string path = QQnPath.Combine(PackagePath, "QQn.TurtleMSBuild.tpZip"); TPack tp = TPack.Create(path, pack); using (TPack pkg = TPack.OpenFrom(path, VerificationMode.Full)) using (DirectoryMap dm = DirectoryMap.Get(ExtractPath)) { Assert.That(pkg, Is.Not.Null); pkg.ExtractTo(dm); } using (TPack pkg = TPack.OpenFrom(path, VerificationMode.Full)) { Assert.That(pkg, Is.Not.Null); pkg.ExtractTo(ExtractPath); } }
/// <summary> /// Tries the expand file list. /// </summary> /// <param name="fileList">The file list.</param> /// <param name="args">The args.</param> /// <returns></returns> public static bool TryExpandFileList(IList <string> fileList, FileExpandArgs args) { if (fileList == null) { throw new ArgumentNullException("fileList"); } else if (args == null) { throw new ArgumentNullException("args"); } for (int i = 0; i < fileList.Count; i++) { string word = fileList[i]; int firstMask = word.IndexOfAny(new char[] { '*', '?' }); if (firstMask >= 0) { word = word.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); DirectoryInfo rootDir; string rest = null; int lastSlash = word.LastIndexOf(Path.DirectorySeparatorChar, firstMask); if (lastSlash < 0) { rootDir = new DirectoryInfo(args.BaseDirectory); rest = word; } else { string dir = word.Substring(0, lastSlash); rootDir = new DirectoryInfo(QQnPath.Combine(args.BaseDirectory, dir)); rest = word.Substring(lastSlash + 1); } Regex fileRegex = ParseFileEx(rootDir, rest, args.FileExpandMode); bool checkAttr = !args.MatchHiddenFiles || !args.MatchSystemFiles; FileAttributes attrMask = (FileAttributes)0; if (!args.MatchHiddenFiles) { attrMask |= FileAttributes.Hidden; } if (!args.MatchSystemFiles) { attrMask |= FileAttributes.System; } SearchOption si = (args.FileExpandMode == FileExpandMode.DirectoryWildCards) ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; bool foundOne = true; SortedList <string, DirectoryInfo> visibleDirs = new SortedList <string, DirectoryInfo>(QQnPath.PathStringComparer); if (args.MatchDirectories) { foreach (DirectoryInfo fsi in rootDir.GetDirectories("*", si)) { if (fileRegex.Match(fsi.FullName).Success) { if (checkAttr && 0 != (fsi.Attributes & attrMask)) { continue; } else if (checkAttr && !DirectoryVisible(fsi, attrMask, visibleDirs)) { continue; } fileList.Insert(i++, fsi.FullName); foundOne = true; } } } if (args.MatchFiles) { foreach (FileInfo fsi in rootDir.GetFiles("*", si)) { if (fileRegex.Match(fsi.FullName).Success) { if (checkAttr && 0 != (fsi.Attributes & attrMask)) { continue; } else if (checkAttr && !DirectoryVisible(fsi, attrMask, visibleDirs)) { continue; } fileList.Insert(i++, fsi.FullName); foundOne = true; } } } if (!foundOne && !args.RemoveNonExistingFiles) { return(false); } fileList.RemoveAt(i--); } else if (args.RemoveNonExistingFiles && !(args.MatchDirectories ? Directory.Exists(word) : File.Exists(word))) { return(false); } } return(true); }
private static string GenerateAttributeAssembly(Assembly assembly, string outputDirectory) { AssemblyName srcName = new AssemblyName(assembly.FullName); if (srcName == null || string.IsNullOrEmpty(srcName.Name)) { return(null); } try { // Prepare dynamic assembly for resources AssemblyName asmName = new AssemblyName(srcName.FullName); asmName.Name = "Tmp." + srcName.Name; // Only create an on-disk assembly. We never have to execute anything AssemblyBuilder newAssembly = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.ReflectionOnly, outputDirectory); string tmpFile = srcName.Name + ".dll"; newAssembly.DefineDynamicModule(asmName.Name, tmpFile); AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(OnReflectionOnlyAssemblyResolve); try { Assembly mscorlib = Assembly.ReflectionOnlyLoad(typeof(int).Assembly.FullName); Assembly system = Assembly.ReflectionOnlyLoad(typeof(Uri).Assembly.FullName); bool hasInformationalVersion = false; bool hasVersion = false; foreach (CustomAttributeData attr in CustomAttributeData.GetCustomAttributes(assembly)) { if ((attr.NamedArguments.Count > 0) || (attr.Constructor == null)) { // We don't use named arguments at this time; not needed for the version resources continue; } Type type = attr.Constructor.ReflectedType; if (type.Assembly != mscorlib && type.Assembly != system) { continue; } if (type.Assembly == mscorlib) { switch (type.Name) { case "System.Reflection.AssemblyInformationalVersionAttribute": hasInformationalVersion = true; break; case "System.Reflection.AssemblyVersionAttribute": hasVersion = true; break; } } List <object> values = new List <object>(); foreach (CustomAttributeTypedArgument arg in attr.ConstructorArguments) { values.Add(arg.Value); } CustomAttributeBuilder cb = new CustomAttributeBuilder(attr.Constructor, values.ToArray()); newAssembly.SetCustomAttribute(cb); } if (!hasVersion) { newAssembly.SetCustomAttribute( new CustomAttributeBuilder(typeof(AssemblyVersionAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { srcName.Version.ToString() })); } if (!hasInformationalVersion) { newAssembly.SetCustomAttribute( new CustomAttributeBuilder(typeof(AssemblyInformationalVersionAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { srcName.Version.ToString() })); } newAssembly.SetCustomAttribute( new CustomAttributeBuilder(typeof(AssemblyCultureAttribute).GetConstructor(new Type[] { typeof(String) }), new object[] { "" })); } finally { AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve -= new ResolveEventHandler(OnReflectionOnlyAssemblyResolve); } newAssembly.DefineVersionInfoResource(); newAssembly.Save(tmpFile); return(QQnPath.Combine(outputDirectory, tmpFile)); } catch (FileLoadException) { return(null); } catch (IOException) { return(null); } }
private SortedFileList <ExternalProject> CreateExternalProjectsList() { SortedFileList <ExternalProject> externalProjects = new SortedFileList <ExternalProject>(); using (StreamReader sr = File.OpenText(ProjectFile)) { string line; while (null != (line = sr.ReadLine())) { if (line.StartsWith("Project(")) { IList <string> words = Tokenizer.GetCommandlineWords(line); if (words.Count < 5 || words[1] != "=") { continue; } Guid projectType = new Guid(words[0].Substring(8).TrimEnd(')').Trim('\"')); string projectName = FilterWord(words[2]); string projectFile = QQnPath.Combine(ProjectPath, FilterWord(words[3])); Guid projectGuid = new Guid(FilterWord(words[4])); if (projectType != solutionItem && File.Exists(projectFile)) { if (QQnPath.ExtensionEquals(projectFile, ".vcproj")) { externalProjects.Add(projectFile, new VCBuildProject(projectGuid, projectFile, projectName, Parameters)); } } } } } if (BuildProperties == null) { Refresh(); } // The property CurrentSolutionConfigurationContents contains the 'real' configuration of external projects string configData; if (BuildProperties.TryGetValue("CurrentSolutionConfigurationContents", out configData)) { XmlDocument doc = new XmlDocument(); doc.LoadXml(configData); foreach (ExternalProject ep in externalProjects) { XmlNode node = doc.SelectSingleNode("//ProjectConfiguration[@Project='" + ep.ProjectGuid.ToString("B").ToUpperInvariant() + "']"); if (node != null) { ep.AddBuildConfiguration(node.InnerText); } } } return(externalProjects); }