/// <summary> /// Check to see if a given node is both part of a project and exists on disk. If asked to /// force sync, then either a file is included in the project or removed from the project. /// </summary> private async Task <bool> IsNodeInSyncWithDiskAsync(IProjectTree specialFileNode, bool forceSync, CancellationToken cancellationToken) { // If the file exists on disk but is not part of the project. if (!specialFileNode.Flags.IsIncludedInProject()) { if (forceSync) { // Since the file already exists on disk, just include it in the project. await _sourceItemsProvider.AddAsync(specialFileNode.FilePath).ConfigureAwait(false); await _projectTreeService.PublishLatestTreeAsync(cancellationToken : cancellationToken).ConfigureAwait(false); } else { return(false); } } // If the file was in the project but not on disk. if (!_fileSystem.Exists(specialFileNode.FilePath)) { if (forceSync) { // Just remove the entry from the project so that we get to a clean state and then we can // create the file as usual. await _projectTreeService.CurrentTree.TreeProvider.RemoveAsync(ImmutableHashSet.Create(specialFileNode)).ConfigureAwait(false); await _projectTreeService.PublishLatestTreeAsync(cancellationToken : cancellationToken).ConfigureAwait(false); } return(false); } return(true); }
public async Task AddFileAsync(string path) { Requires.NotNullOrEmpty(path, nameof(path)); string fullPath = _project.MakeRooted(path); await _configuredImports.Value.SourceItemsProvider.AddAsync(fullPath); await _treeService.PublishLatestTreeAsync(waitForFileSystemUpdates : false); }
public static async Task InstallTargets(EnvDTE.Project envDteProject, IProjectLockService projectLockService, UnconfiguredProject unconfiguredProject, string toolsPath) { var logger = new TraceLogger(); try { if (projectLockService == null) { throw new ArgumentNullException("projectLockService"); } if (unconfiguredProject == null) { throw new ArgumentNullException("unconfiguredProject"); } using (var access = await projectLockService.WriteLockAsync()) { var configuredProject = await unconfiguredProject.GetSuggestedConfiguredProjectAsync(); Project project = await access.GetProjectAsync(configuredProject); // If you're going to change the project in any way, // check it out from SCC first: await access.CheckoutAsync(configuredProject.UnconfiguredProject.FullPath); // install targets var installer = new InstallTargetsHelper(logger); installer.Install(project, toolsPath); // configureCallback(project); IProjectTreeService projectTreeService = configuredProject.Services.ExportProvider.GetExportedValue <IProjectTreeService>(); await projectTreeService.PublishLatestTreeAsync(); // envDteProject.Save(envDteProject.FullName); // save changes. //project.Save(project.FullPath); } } catch (AggregateException ex) { logger.LogError(ex.Message); foreach (var e in ex.InnerExceptions) { logger.LogError(e.Message); } throw; } catch (Exception e) { logger.LogError(e.Message); } }