private async Task AddNugetAndNpmReferences(ModuleWithMastersInfo module, string[] projectFiles, bool useDotnetCliToInstall) { var webPackagesWillBeAddedToBlazorServerProject = SouldWebPackagesBeAddedToBlazorServerProject(module, projectFiles); foreach (var nugetPackage in module.NugetPackages) { var nugetTarget = await IsProjectTiered(projectFiles) && nugetPackage.TieredTarget != NuGetPackageTarget.Undefined ? nugetPackage.TieredTarget : nugetPackage.Target; if (webPackagesWillBeAddedToBlazorServerProject && nugetTarget == NuGetPackageTarget.Web) { nugetTarget = NuGetPackageTarget.BlazorServer; } var targetProjectFile = ProjectFinder.FindNuGetTargetProjectFile(projectFiles, nugetTarget); if (targetProjectFile == null) { Logger.LogDebug($"Target project is not available for this NuGet package '{nugetPackage.Name}'"); continue; } await ProjectNugetPackageAdder.AddAsync(null, targetProjectFile, nugetPackage, null, useDotnetCliToInstall); } var mvcNpmPackages = module.NpmPackages?.Where(p => p.ApplicationType.HasFlag(NpmApplicationType.Mvc)) .ToList(); if (!mvcNpmPackages.IsNullOrEmpty()) { var targetProjects = ProjectFinder.FindNpmTargetProjectFile(projectFiles); if (targetProjects.Any()) { NpmGlobalPackagesChecker.Check(); foreach (var targetProject in targetProjects) { foreach (var npmPackage in mvcNpmPackages) { await ProjectNpmPackageAdder.AddMvcPackageAsync(Path.GetDirectoryName(targetProject), npmPackage); } } } else { Logger.LogDebug("Target project is not available for NPM packages."); } } }
public virtual async Task ExecuteAsync(CommandLineArgs commandLineArgs) { if (commandLineArgs.Target == null) { throw new CliUsageException( "Package name is missing!" + Environment.NewLine + Environment.NewLine + GetUsageInfo() ); } var isAngularPackage = false; var isNugetPackage = true; if (commandLineArgs.Target.StartsWith("@")) { isAngularPackage = true; isNugetPackage = false; } var version = commandLineArgs.Options.GetOrNull(Options.Version.Short, Options.Version.Long); var withSourceCode = commandLineArgs.Options.ContainsKey(Options.SourceCode.Long); if (isNugetPackage) { var addSourceCodeToSolutionFile = withSourceCode && commandLineArgs.Options.ContainsKey("add-to-solution-file"); await ProjectNugetPackageAdder.AddAsync( GetSolutionFile(commandLineArgs), GetProjectFile(commandLineArgs), commandLineArgs.Target, version, true, withSourceCode, addSourceCodeToSolutionFile ); } else if (isAngularPackage) { await ProjectNpmPackageAdder.AddAngularPackageAsync( GetAngularDirectory(commandLineArgs), commandLineArgs.Target, version, withSourceCode ); } }