public override object[] Build() { List <object> items = new List <object>(); // create custom acton Wix.CustomAction action = new Wix.CustomAction(); action.Id = Common.GetId(); action.Directory = "INSTALLDIR"; if (SourcePath.Contains(":")) { action.ExeCommand = SourcePath + " " + Function; // EXE IN TARGET SYSTEM } else { action.ExeCommand = "[SystemFolder]" + SourcePath + " " + Function; // EXE IN TARGET SYSTEM } items.Add(action); // create install execute sequence Wix.InstallExecuteSequence executeSequence = new Wix.InstallExecuteSequence(); executeSequence.ItemsElementName = new Wix.ItemsChoiceType2[] { Wix.ItemsChoiceType2.Custom }; Wix.Custom custom = new Wix.Custom(); custom.Action = action.Id; base.SetExecutionSequence(custom); base.SetExecuteType(custom); executeSequence.Items = new object[] { custom }; items.Add(executeSequence); return(items.ToArray()); }
public PackageItem(ITaskItem item) { OriginalItem = item; SourcePath = item.GetMetadata("FullPath"); SourceProject = GetMetadata("MSBuildSourceProjectFile"); string value = GetMetadata("TargetFramework"); if (!String.IsNullOrWhiteSpace(value)) { TargetFramework = NuGetFramework.Parse(value); } TargetPath = item.GetMetadata(nameof(TargetPath)); AdditionalProperties = GetMetadata(nameof(AdditionalProperties)); UndefineProperties = GetMetadata(nameof(UndefineProperties)); HarvestedFrom = GetMetadata(nameof(HarvestedFrom)); Package = GetMetadata("PackageId"); PackageVersion = GetMetadata("PackageVersion"); IsDll = Path.GetExtension(SourcePath).Equals(".dll", StringComparison.OrdinalIgnoreCase); IsPlaceholder = NuGetAssetResolver.IsPlaceholder(SourcePath); IsRef = TargetPath.StartsWith("ref/", StringComparison.OrdinalIgnoreCase); // determine if we need to append filename to TargetPath // see https://docs.nuget.org/create/nuspec-reference#specifying-files-to-include-in-the-package // SourcePath specifies file and target specifies file - do nothing // SourcePath specifies file and Target specifies directory - copy filename // SourcePath specifies wildcard files - copy wildcard // SourcePath specifies recursive wildcard - do not allow, recursive directory may impact asset selection // we don't want to attempt to expand the wildcard since the build may not yet be complete. if (SourcePath.Contains("**")) { throw new ArgumentException($"Recursive wildcards \"**\" are not permitted in source paths for packages: {SourcePath}. Recursive directory may impact asset selection and we don't want to attempt to expand the wildcard since the build may not yet be complete."); } string sourceFile = Path.GetFileName(SourcePath); if (!Path.GetExtension(TargetPath).Equals(Path.GetExtension(sourceFile), StringComparison.OrdinalIgnoreCase) || sourceFile.Contains("*")) { TargetPath = Path.Combine(TargetPath, sourceFile); } // standardize to / TargetPath = TargetPath.Replace('\\', '/'); int dirLength = TargetPath.LastIndexOf('/'); TargetDirectory = (dirLength > 0) ? TargetPath.Substring(0, dirLength) : String.Empty; }
public static IEnumerable <RouteResultEventArgs> Route(string path) { var routeResults = new List <RouteResultEventArgs>(); var Configurarions = JsonSerializer.Deserialize <Configurations>(File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configurations.json"))); if ((!string.IsNullOrEmpty(Configurarions.TeraCopyPath)) && (!File.Exists(Path.Combine(Configurarions.TeraCopyPath)))) { routeResults.Add(new RouteResultEventArgs() { Color = ConsoleColor.Red, Message = $"TeraCopy not found: {Configurarions.TeraCopyPath}" }); return(routeResults); } bool IsFile = File.Exists(path); string ParentFolder = new DirectoryInfo(path).Parent.FullName.TrimEnd(Path.AltDirectorySeparatorChar); IEnumerable <string> SourcesDirectories = Configurarions.SourcesDirectories .Select(a => a.TrimEnd(Path.AltDirectorySeparatorChar)); if (SourcesDirectories.Contains(ParentFolder)) { if (IsFile || (Directory.Exists(path))) { List <string> FileEntries = new List <string>(); if (IsFile) { if (Configurarions.FilesFilter .Any(a => a.Equals(Path.GetExtension(path), StringComparison.OrdinalIgnoreCase))) { FileEntries.Add(path); } } else { foreach (var filter in Configurarions.FilesFilter) { FileEntries.AddRange(Directory.GetFiles(path, $"*{filter}", SearchOption.TopDirectoryOnly)); } } if (FileEntries.Count > 0) { foreach (string SourcePath in FileEntries) { routeResults.Add(new RouteResultEventArgs() { Message = $"Source: {SourcePath}" }); try { DestinationMapping DestinationMapping = null; if (IsFile) { string FileName = Path.GetFileName(SourcePath); foreach (var mapping in Configurarions.DestinationMappings .Where(a => !string.IsNullOrEmpty(a.NameFilter))) { if (FileName.Contains(mapping.NameFilter)) { DestinationMapping = mapping; break; } } } else { DestinationMapping = Configurarions.DestinationMappings .Where(a => !string.IsNullOrEmpty(a.PathFilter)) .SingleOrDefault(a => SourcePath.Contains(a.PathFilter)); } if (DestinationMapping != null) //Found mapping { string parameters; string Filename = Path.GetFileName(SourcePath); for (int I = 0; I <= DestinationMapping.DestinationDirectories.Count - 1; I++) { string DestinationPath = Path.Combine(DestinationMapping.DestinationDirectories[I], Filename); routeResults.Add(new RouteResultEventArgs() { Color = ConsoleColor.Blue, Message = $"Destination: {DestinationPath}" }); if (!string.IsNullOrEmpty(Configurarions.TeraCopyPath)) { parameters = string.Format("Copy \"{0}\" \"{1}\"", SourcePath, DestinationMapping.DestinationDirectories[I]); System.Diagnostics.Process.Start(Configurarions.TeraCopyPath, parameters); //Wait for teracopy to open, so it includes the next file in the same window System.Threading.Thread.Sleep(5000); } else { File.Copy(SourcePath, DestinationPath); } } } else { routeResults.Add(new RouteResultEventArgs() { Color = ConsoleColor.Yellow, Message = "No mapping defined for the directory" }); } } catch { routeResults.Add(new RouteResultEventArgs() { Color = ConsoleColor.Red, Message = "Error while moving files" }); } } } else { routeResults.Add(new RouteResultEventArgs() { Color = ConsoleColor.Yellow, Message = $"No files to copy: {path}. Filter: {string.Join(";", Configurarions.FilesFilter)}" }); } } else { routeResults.Add(new RouteResultEventArgs() { Color = ConsoleColor.Red, Message = $"Directory does not exists: {path}" }); } } else { routeResults.Add(new RouteResultEventArgs() { Message = $"Directory not mapped: {ParentFolder}" }); } return(routeResults); }