src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/SpecialFileProviders/AbstractSpecialFileProvider.cs
/// <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>
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.
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 .
private async Task<bool> IsNodeInSyncWithDiskAsync(IProjectTree specialFileNode, bool forceSync, CancellationToken cancellationToken)
        {
            if (!specialFileNode.Flags.IsIncludedInProject())
            {
                if (forceSync)
                {
                    await _sourceItemsProvider.AddAsync(specialFileNode.FilePath).ConfigureAwait(false);
                    await _projectTree.TreeService.PublishLatestTreeAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    return false;
                }
            }
            if (!_fileSystem.FileExists(specialFileNode.FilePath))
            {
                if (forceSync)
                {
                    await _projectTree.TreeProvider.RemoveAsync(ImmutableHashSet.Create(specialFileNode)).ConfigureAwait(false);
                    await _projectTree.TreeService.PublishLatestTreeAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
                }
                return false;
            }
            return true;
        }
private async Task < bool > IsNodeInSyncWithDiskAsync ( IProjectTree specialFileNode , bool forceSync , CancellationToken cancellationToken ) { if ( ! specialFileNode . Flags . IsIncludedInProject ( ) ) { if ( forceSync ) { await _sourceItemsProvider . AddAsync ( specialFileNode . FilePath ) . ConfigureAwait ( false ) ; await _projectTree . TreeService . PublishLatestTreeAsync ( cancellationToken : cancellationToken ) . ConfigureAwait ( false ) ; } else { return false ; } } if ( ! _fileSystem . FileExists ( specialFileNode . FilePath ) ) { if ( forceSync ) { await _projectTree . TreeProvider . RemoveAsync ( ImmutableHashSet . Create ( specialFileNode ) ) . ConfigureAwait ( false ) ; await _projectTree . TreeService . PublishLatestTreeAsync ( cancellationToken : cancellationToken ) . ConfigureAwait ( false ) ; } return false ; } return true ; }
Check to see if a given node is both part of a project and exists on disk.
Check to see if a given node is both part of a project and exists on disk .
// If the file exists on disk but is not part of the project. // Since the file already exists on disk, just include it in the project. // If the file was in the project but not on disk. // Just remove the entry from the project so that we get to a clean state and then we can  // create the file as usual.
specialFileNode
IProjectTree
forceSync
bool
cancellationToken
CancellationToken