This commit is contained in:
Jasmine Woon 2024-11-12 14:37:47 -08:00
Родитель 38d14b22c5
Коммит 78df02954b
2 изменённых файлов: 6 добавлений и 25 удалений

Просмотреть файл

@ -65,7 +65,9 @@ namespace VSProjectQueryAPISample
.With(f => f.Path)),
cancellationToken);
var sourceFilePath = consoleApp1QueryResults.First().Files.First().Path;
IFileSnapshot sourceFile = consoleApp1QueryResults.First().Files.First();
var sourceFilePath = sourceFile.Path;
sb.Append(sourceFilePath + " to ");
// Query the destination project to retrieve its path.
@ -84,19 +86,8 @@ namespace VSProjectQueryAPISample
project => project.AddFileFromCopy(sourceFilePath, destinationProject),
cancellationToken);
// Query the source project to retrieve the file to be deleted.
IQueryResults<IProjectSnapshot> sourceFileQueryResults = await querySpace.QueryProjectsAsync(
project => project
.Where(project => project.Name == "ConsoleApp1")
.With(project => project.Files
.Where(file => file.Path == sourceFilePath)
.With(file => file.FileName)),
cancellationToken);
IAsyncQueryable<IFileSnapshot> file = sourceFileQueryResults.First().Files;
// Action query to delete the source file from the source project.
await file.AsUpdatable().Delete().ExecuteAsync();
await sourceFile.AsUpdatable().Delete().ExecuteAsync();
await this.Extensibility.Shell().ShowPromptAsync(sb.ToString(), PromptOptions.OK, cancellationToken);
}

Просмотреть файл

@ -268,18 +268,8 @@ var result = await querySpace.UpdateProjectsAsync(
cancellationToken);
```
Next, delete the original file by obtaining an `IAsyncQueryable<IFileSnapshot>` instance of the file and proceeding with its deletion. The `AsUpdatable()` method indicates that an action will be performed on the project system. This is followed by the `Delete()` action and its execution using `ExecuteAsync()`.
Next, delete the original file by obtaining an `FileSnapshot` instance of the file and proceeding with its deletion. The `AsUpdatable()` method indicates that an action will be performed on the project system. This is followed by the `Delete()` action and its execution using `ExecuteAsync()`.
```csharp
IQueryResults<IProjectSnapshot> sourceFileQueryResults = await querySpace.QueryProjectsAsync(
project => project
.Where(project => project.Name == "ConsoleApp1")
.With(project => project.Files
.Where(file => file.Path == sourceFilePath)
.With(file => file.FileName)),
cancellationToken);
IAsyncQueryable<IFileSnapshot> file = sourceFileQueryResults.First().Files;
await file.AsUpdatable().Delete().ExecuteAsync();
await sourceFile.AsUpdatable().Delete().ExecuteAsync();
```