protected override int Execute() { var currentModuleDirectory = Helper.GetModuleDirectory(Directory.GetCurrentDirectory()); var currentModule = Path.GetFileName(currentModuleDirectory); PackageUpdater.UpdatePackages(); project = Yaml.GetProjectFileName(project, currentModule); var moduleToInsert = Helper.TryFixModuleCase(dep.Name); dep = new Dep(moduleToInsert, dep.Treeish, dep.Configuration); var configuration = dep.Configuration; if (!Helper.HasModule(moduleToInsert)) { ConsoleWriter.WriteError($"Can't find module '{moduleToInsert}'"); return(-1); } if (!Directory.Exists(Path.Combine(Helper.CurrentWorkspace, moduleToInsert))) { GetAndBuild(dep); } Log.Debug( $"{moduleToInsert + (configuration == null ? "" : Helper.ConfigurationDelimiter + configuration)} -> {project}"); CheckBranch(); Log.Info("Getting install data for " + moduleToInsert + Helper.ConfigurationDelimiter + configuration); var installData = InstallParser.Get(moduleToInsert, configuration); if (!installData.BuildFiles.Any()) { ConsoleWriter.WriteWarning($"No install files found in '{moduleToInsert}'"); return(0); } AddModuleToCsproj(installData); if (testReplaces) { return(hasReplaces ? -1 : 0); } if (!File.Exists(Path.Combine(currentModuleDirectory, Helper.YamlSpecFile))) { throw new CementException( "No module.yaml file. You should patch deps file manually or convert old spec to module.yaml (cm convert-spec)"); } DepsPatcherProject.PatchDepsForProject(currentModuleDirectory, dep, project); return(0); }
protected override int Execute() { var modulePath = Helper.GetModuleDirectory(Directory.GetCurrentDirectory()); var moduleName = Path.GetFileName(modulePath); project = Yaml.GetProjectFileName(project, moduleName); configuration = configuration ?? "full-build"; var buildData = Yaml.BuildParser(moduleName).Get(configuration).FirstOrDefault(t => !t.Target.IsFakeTarget()); var projectPath = Path.GetFullPath(project); var csproj = new ProjectFile(projectPath); var deps = new DepsParser(modulePath).Get(configuration); ConsoleWriter.WriteInfo("patching csproj"); var patchedDocument = csproj.CreateCsProjWithNugetReferences(deps.Deps, preRelease); var backupFileName = Path.Combine(Path.GetDirectoryName(projectPath) ?? "", "backup." + Path.GetFileName(projectPath)); if (File.Exists(backupFileName)) { File.Delete(backupFileName); } File.Move(projectPath, backupFileName); try { XmlDocumentHelper.Save(patchedDocument, projectPath, "\n"); var shellRunner = new ShellRunner(LogManager.GetLogger <ShellRunner>()); var cleaner = new Cleaner(shellRunner); var moduleBuilder = new ModuleBuilder(Log, buildSettings); moduleBuilder.Init(); ConsoleWriter.WriteInfo("start pack"); if (!moduleBuilder.DotnetPack(modulePath, projectPath, buildData?.Configuration ?? "Release")) { return(-1); } } finally { if (File.Exists(projectPath)) { File.Delete(projectPath); } File.Move(backupFileName, projectPath); } return(0); }