XFiler.FileOperations.Windows
10.0.1
dotnet add package XFiler.FileOperations.Windows --version 10.0.1
NuGet\Install-Package XFiler.FileOperations.Windows -Version 10.0.1
<PackageReference Include="XFiler.FileOperations.Windows" Version="10.0.1" />
<PackageVersion Include="XFiler.FileOperations.Windows" Version="10.0.1" />
<PackageReference Include="XFiler.FileOperations.Windows" />
paket add XFiler.FileOperations.Windows --version 10.0.1
#r "nuget: XFiler.FileOperations.Windows, 10.0.1"
#:package XFiler.FileOperations.Windows@10.0.1
#addin nuget:?package=XFiler.FileOperations.Windows&version=10.0.1
#tool nuget:?package=XFiler.FileOperations.Windows&version=10.0.1
FileOperations
Platform-native file operations for .NET 10 desktop apps: move to Recycle Bin / Trash, well-known user folders, logical drives and drive mount notifications — behind one set of interfaces for Windows and macOS. Used by the X-Filer file manager.
| Package | Target | Version | Downloads |
|---|---|---|---|
| XFiler.FileOperations.Abstractions | net10.0 |
||
| XFiler.FileOperations.Windows | net10.0-windows |
||
| XFiler.FileOperations.Mac | net10.0-macos |
||
| Egorozh.Windows.ImageOperations | net10.0-windows |
What is inside
| Interface (Abstractions) | Windows | macOS |
|---|---|---|
IFileOperations — delete a file or folder permanently or to the Recycle Bin / Trash, list logical drives |
WindowsFileOperations (Shell SHFileOperation) |
MacOsFileOperations (NSFileManager.TrashItem, mounted volumes) |
IPlatformFolders — app data, Desktop, Downloads, Documents, Movies, Music, Pictures |
WindowsPlatformFolders |
MacOsPlatformFolders |
IDriveDetector — DriveChanged event when a drive is added or removed |
WindowsDriveDetector (WMI Win32_VolumeChangeEvent) |
MacOsDriveDetector (NSWorkspace mount/unmount notifications; IDisposable) |
WindowsFileOperations also has static helpers that go through the Windows Shell with its own progress
and confirmation UI: CopyFile/CopyFiles/CopyDirectory, MoveFile/MoveFiles/MoveDirectory,
DeleteFile/DeleteFiles/DeleteDirectory and Rename*.
Egorozh.Windows.ImageOperations extracts the Shell icon of a file (ImageSystem.GetIcon,
ImageSystem.GetIconStream).
Install
Reference the abstractions from shared code and the platform package from the app head:
<ItemGroup>
<PackageReference Include="XFiler.FileOperations.Abstractions" Version="10.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net10.0-windows'">
<PackageReference Include="XFiler.FileOperations.Windows" Version="10.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net10.0-macos'">
<PackageReference Include="XFiler.FileOperations.Mac" Version="10.0.0" />
</ItemGroup>
The Windows package targets net10.0-windows, so a plain net10.0 project cannot reference it — the
Windows head of the app has to target net10.0-windows too. The Mac package needs the macos workload
(dotnet workload install macos).
Usage
using FileOperations.Abstractions;
using FileOperations.Abstractions.Enums;
#if MACOS
using FileOperations.MacOs;
#else
using FileOperations.Windows;
#endif
#if MACOS
IFileOperations fileOperations = new MacOsFileOperations();
IPlatformFolders folders = new MacOsPlatformFolders();
#else
IFileOperations fileOperations = new WindowsFileOperations();
IPlatformFolders folders = new WindowsPlatformFolders();
#endif
// Recycle Bin on Windows, Trash on macOS; throws if the item cannot be moved there.
fileOperations.DeleteFile(path, RecycleOption.SendToRecycleBin);
fileOperations.DeleteDirectory(folder, DeleteDirectoryOption.DeleteAllContents, RecycleOption.SendToRecycleBin);
string settingsFolder = Path.Combine(folders.GetAppDataPath(), "MyApp");
Watch for drives being plugged in or ejected:
#if MACOS
IDriveDetector detector = new MacOsDriveDetector();
#else
IDriveDetector detector = new WindowsDriveDetector();
#endif
detector.DriveChanged += (type, drive) => Console.WriteLine($"{type}: {drive}");
All packages are marked AOT-compatible.
Build
cd src
dotnet build FileOperations.sln
EnableWindowsTargeting is on, so the Windows projects also build on macOS and Linux (they only run on
Windows). Building the Mac project needs macOS with Xcode and the macos workload.
Release
CI (.github/workflows/ci.yml) builds and packs the Windows packages on a Windows runner and the Mac
package on a macOS runner, on every push and pull request to main. Pushing a v* tag publishes all
packages to NuGet.org with the version taken from the tag (v10.0.1 → 10.0.1) through NuGet
Trusted Publishing — no API key: a nuget.org trusted publishing policy for this repository and
ci.yml, and the NUGET_USER repository secret (nuget.org profile name of the policy's creator).
git tag v10.0.1
git push origin v10.0.1
Changelog
10.0.0
- Targets .NET 10:
net10.0(Abstractions),net10.0-windows(Windows, ImageOperations),net10.0-macos(Mac). - macOS: moving to Trash throws an
IOExceptionwhen it fails instead of silently doing nothing. - macOS:
MacOsDriveDetectorreports mounted and unmounted volumes (it was an empty stub).
8.0.0 — first release, .NET 8.
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0-windows7.0 is compatible. |
-
net10.0-windows7.0
- System.Management (>= 10.0.13)
- XFiler.FileOperations.Abstractions (>= 10.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.