Lewati ke konten

Compiler Warning ASPIREFILESYSTEM001

Konten ini belum tersedia dalam bahasa Anda.

Version introduced: 13.1

File system service types and members are for evaluation purposes only and are subject to change or removal in future updates. Suppress this diagnostic to proceed.

This diagnostic warning is reported when using experimental file system service APIs in Aspire, including:

  • IFileSystemService interface
  • ITempFileSystemService interface
  • TempDirectory class
  • TempFile class

These APIs provide a centralized way to manage temporary directories and files used by Aspire, improving testability and consistency across the platform.

The following code generates ASPIREFILESYSTEM001:

C# — Using IFileSystemService
var builder = DistributedApplication.CreateBuilder(args);
var fileSystemService = builder.Services
.BuildServiceProvider()
.GetRequiredService<IFileSystemService>();
// Create a temporary subdirectory
using var tempDir = fileSystemService.TempDirectory.CreateTempSubdirectory("aspire");
Console.WriteLine($"Temp directory: {tempDir.Path}");
// Create a temporary file
using var tempFile = fileSystemService.TempDirectory.CreateTempFile("config.json");
Console.WriteLine($"Temp file: {tempFile.Path}");

The IFileSystemService provides a standardized interface for managing temporary files and directories in Aspire. This abstraction enables:

  • Consistent temp file management — Centralized handling of temporary resources
  • Automatic cleanup — Disposable patterns ensure resources are cleaned up properly
  • Testability — Easier to mock and test file system operations
  • Named files — Ability to create temp files with specific names

IFileSystemService

  • Main service interface providing access to temporary directory operations
  • Access via TempDirectory property

ITempFileSystemService

  • Provides methods for creating temporary subdirectories and files
  • CreateTempSubdirectory(string? prefix) — Creates a temp subdirectory
  • CreateTempFile(string? fileName) — Creates a temp file

TempDirectory

  • Represents a temporary directory that is automatically deleted when disposed
  • Path property provides the full path to the directory

TempFile

  • Represents a temporary file that is automatically deleted when disposed
  • Path property provides the full path to the file

Suppress the warning with either of the following methods:

  • Set the severity of the rule in the .editorconfig file.

    .editorconfig
    [*.{cs,vb}]
    dotnet_diagnostic.ASPIREFILESYSTEM001.severity = none

    For more information about editor config files, see Configuration files for code analysis rules.

  • Add the following PropertyGroup to your project file:

    C# project file
    <PropertyGroup>
    <NoWarn>$(NoWarn);ASPIREFILESYSTEM001</NoWarn>
    </PropertyGroup>
  • Suppress in code with the #pragma warning disable ASPIREFILESYSTEM001 directive:

    C# — Suppressing the warning
    #pragma warning disable ASPIREFILESYSTEM001
    var fileSystemService = builder.Services
    .BuildServiceProvider()
    .GetRequiredService<IFileSystemService>();
    #pragma warning restore ASPIREFILESYSTEM001
Tanya & JawabKolaborasiKomunitasDiskusiTonton