public Task AddAsync(string projectFile, NugetPackageInfo package) { if (File.ReadAllText(projectFile).Contains($"\"{package.Name}\"")) { return(Task.CompletedTask); } using (DirectoryHelper.ChangeCurrentDirectory(Path.GetDirectoryName(projectFile))) { Logger.LogInformation($"Installing '{package.Name}' package to the project '{Path.GetFileNameWithoutExtension(projectFile)}'..."); CmdHelper.Run("dotnet", "add package " + package.Name); var moduleFiles = ModuleClassFinder.Find(projectFile, "RocketModule"); if (moduleFiles.Count == 0) { throw new CliUsageException($"Could not find a class derived from RocketModule in the project {projectFile}"); } if (moduleFiles.Count > 1) { throw new CliUsageException($"There are multiple classes derived from RocketModule in the project {projectFile}: " + moduleFiles.JoinAsString(", ")); } ModuleClassDependcyAdder.Add(moduleFiles.First(), package.ModuleClass); Logger.LogInformation("Successfully installed."); } return(Task.CompletedTask); }
public ProjectNugetPackageAdder( IJsonSerializer jsonSerializer, ProjectNpmPackageAdder npmPackageAdder, DerivedClassFinder moduleClassFinder, ModuleClassDependcyAdder moduleClassDependcyAdder, IRemoteServiceExceptionHandler remoteServiceExceptionHandler) { JsonSerializer = jsonSerializer; NpmPackageAdder = npmPackageAdder; ModuleClassFinder = moduleClassFinder; ModuleClassDependcyAdder = moduleClassDependcyAdder; RemoteServiceExceptionHandler = remoteServiceExceptionHandler; Logger = NullLogger <ProjectNugetPackageAdder> .Instance; }