public override Stream CreateFile(string fullPath, INuGetProjectContext nuGetProjectContext) { // See if there are any pending changes for this file var pendingChanges = PrivateWorkspace.GetPendingChanges(fullPath, RecursionType.None).ToArray(); var pendingDeletes = pendingChanges.Where(c => c.IsDelete).ToArray(); // We would need to pend an edit if (a) the file is pending delete (b) is bound to source control and does not already have pending edits or adds bool sourceControlBound = IsSourceControlBound(fullPath); bool requiresEdit = pendingDeletes.Any() || (!pendingChanges.Any(c => c.IsEdit || c.IsAdd) && sourceControlBound); // Undo all pending deletes if (pendingDeletes.Any()) { PrivateWorkspace.Undo(pendingDeletes); } // If the file was marked as deleted, and we undid the change or has no pending adds or edits, we need to edit it. if (requiresEdit) { // If the file exists, but there is not pending edit then edit the file (if it is under source control) requiresEdit = PrivateWorkspace.PendEdit(fullPath) > 0; } var fileStream = FileSystemUtility.CreateFile(fullPath); // If we didn't have to edit the file, this must be a new file. if (!sourceControlBound) { PrivateWorkspace.PendAdd(fullPath); } return fileStream; }
public async override Task<bool> InstallPackageAsync(Packaging.Core.PackageIdentity packageIdentity, System.IO.Stream packageStream, INuGetProjectContext nuGetProjectContext, CancellationToken token) { if (!packageStream.CanSeek) { throw new ArgumentException(NuGet.ProjectManagement.Strings.PackageStreamShouldBeSeekable); } nuGetProjectContext.Log(MessageLevel.Info, Strings.InstallingPackage, packageIdentity); packageStream.Seek(0, SeekOrigin.Begin); var zipArchive = new ZipArchive(packageStream); PackageReader packageReader = new PackageReader(zipArchive); var packageSupportedFrameworks = packageReader.GetSupportedFrameworks(); var projectFrameworks = _project.GetSupportedFrameworksAsync(token) .Result .Select(f => NuGetFramework.Parse(f.FullName)); var args = new Dictionary<string, object>(); args["Frameworks"] = projectFrameworks.Where( projectFramework => IsCompatible(projectFramework, packageSupportedFrameworks)).ToArray(); await _project.InstallPackageAsync( new NuGetPackageMoniker { Id = packageIdentity.Id, Version = packageIdentity.Version.ToNormalizedString() }, args, logger: null, progress: null, cancellationToken: token); return true; }
public NuGetProject CreateNuGetProject (DotNetProject project, INuGetProjectContext context) { Runtime.AssertMainThread (); var nugetAwareProject = project as INuGetAwareProject; if (nugetAwareProject != null) return nugetAwareProject.CreateNuGetProject (); var projectSystem = new MonoDevelopMSBuildNuGetProjectSystem (project, context); string projectJsonPath = ProjectJsonPathUtilities.GetProjectConfigPath (project.BaseDirectory, project.Name); if (File.Exists (projectJsonPath)) { return new BuildIntegratedProjectSystem ( projectJsonPath, project.FileName, project, projectSystem, project.Name, settings); } string baseDirectory = GetBaseDirectory (project); string folderNuGetProjectFullPath = PackagesFolderPathUtility.GetPackagesFolderPath (baseDirectory, settings); string packagesConfigFolderPath = project.BaseDirectory; return new MSBuildNuGetProject ( projectSystem, folderNuGetProjectFullPath, packagesConfigFolderPath); }
/// <summary> /// Creates a .refresh file in bin directory of the IFileSystem that points to the assembly being installed. /// This works around issues in DTE's AddReference method when dealing with GACed binaries. /// </summary> /// <remarks>Adds the file to the DTE project system</remarks> /// <param name="projectSystem">the web site project system where this will be added</param> /// <param name="assemblyPath">The path to the assembly being added</param> public static void CreateRefreshFile(WebSiteProjectSystem projectSystem, string assemblyPath, INuGetProjectContext nuGetProjectContext) { if (projectSystem == null) { throw new ArgumentNullException("projectSystem"); } if (assemblyPath == null) { throw new ArgumentNullException("assemblyPath"); } string refreshFilePath = CreateRefreshFilePath(projectSystem.ProjectFullPath, assemblyPath); if (!FileSystemUtility.FileExists(projectSystem.ProjectFullPath, refreshFilePath)) { try { using (var stream = CreateRefreshFileStream(projectSystem.ProjectFullPath, assemblyPath)) { // TODO: log to nuGetProjectContext? projectSystem.AddFile(refreshFilePath, stream); } } catch (UnauthorizedAccessException exception) { // log IO permission error ExceptionHelper.WriteToActivityLog(exception); } } }
/// <summary> /// Install package by Identity /// </summary> /// <param name="project"></param> /// <param name="identity"></param> /// <param name="resolutionContext"></param> /// <param name="projectContext"></param> /// <param name="isPreview"></param> /// <param name="isForce"></param> /// <param name="uninstallContext"></param> /// <returns></returns> protected async Task InstallPackageByIdentityAsync(NuGetProject project, PackageIdentity identity, ResolutionContext resolutionContext, INuGetProjectContext projectContext, bool isPreview, bool isForce = false, UninstallationContext uninstallContext = null) { List<NuGetProjectAction> actions = new List<NuGetProjectAction>(); // For Install-Package -Force if (isForce) { PackageReference installedReference = project.GetInstalledPackagesAsync(CancellationToken.None).Result.Where(p => StringComparer.OrdinalIgnoreCase.Equals(identity.Id, p.PackageIdentity.Id)).FirstOrDefault(); if (installedReference != null) { actions.AddRange(await PackageManager.PreviewUninstallPackageAsync(project, installedReference.PackageIdentity, uninstallContext, projectContext, CancellationToken.None)); } NuGetProjectAction installAction = NuGetProjectAction.CreateInstallProjectAction(identity, ActiveSourceRepository); actions.Add(installAction); } else { actions.AddRange(await PackageManager.PreviewInstallPackageAsync(project, identity, resolutionContext, projectContext, ActiveSourceRepository, null, CancellationToken.None)); } if (isPreview) { PreviewNuGetPackageActions(actions); } else { await PackageManager.ExecuteNuGetProjectActionsAsync(project, actions, this, CancellationToken.None); } }
public VsPackageInstaller(ISourceRepositoryProvider sourceRepositoryProvider, ISettings settings, ISolutionManager solutionManager, IVsPackageInstallerServices packageServices) { _sourceRepositoryProvider = sourceRepositoryProvider; _settings = settings; _solutionManager = solutionManager; _projectContext = new VSAPIProjectContext(); _packageServices = packageServices; }
public static void AddFile(string root, string path, Action<Stream> writeToStream, INuGetProjectContext nuGetProjectContext) { if (writeToStream == null) { throw new ArgumentNullException("writeToStream"); } AddFileCore(root, path, writeToStream, nuGetProjectContext); }
public static void AddFile(string root, string path, Stream stream, INuGetProjectContext nuGetProjectContext) { if (stream == null) { throw new ArgumentNullException("stream"); } AddFileCore(root, path, targetStream => stream.CopyTo(targetStream), nuGetProjectContext); }
/// <summary> /// PostProcessAsync is not run for BuildIntegratedNuGetProjects so we run it directly after /// running a NuGet action. /// </summary> public static Task RunPostProcessAsync (this NuGetProject project, INuGetProjectContext context, CancellationToken token) { var buildIntegratedProject = project as IBuildIntegratedNuGetProject; if (buildIntegratedProject != null) { return buildIntegratedProject.PostProcessAsync (context, token); } return Task.FromResult (0); }
public static bool IsPackagesFolderBoundToSourceControl(INuGetProjectContext nuGetProjectContext) { var sourceControlManager = GetSourceControlManager(nuGetProjectContext); if (sourceControlManager != null) { return sourceControlManager.IsPackagesFolderBoundToSourceControl(); } return false; }
public Task ExecuteNuGetProjectActionsAsync ( NuGetProject nuGetProject, IEnumerable<NuGetProjectAction> nuGetProjectActions, INuGetProjectContext nuGetProjectContext, CancellationToken token) { return packageManager.ExecuteNuGetProjectActionsAsync ( nuGetProject, nuGetProjectActions, nuGetProjectContext, token); }
public static SourceControlManager GetSourceControlManager(INuGetProjectContext nuGetProjectContext) { if (nuGetProjectContext != null) { var sourceControlManagerProvider = nuGetProjectContext.SourceControlManagerProvider; if (sourceControlManagerProvider != null) { return sourceControlManagerProvider.GetSourceControlManager(); } } return null; }
public InstallNuGetPackageAction ( IEnumerable<SourceRepository> primarySources, IMonoDevelopSolutionManager solutionManager, IDotNetProject dotNetProject, INuGetProjectContext projectContext) : this ( primarySources, null, solutionManager, dotNetProject, projectContext) { }
public async override Task<bool> InstallPackageAsync(PackageIdentity packageIdentity, Stream packageStream, INuGetProjectContext nuGetProjectContext, CancellationToken token) { if (packageIdentity == null) { throw new ArgumentNullException("packageIdentity"); } if (packageStream == null) { throw new ArgumentNullException("packageStream"); } if (nuGetProjectContext == null) { throw new ArgumentNullException("nuGetProjectContext"); } if (!packageStream.CanSeek) { throw new ArgumentException(Strings.PackageStreamShouldBeSeekable); } // 1. Check if the Package already exists at root, if so, return false if (PackageExists(packageIdentity)) { nuGetProjectContext.Log(MessageLevel.Warning, Strings.PackageAlreadyExistsInFolder, packageIdentity, Root); return false; } nuGetProjectContext.Log(MessageLevel.Info, Strings.AddingPackageToFolder, packageIdentity, Root); // 2. Call PackageExtractor to extract the package into the root directory of this FileSystemNuGetProject packageStream.Seek(0, SeekOrigin.Begin); var addedPackageFilesList = new List<string>(await PackageExtractor.ExtractPackageAsync(packageStream, packageIdentity, PackagePathResolver, nuGetProjectContext.PackageExtractionContext, PackageSaveMode, token)); if (PackageSaveMode.HasFlag(PackageSaveModes.Nupkg)) { var packageFilePath = GetInstalledPackageFilePath(packageIdentity); if (File.Exists(packageFilePath)) { addedPackageFilesList.Add(packageFilePath); } } // Pend all the package files including the nupkg file FileSystemUtility.PendAddFiles(addedPackageFilesList, Root, nuGetProjectContext); nuGetProjectContext.Log(MessageLevel.Info, Strings.AddedPackageToFolder, packageIdentity, Root); return true; }
public ReinstallNuGetPackageAction ( IDotNetProject project, IMonoDevelopSolutionManager solutionManager, INuGetProjectContext projectContext, IPackageManagementEvents packageManagementEvents) { this.context = projectContext; this.packageManagementEvents = packageManagementEvents; var repositories = solutionManager.CreateSourceRepositoryProvider ().GetRepositories (); installAction = CreateInstallAction (solutionManager, project, repositories); uninstallAction = CreateUninstallAction (solutionManager, project); }
public TestMSBuildNuGetProjectSystem(NuGetFramework targetFramework, INuGetProjectContext nuGetProjectContext, string projectFullPath = null, string projectName = null) { TargetFramework = targetFramework; References = new Dictionary<string, string>(); FrameworkReferences = new HashSet<string>(); Files = new HashSet<string>(); Imports = new HashSet<string>(); NuGetProjectContext = nuGetProjectContext; ProjectFullPath = String.IsNullOrEmpty(projectFullPath) ? Environment.CurrentDirectory : projectFullPath; ScriptsExecuted = new Dictionary<string, int>(); ProcessedFiles = new HashSet<string>(); ProjectName = projectName ?? TestProjectName; }
public UninstallNuGetPackageAction ( IMonoDevelopSolutionManager solutionManager, IDotNetProject dotNetProject, INuGetProjectContext projectContext, INuGetPackageManager packageManager, IPackageManagementEvents packageManagementEvents) { this.dotNetProject = dotNetProject; this.context = projectContext; this.packageManager = packageManager; this.packageManagementEvents = packageManagementEvents; project = solutionManager.GetNuGetProject (dotNetProject); }
public Task ExecuteNuGetProjectActionsAsync ( NuGetProject nuGetProject, IEnumerable<NuGetProjectAction> nuGetProjectActions, INuGetProjectContext nuGetProjectContext, CancellationToken token) { ExecutedNuGetProject = nuGetProject; ExecutedActions = nuGetProjectActions.ToList (); ExecutedProjectContext = nuGetProjectContext; ExecutedCancellationToken = token; BeforeExecuteAction (); return Task.FromResult (0); }
public static XDocument GetOrCreateDocument(XName rootName, string root, string path, INuGetProjectContext nuGetProjectContext) { if (File.Exists(Path.Combine(root, path))) { try { return GetDocument(root, path); } catch (FileNotFoundException) { return CreateDocument(rootName, root, path, nuGetProjectContext); } } return CreateDocument(rootName, root, path, nuGetProjectContext); }
private static void WriteAddedFileAndDirectory(string path, INuGetProjectContext nuGetProjectContext) { if (String.IsNullOrEmpty(path)) return; string folderPath = Path.GetDirectoryName(path); if (!String.IsNullOrEmpty(folderPath)) { nuGetProjectContext.Log(MessageLevel.Debug, Strings.Debug_AddedFileToFolder, Path.GetFileName(path), folderPath); } else { nuGetProjectContext.Log(MessageLevel.Debug, Strings.Debug_AddedFile, Path.GetFileName(path)); } }
public InstallNuGetPackageAction ( IEnumerable<SourceRepository> primarySources, IEnumerable<SourceRepository> secondarySources, IMonoDevelopSolutionManager solutionManager, IDotNetProject dotNetProject, INuGetProjectContext projectContext) : this ( primarySources, secondarySources, solutionManager, dotNetProject, projectContext, new MonoDevelopNuGetPackageManager (solutionManager), PackageManagementServices.PackageManagementEvents) { }
private static void AddFileCore(string root, string path, Action<Stream> writeToStream, INuGetProjectContext nuGetProjectContext) { if (String.IsNullOrEmpty(path) || String.IsNullOrEmpty(Path.GetFileName(path))) return; Directory.CreateDirectory(GetFullPath(root, Path.GetDirectoryName(path))); string fullPath = GetFullPath(root, path); using (Stream outputStream = CreateFile(fullPath, nuGetProjectContext)) { writeToStream(outputStream); } WriteAddedFileAndDirectory(path, nuGetProjectContext); }
public static async Task Download ( IMonoDevelopSolutionManager solutionManager, PackageIdentity packageIdentity, INuGetProjectContext context, CancellationToken token) { if (!IsMissing (solutionManager, packageIdentity)) return; await PackageDownloader.GetDownloadResourceResultAsync ( solutionManager.CreateSourceRepositoryProvider ().GetRepositories (), packageIdentity, solutionManager.Settings, new LoggerAdapter (context), token); }
public UpdateNuGetPackageAction ( IMonoDevelopSolutionManager solutionManager, IDotNetProject dotNetProject, INuGetProjectContext projectContext, INuGetPackageManager packageManager, IPackageManagementEvents packageManagementEvents) { this.dotNetProject = dotNetProject; this.context = projectContext; this.packageManager = packageManager; this.packageManagementEvents = packageManagementEvents; project = solutionManager.GetNuGetProject (dotNetProject); sourceRepositoryProvider = solutionManager.CreateSourceRepositoryProvider (); primarySources = sourceRepositoryProvider.GetRepositories ().ToList (); }
public override void PendAddFiles(IEnumerable<string> fullPaths, string root, INuGetProjectContext nuGetProjectContext) { HashSet<string> filesToAdd = new HashSet<string>(); foreach (var fullPath in fullPaths) { // TODO: Should one also add the Directory under which the file is present since it is TFS? // It would be consistent across Source Control providers to only add files to Source Control filesToAdd.Add(fullPath); filesToAdd.Add(Path.GetDirectoryName(fullPath)); } ProcessAddFiles(filesToAdd, root, nuGetProjectContext); if (filesToAdd.Any()) { PrivateWorkspace.PendAdd(filesToAdd.ToArray(), isRecursive: false); } }
public static IMSBuildNuGetProjectSystem CreateMSBuildNuGetProjectSystem(EnvDTEProject envDTEProject, INuGetProjectContext nuGetProjectContext) { if (envDTEProject == null) { throw new ArgumentNullException("project"); } if (String.IsNullOrEmpty(envDTEProject.FullName)) { throw new InvalidOperationException( String.Format(CultureInfo.CurrentCulture, Strings.DTE_ProjectUnsupported, EnvDTEProjectUtility.GetName(envDTEProject))); } #if VS14 if (EnvDTEProjectUtility.SupportsINuGetProjectSystem(envDTEProject)) { throw new InvalidOperationException("Does not support INuGetProjectSystem"); } #endif var guids = VsHierarchyUtility.GetProjectTypeGuids(envDTEProject); if (guids.Contains(NuGetVSConstants.CppProjectTypeGuid)) // Got a cpp project { if (!EnvDTEProjectUtility.IsClr(envDTEProject)) return new NativeProjectSystem(envDTEProject, nuGetProjectContext); } // Try to get a factory for the project type guid foreach (var guid in guids) { IMSBuildNuGetProjectSystemThunk factory; if (_factories.TryGetValue(guid, out factory)) { return factory(envDTEProject, nuGetProjectContext); } } // Fall back to the default if we have no special project types return new VSMSBuildNuGetProjectSystem(envDTEProject, nuGetProjectContext); }
public override async Task<bool> InstallPackageAsync ( PackageIdentity packageIdentity, DownloadResourceResult downloadResourceResult, INuGetProjectContext nuGetProjectContext, CancellationToken token) { return await Runtime.RunInMainThread (async () => { // Check if this NuGet package is already installed and should be removed. PackageReference existingPackageReference = project.FindPackageReference (packageIdentity); if (existingPackageReference != null) { if (ShouldRemoveExistingPackageReference (existingPackageReference, packageIdentity)) { project.PackageReferences.Remove (existingPackageReference); } else { nuGetProjectContext.Log ( MessageLevel.Info, GettextCatalog.GetString ("Package '{0}' already installed.", packageIdentity)); return true; } } bool developmentDependency = false; if (IsNuGetBuildPackagingPackage (packageIdentity)) { await GlobalPackagesExtractor.Extract (project.ParentSolution, packageIdentity, downloadResourceResult, token); developmentDependency = true; GenerateNuGetBuildPackagingTargets (packageIdentity); } var packageReference = new PackageReference (packageIdentity); if (developmentDependency) packageReference.PrivateAssets = "All"; project.PackageReferences.Add (packageReference); await SaveProject (); return true; }); }
public override Task PreProcessAsync(INuGetProjectContext nuGetProjectContext, CancellationToken token) { _packageUpdateState.Clear(); return(base.PreProcessAsync(nuGetProjectContext, token)); }
public override async Task <bool> InstallPackageAsync( PackageIdentity packageIdentity, DownloadResourceResult downloadResourceResult, INuGetProjectContext nuGetProjectContext, CancellationToken token) { if (downloadResourceResult == null) { throw new ArgumentNullException(nameof(downloadResourceResult)); } var packageStream = downloadResourceResult.PackageStream; if (!packageStream.CanSeek) { throw new ArgumentException(Strings.PackageStreamShouldBeSeekable); } // Uninstall the package if it is already installed. This should only happen when an // update occurred from Install-Package PMC command, the Browse tab in the UI, or the // Installed tab in the UI. An update from the Updates tab has an explicit Uninstall // action before the install. var installedPackages = await GetInstalledPackagesAsync(token); var packageToReplace = installedPackages .Where(pr => StringComparer.OrdinalIgnoreCase.Equals(pr.PackageIdentity.Id, packageIdentity.Id)) .FirstOrDefault(); if (packageToReplace != null) { await UninstallPackageAsync(packageToReplace.PackageIdentity, nuGetProjectContext, token); } nuGetProjectContext.Log(MessageLevel.Info, Strings.InstallingPackage, packageIdentity); // Get additional information from the package that the INuGetPackageManager can act on. packageStream.Seek(0, SeekOrigin.Begin); IEnumerable <NuGetFramework> supportedFrameworks; IEnumerable <PackageType> packageTypes; using (var packageReader = new PackageArchiveReader(packageStream, leaveStreamOpen: true)) { supportedFrameworks = packageReader.GetSupportedFrameworks(); packageTypes = packageReader.GetPackageTypes(); } var args = new Dictionary <string, object>(); args["Frameworks"] = supportedFrameworks .Where(f => f.IsSpecificFramework) .ToArray(); args["PackageTypes"] = packageTypes .ToArray(); object state; if (_packageUpdateState.TryGetValue(packageIdentity.Id, out state)) { args[StateKey] = state; } // Perform the actual installation by delegating to INuGetPackageManager. await _project.InstallPackageAsync( new NuGetPackageMoniker { Id = packageIdentity.Id, Version = packageIdentity.Version.ToNormalizedString() }, args, logger : null, progress : null, cancellationToken : token); return(true); }
public WixProjectSystem(IVsProjectAdapter vsProjectAdapter, INuGetProjectContext nuGetProjectContext) : base(vsProjectAdapter, nuGetProjectContext) { }
public void MarkPackageDirectoryForDeletion(PackageIdentity package, string packageDirectory, INuGetProjectContext projectContext) { }
/// <summary> /// Marks the files for deletion /// It will perform necessary operations such as undoing pending changes and so on as appropriate /// </summary> public abstract void PendDeleteFiles(IEnumerable <string> fullPaths, string root, INuGetProjectContext nuGetProjectContext);
public async Task <NuGetProject> GetOrCreateProjectAsync(EnvDTE.Project project, INuGetProjectContext projectContext) { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var projectSafeName = await project.GetCustomUniqueNameAsync(); var nuGetProject = await GetNuGetProjectAsync(projectSafeName); // if the project does not exist in the solution (this is true for new templates) // create it manually if (nuGetProject == null) { var vsProjectAdapter = await _vsProjectAdapterProvider.CreateAdapterForFullyLoadedProjectAsync(project); nuGetProject = await CreateNuGetProjectAsync(vsProjectAdapter, projectContext); } return(nuGetProject); }
protected CpsProjectSystem(IVsProjectAdapter vsProjectAdapter, INuGetProjectContext nuGetProjectContext) : base(vsProjectAdapter, nuGetProjectContext) { }
/// <summary> /// Install package by Id /// </summary> /// <param name="project"></param> /// <param name="packageId"></param> /// <param name="resolutionContext"></param> /// <param name="projectContext"></param> /// <param name="isPreview"></param> /// <param name="isForce"></param> /// <param name="uninstallContext"></param> /// <returns></returns> protected async Task InstallPackageByIdAsync(NuGetProject project, string packageId, ResolutionContext resolutionContext, INuGetProjectContext projectContext, bool isPreview) { try { var actions = await PackageManager.PreviewInstallPackageAsync(project, packageId, resolutionContext, projectContext, PrimarySourceRepositories, null, CancellationToken.None); if (!actions.Any()) { // nuget operation status is set to NoOp to log under telemetry event when // there is no preview action. _status = NuGetOperationStatus.NoOp; } else { // update packages count to be logged under telemetry event _packageCount = actions.Select( action => action.PackageIdentity.Id).Distinct(StringComparer.OrdinalIgnoreCase).Count(); } // stop telemetry event timer to avoid UI interaction TelemetryServiceUtility.StopTimer(); if (!ShouldContinueDueToDotnetDeprecation(actions, isPreview)) { // resume telemetry event timer after ui confirmation TelemetryServiceUtility.StartOrResumeTimer(); return; } // resume telemetry event timer after ui confirmation TelemetryServiceUtility.StartOrResumeTimer(); if (isPreview) { PreviewNuGetPackageActions(actions); } else { var identity = actions.Select(v => v.PackageIdentity).Where(p => p.Id.Equals(packageId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); NuGetPackageManager.SetDirectInstall(identity, projectContext); await PackageManager.ExecuteNuGetProjectActionsAsync(project, actions, this, resolutionContext.SourceCacheContext, CancellationToken.None); NuGetPackageManager.ClearDirectInstall(projectContext); // Refresh Manager UI if needed RefreshUI(actions); } } catch (InvalidOperationException ex) when(ex.InnerException is PackageAlreadyInstalledException) { // Set nuget operation status to NoOp for telemetry event when package // is already installed. _status = NuGetOperationStatus.NoOp; Log(MessageLevel.Info, ex.Message); } }
public void SetDirectInstall(PackageIdentity directInstall, INuGetProjectContext nuGetProjectContext) { SetDirectInstallPackageIdentity = directInstall; SetDirectInstallProjectContext = nuGetProjectContext; }
public void ClearDirectInstall(INuGetProjectContext nuGetProjectContext) { ClearDirectInstallProjectContext = nuGetProjectContext; }
public JsProjectSystem(EnvDTEProject envDTEProject, INuGetProjectContext nuGetProjectContext) : base(envDTEProject, nuGetProjectContext) { }
public void SetDirectInstall(PackageIdentity directInstall, INuGetProjectContext nuGetProjectContext) { NuGetPackageManager.SetDirectInstall(directInstall, nuGetProjectContext); }
public void ClearDirectInstall(INuGetProjectContext nuGetProjectContext) { NuGetPackageManager.ClearDirectInstall(nuGetProjectContext); }
public override Stream CreateFile(string fullPath, INuGetProjectContext nuGetProjectContext) { PendAddedFiles.Add(fullPath); return(FileSystemUtility.CreateFile(fullPath)); }
/// <summary> /// Creates a file, and adds it to source control. /// </summary> /// <param name="root">Root folder.</param> /// <param name="path">Relative path in the root folder.</param> /// <param name="nuGetProjectContext">the project context.</param> /// <returns>A writeable filestream.</returns> public static Stream CreateFile(string root, string path, INuGetProjectContext nuGetProjectContext) { return(CreateFile(GetFullPath(root, path), nuGetProjectContext)); }
public override Task <bool> UninstallPackageAsync(PackageIdentity packageIdentity, INuGetProjectContext nuGetProjectContext, CancellationToken token) { if (packageIdentity == null) { throw new ArgumentNullException("packageIdentity"); } if (nuGetProjectContext == null) { throw new ArgumentNullException("nuGetProjectContext"); } List <PackageReference> installedPackagesList = GetInstalledPackagesList(); var packageReference = installedPackagesList.Where(p => p.PackageIdentity.Equals(packageIdentity)).FirstOrDefault(); if (packageReference == null) { nuGetProjectContext.Log(MessageLevel.Warning, Strings.PackageDoesNotExisttInPackagesConfig, packageIdentity, Path.GetFileName(FullPath)); return(Task.FromResult(false)); } installedPackagesList.Remove(packageReference); if (installedPackagesList.Count > 0) { // Create new file or overwrite existing file using (var stream = FileSystemUtility.CreateFile(FullPath, nuGetProjectContext)) { var writer = new PackagesConfigWriter(stream); foreach (var pr in installedPackagesList) { writer.WritePackageEntry(pr); } writer.Close(); } } else { FileSystemUtility.DeleteFile(FullPath, nuGetProjectContext); } nuGetProjectContext.Log(MessageLevel.Info, Strings.RemovedPackageFromPackagesConfig, packageIdentity, Path.GetFileName(FullPath)); return(Task.FromResult(true)); }
public static void DeleteFiles(IEnumerable <ZipFilePair> packageFiles, string packagesDir, INuGetProjectContext nuGetProjectContext) { var filesToDelete = new List <string>(); foreach (var packageFile in packageFiles.Where(e => e.IsInstalled())) { if (ContentEquals(packageFile.FileFullPath, packageFile.PackageEntry.Open)) { MakeWritable(packageFile.FileFullPath); filesToDelete.Add(packageFile.FileFullPath); } else { nuGetProjectContext.Log(MessageLevel.Warning, Strings.Warning_FileModified, packageFile.FileFullPath); } } var sourceControlManager = SourceControlUtility.GetSourceControlManager(nuGetProjectContext); if (sourceControlManager != null && sourceControlManager.IsPackagesFolderBoundToSourceControl()) { sourceControlManager.PendDeleteFiles(filesToDelete, packagesDir, nuGetProjectContext); foreach (var fileToDelete in filesToDelete) { File.Delete(fileToDelete); } } else { // When it is not SourceControl, it is a different scenario altogether // First get all directories that contain files var directoryLookup = filesToDelete.ToLookup(p => Path.GetDirectoryName(p)); // Get all directories that this package may have added var directories = from grouping in directoryLookup from directory in GetDirectories(grouping.Key, altDirectorySeparator: false) orderby directory.Length descending select directory; // Remove files from every directory foreach (var directory in directories) { var directoryFiles = directoryLookup.Contains(directory) ? directoryLookup[directory] : Enumerable.Empty <string>(); var dirPath = Path.Combine(packagesDir, directory); if (!Directory.Exists(dirPath)) { continue; } foreach (var file in directoryFiles) { var path = Path.Combine(packagesDir, file); File.Delete(path); } // If the directory is empty then delete it if (!GetFiles(packagesDir, dirPath, "*.*").Any() && !GetDirectories(packagesDir, dirPath).Any()) { DeleteDirectorySafe(Path.Combine(packagesDir, dirPath), recursive: false, nuGetProjectContext: nuGetProjectContext); } } } }
private async Task <NuGetProject> CreateNuGetProjectAsync(IVsProjectAdapter project, INuGetProjectContext projectContext = null) { var context = new ProjectProviderContext( projectContext ?? EmptyNuGetProjectContext, () => PackagesFolderPathUtility.GetPackagesFolderPath(this, _settings.Value)); return(await _projectSystemFactory.TryCreateNuGetProjectAsync(project, context)); }
protected async Task <NuGetProject> CreateProjectAsync(IProjectAdapter projectAdapter, INuGetProjectContext nuGetProjectContext = null) { var context = new ProjectProviderContext( nuGetProjectContext ?? EmptyNuGetProjectContext, () => PackagesFolderPathUtility.GetPackagesFolderPath(this, NuGetSettings)); return(await _nuGetProjectFactory.TryCreateNuGetProjectAsync(projectAdapter, context)); }
/// <summary> /// CreateFile does the following /// Marks the file for edit if it already exists /// Calls File.Create which creates a file or opens it if already exists /// Marks the file for add if it was just created /// It will perform necessary operations such as undoing pending changes and so on as appropriate /// </summary> /// <param name="fullPath"></param> /// <param name="nuGetProjectContext"></param> /// <returns></returns> public abstract Stream CreateFile(string fullPath, INuGetProjectContext nuGetProjectContext);
public static void DeleteDirectorySafe(string fullPath, bool recursive, INuGetProjectContext nuGetProjectContext) { DoSafeAction(() => DeleteDirectory(fullPath, recursive, nuGetProjectContext), nuGetProjectContext); }
public void DeleteMarkedPackageDirectories(INuGetProjectContext projectContext) { }
internal static void DeleteFileSafe(string fullPath, INuGetProjectContext nuGetProjectContext) { DoSafeAction(() => DeleteFile(fullPath, nuGetProjectContext), nuGetProjectContext); }
public NuGetProject CreateNuGetProject(IDotNetProject project, INuGetProjectContext context) { return(CreateNuGetProject(project.DotNetProject, context)); }
public static void AddFile(string root, string path, Action <Stream> writeToStream, INuGetProjectContext nuGetProjectContext) { if (writeToStream == null) { throw new ArgumentNullException("writeToStream"); } AddFileCore(root, path, writeToStream, nuGetProjectContext); }
public override Task <bool> InstallPackageAsync(string packageId, VersionRange range, INuGetProjectContext nuGetProjectContext, BuildIntegratedInstallationContext installationContext, CancellationToken token) { throw new NotImplementedException(); }
private static void AddFileCore(string root, string path, Action <Stream> writeToStream, INuGetProjectContext nuGetProjectContext) { if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(Path.GetFileName(path))) { return; } Directory.CreateDirectory(GetFullPath(root, Path.GetDirectoryName(path))); var fullPath = GetFullPath(root, path); using (var outputStream = CreateFile(fullPath, nuGetProjectContext)) { writeToStream(outputStream); } WriteAddedFileAndDirectory(path, nuGetProjectContext); }
public NuGetProject CreateNuGetProject (IDotNetProject project, INuGetProjectContext context) { return CreateNuGetProject (project.DotNetProject, context); }
/// <summary> /// Uninstall package by Id /// </summary> /// <param name="project"></param> /// <param name="packageId"></param> /// <param name="uninstallContext"></param> /// <param name="projectContext"></param> /// <param name="isPreview"></param> /// <returns></returns> protected async Task UninstallPackageByIdAsync(NuGetProject project, string packageId, UninstallationContext uninstallContext, INuGetProjectContext projectContext, bool isPreview) { if (isPreview) { IEnumerable <NuGetProjectAction> actions = await PackageManager.PreviewUninstallPackageAsync(project, packageId, uninstallContext, projectContext, CancellationToken.None); PreviewNuGetPackageActions(actions); } else { await PackageManager.UninstallPackageAsync(project, packageId, uninstallContext, projectContext, CancellationToken.None); } }
public static void DeleteFileAndParentDirectoriesIfEmpty(string root, string filePath, INuGetProjectContext nuGetProjectContext) { var fullPath = GetFullPath(root, filePath); // first delete the file itself DeleteFileSafe(fullPath, nuGetProjectContext); if (!string.IsNullOrEmpty(filePath)) { // now delete all parent directories if they are empty for (var path = Path.GetDirectoryName(filePath); !string.IsNullOrEmpty(path); path = Path.GetDirectoryName(path)) { if (GetFiles(root, path, "*.*").Any() || GetDirectories(root, path).Any()) { // if this directory is not empty, stop break; } // otherwise, delete it, and move up to its parent DeleteDirectorySafe(fullPath, false, nuGetProjectContext); } } }
protected CpsProjectSystem(EnvDTEProject envDTEProject, INuGetProjectContext nuGetProjectContext) : base(envDTEProject, nuGetProjectContext) { }
private MSBuildProjectSystem GetMSBuildProject(string packageReferenceFilePath, INuGetProjectContext projectContext) { // Try to locate the project file associated with this packages.config file var directory = Path.GetDirectoryName(packageReferenceFilePath); var projectFiles = ProjectHelper.GetProjectFiles(directory).Take(2).ToArray(); if (projectFiles.Length == 0) { throw new CommandException(LocalizedResourceManager.GetString("UnableToLocateProjectFile"), packageReferenceFilePath); } if (projectFiles.Length > 1) { throw new CommandException(LocalizedResourceManager.GetString("MultipleProjectFilesFound"), packageReferenceFilePath); } return(new MSBuildProjectSystem(_msbuildDirectory, projectFiles[0], projectContext)); }
public Task RestoreMissingPackagesAsync ( INuGetAwareProject project, INuGetProjectContext context, CancellationToken token) { return project.RestorePackagesAsync (solutionManager, context, token); }