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, "AbpModule"); if (moduleFiles.Count == 0) { throw new CliUsageException($"Could not find a class derived from AbpModule in the project {projectFile}"); } if (moduleFiles.Count > 1) { throw new CliUsageException($"There are multiple classes derived from AbpModule in the project {projectFile}: " + moduleFiles.JoinAsString(", ")); } ModuleClassDependcyAdder.Add(moduleFiles.First(), package.ModuleClass); Logger.LogInformation("Successfully installed."); } return(Task.CompletedTask); }
public async Task AddAsync(string projectFile, NugetPackageInfo package) { using (DirectoryHelper.ChangeCurrentDirectory(Path.GetDirectoryName(projectFile))) { Logger.LogInformation($"Installing '{package.Name}' package to the project '{Path.GetFileNameWithoutExtension(projectFile)}'..."); var procStartInfo = new ProcessStartInfo("dotnet", "add package " + package.Name); Process.Start(procStartInfo).WaitForExit(); var moduleFiles = ModuleClassFinder.Find(projectFile); if (moduleFiles.Count == 0) { throw new CliUsageException($"Could not find a class derived from AbpModule in the project {projectFile}"); } if (moduleFiles.Count > 1) { throw new CliUsageException($"There are multiple classes derived from AbpModule in the project {projectFile}: " + moduleFiles.JoinAsString(", ")); } ModuleClassDependcyAdder.Add(moduleFiles.First(), package.ModuleClass); if (package.DependedNpmPackage != null) { await NpmPackageAdder.AddAsync(Path.GetDirectoryName(projectFile), package.DependedNpmPackage); } Logger.LogInformation("Successfully installed."); } }
protected virtual async Task AddAsPackageReference(string projectFile, NugetPackageInfo package, string version, bool useDotnetCliToInstall) { var projectFileContent = File.ReadAllText(projectFile); if (projectFileContent.Contains($"\"{package.Name}\"")) { return; } using (DirectoryHelper.ChangeCurrentDirectory(Path.GetDirectoryName(projectFile))) { Logger.LogInformation( $"Installing '{package.Name}' package to the project '{Path.GetFileNameWithoutExtension(projectFile)}'..."); if (useDotnetCliToInstall) { AddUsingDotnetCli(package, version); } else { AddToCsprojManuallyAsync(projectFile, package, version); } var moduleFiles = ModuleClassFinder.Find(projectFile, "AbpModule"); if (moduleFiles.Count == 0) { throw new CliUsageException( $"Could not find a class derived from AbpModule in the project {projectFile}"); } if (moduleFiles.Count > 1) { throw new CliUsageException( $"There are multiple classes derived from AbpModule in the project {projectFile}: " + moduleFiles.JoinAsString(", ")); } ModuleClassDependcyAdder.Add(moduleFiles.First(), package.ModuleClass); } if (useDotnetCliToInstall && (package.Target == NuGetPackageTarget.Blazor || package.Target == NuGetPackageTarget.BlazorServer || package.Target == NuGetPackageTarget.BlazorWebAssembly)) { try { await RunBundleForBlazorAsync(projectFile); } catch (Exception e) { Logger.LogWarning("Couldn't run bundle for blazor."); } } Logger.LogInformation("Successfully installed."); }
public Task AddAsync(string projectFile, NugetPackageInfo package, string version = null, bool useDotnetCliToInstall = true) { var projectFileContent = File.ReadAllText(projectFile); if (projectFileContent.Contains($"\"{package.Name}\"")) { return(Task.CompletedTask); } if (version == null) { version = GetAbpVersionOrNull(projectFileContent); } using (DirectoryHelper.ChangeCurrentDirectory(Path.GetDirectoryName(projectFile))) { Logger.LogInformation( $"Installing '{package.Name}' package to the project '{Path.GetFileNameWithoutExtension(projectFile)}'..."); if (useDotnetCliToInstall) { AddUsingDotnetCli(package, version); } else { AddToCsprojManuallyAsync(projectFile, package, version); } var moduleFiles = ModuleClassFinder.Find(projectFile, "AbpModule"); if (moduleFiles.Count == 0) { throw new CliUsageException( $"Could not find a class derived from AbpModule in the project {projectFile}"); } if (moduleFiles.Count > 1) { throw new CliUsageException( $"There are multiple classes derived from AbpModule in the project {projectFile}: " + moduleFiles.JoinAsString(", ")); } ModuleClassDependcyAdder.Add(moduleFiles.First(), package.ModuleClass); Logger.LogInformation("Successfully installed."); } return(Task.CompletedTask); }