Compiler Warning ASPIREFILESYSTEM001
このコンテンツはまだ日本語訳がありません。
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:
IFileSystemServiceinterfaceITempFileSystemServiceinterfaceTempDirectoryclassTempFileclass
These APIs provide a centralized way to manage temporary directories and files used by Aspire, improving testability and consistency across the platform.
Example
Section titled “Example”The following code generates ASPIREFILESYSTEM001:
var builder = DistributedApplication.CreateBuilder(args);
var fileSystemService = builder.Services .BuildServiceProvider() .GetRequiredService<IFileSystemService>();
// Create a temporary subdirectoryusing var tempDir = fileSystemService.TempDirectory.CreateTempSubdirectory("aspire");Console.WriteLine($"Temp directory: {tempDir.Path}");
// Create a temporary fileusing var tempFile = fileSystemService.TempDirectory.CreateTempFile("config.json");Console.WriteLine($"Temp file: {tempFile.Path}");Understanding the file system service
Section titled “Understanding the file system service”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
Key interfaces and classes
Section titled “Key interfaces and classes”IFileSystemService
- Main service interface providing access to temporary directory operations
- Access via
TempDirectoryproperty
ITempFileSystemService
- Provides methods for creating temporary subdirectories and files
CreateTempSubdirectory(string? prefix)— Creates a temp subdirectoryCreateTempFile(string? fileName)— Creates a temp file
TempDirectory
- Represents a temporary directory that is automatically deleted when disposed
Pathproperty provides the full path to the directory
TempFile
- Represents a temporary file that is automatically deleted when disposed
Pathproperty provides the full path to the file
To suppress this warning
Section titled “To suppress this warning”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 = noneFor more information about editor config files, see Configuration files for code analysis rules.
-
Add the following
PropertyGroupto your project file:C# project file <PropertyGroup><NoWarn>$(NoWarn);ASPIREFILESYSTEM001</NoWarn></PropertyGroup> -
Suppress in code with the
#pragma warning disable ASPIREFILESYSTEM001directive:C# — Suppressing the warning #pragma warning disable ASPIREFILESYSTEM001var fileSystemService = builder.Services.BuildServiceProvider().GetRequiredService<IFileSystemService>();#pragma warning restore ASPIREFILESYSTEM001