/// <summary> /// Создаёт папку Release. /// </summary> /// <param name="dir"></param> public DirectoryInfo CreateReleaseDirectory(DirectoryInfo dir, bool confirmIfExists) { if (dir == null) { throw new ArgumentNullException(nameof(dir)); } DirectoryInfo releaseDirectory = new DirectoryInfo(Path.Combine(dir.FullName, "R - " + this.FolderModuleName)); if (!releaseDirectory.Exists) { releaseDirectory.Create(); } else if (confirmIfExists) { if (!WSSDeveloperPackage.ShowUserConfirmYesNo($"Папка\n{releaseDirectory.FullName}\nуже существует. Заменить?", $"Папка {releaseDirectory.Name} уже существует")) { return(null); } } foreach (ProjectItem item in this.ReleaseFolder.ProjectItems) { string sourcePath = item.GetFullPath(); string targetPath = Path.Combine(releaseDirectory.FullName, item.Name); this.CopyAndOverwrite(sourcePath, targetPath); } if (this.DeployFolder != null) { this.EnsureFile(this.DeployFolder, releaseDirectory, "uninstall.bat", Constants.UninstallBatContent, Encoding.ASCII); this.EnsureFile(this.DeployFolder, releaseDirectory, "setup.bat", Constants.SetupBatContent, Encoding.ASCII); } return(releaseDirectory); }
/// <summary> /// Создаёт папку Sources. /// </summary> /// <param name="dir"></param> public void CreateSourcesDirectory(DirectoryInfo dir, bool confirmIfExists) { if (dir == null) { throw new ArgumentNullException(nameof(dir)); } DirectoryInfo sourcesDirectory = new DirectoryInfo(Path.Combine(dir.FullName, "S - " + this.FolderModuleName)); if (!sourcesDirectory.Exists) { sourcesDirectory.Create(); } else { if (confirmIfExists) { if (!WSSDeveloperPackage.ShowUserConfirmYesNo($"Папка\n{sourcesDirectory.FullName}\nуже существует. Заменить?", $"Папка {sourcesDirectory.Name} уже существует")) { return; } } } string zipFilePath = Path.Combine(sourcesDirectory.FullName, this.FileModuleName + ".zip"); this.DeleteFile(zipFilePath); DirectoryInfo projectDir = new DirectoryInfo(this.Project.GetProjectFolder()); try { ZipFile.CreateFromDirectory(projectDir.FullName, zipFilePath, CompressionLevel.Optimal, true, Encoding.UTF8); } catch (Exception ex) { Debug.WriteLine("Не удалось сформировать S архив: " + ex); // Удаляем возможно частично сформированный архив this.DeleteFile(zipFilePath); //копируем в %temp% и формируем архив оттуда this.CreateZipFromTempCopy(projectDir, zipFilePath); } }
/// <summary> /// Срабатывает при выполнении команды. /// </summary> protected override void OnExecute() { ThreadHelper.ThrowIfNotOnUIThread(); var copiedFiles = new List <string>(); //копируем из папки с результатами билда все файлы, которые есть в папке Release string outputPath = this.DTEInfo.SelectedProject.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath")?.Value?.ToString() ?? "bin"; foreach (ProjectItem releaseFile in this.Release.ProjectItems.OfType <ProjectItem>()) { _CopyFile(outputPath, releaseFile.Name, releaseFile); } // Копирум WSP, если есть _CopyFile("Deploy", this.WSPFileName, this.Release.GetChildItem(this.WSPFileName)); // Пишем, какие файлы были скопированы if (copiedFiles.Count > 0) { this.WriteToOutput("\nСледующие файлы были скопированы в Release:\n\t" + String.Join("\n\t", copiedFiles.ToArray())); } else { this.WriteToOutput("Ни один файл не был скопирован в Release."); } // Выполняет копирование файла. void _CopyFile(string dir, string name, ProjectItem projItem) { FileInfo sourceFile = this.GetFile(dir, name, SearchOption.TopDirectoryOnly); if (sourceFile != null) { if (String.Equals(sourceFile.Extension, ".config", StringComparison.InvariantCultureIgnoreCase)) { if (!WSSDeveloperPackage.ShowUserConfirmYesNo($"Заменить файл {name} в папке Release?", "Замена файла")) { return; } } this.AddOrReplaceFile(sourceFile, projItem); copiedFiles.Add($"{name} из [{dir?.Trim('\\')}]"); } } }