private static void CreateUnsavedFile(IUnitTestGeneratorPackage package, GenerationItem generationItem) { ThreadHelper.ThrowIfNotOnUIThread(); var tempFile = Path.Combine(Path.GetTempPath(), Path.GetFileName(generationItem.TargetFileName)); try { File.WriteAllText(tempFile, Strings.DisconnectedFileHeader + generationItem.TargetContent); var dte = (DTE2)package.GetService(typeof(DTE)); if (dte != null) { var window = dte.ItemOperations.OpenFile(tempFile, Constants.vsViewKindCode); window.Document.Saved = false; } } finally { try { File.Delete(tempFile); } catch (IOException) { } } }
public static void AddNugetPackagesToProject(Project currentProject, IList <INugetPackageReference> packagesToInstall, Action <string> logMessage, IUnitTestGeneratorPackage generatorPackage) { ThreadHelper.ThrowIfNotOnUIThread(); var installedPackages = generatorPackage.PackageInstallerServices.GetInstalledPackages(currentProject).ToList(); var installablePackages = packagesToInstall.Where(x => PackageNeedsInstalling(installedPackages, x)).ToList(); if (generatorPackage.GetService(typeof(SVsThreadedWaitDialogFactory)) is IVsThreadedWaitDialogFactory dialogFactory) { dialogFactory.CreateInstance(out var dialog); if (dialog != null) { foreach (var package in installablePackages) { var message = string.Format(CultureInfo.CurrentCulture, "Installing package '{0}'...", package.Name); dialog.StartWaitDialog("Installing NuGet packages", message, string.Empty, null, message, 0, false, true); InstallPackage(currentProject, generatorPackage, package); } dialog.EndWaitDialog(out _); return; } } foreach (var package in installablePackages) { logMessage(string.Format(CultureInfo.CurrentCulture, "Installing package '{0}'...", package.Name)); InstallPackage(currentProject, generatorPackage, package); } }