ForceOps.Lib 1.3.1

dotnet add package ForceOps.Lib --version 1.3.1
NuGet\Install-Package ForceOps.Lib -Version 1.3.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ForceOps.Lib" Version="1.3.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ForceOps.Lib --version 1.3.1
#r "nuget: ForceOps.Lib, 1.3.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ForceOps.Lib as a Cake Addin
#addin nuget:?package=ForceOps.Lib&version=1.3.1

// Install ForceOps.Lib as a Cake Tool
#tool nuget:?package=ForceOps.Lib&version=1.3.1

ForceOps

main build Nuget

Forcefully perform file operations by terminating processes that are using the file or directory.

Only supports windows, and not planned to support linux.

Uses LockCheck to find processes locking files, and will elevate itself if it the process is owned by another user.

See Benchmarks on github pages.

Refer also to 10.4 Example: file deletion in Windows from "A Philosophy of Software Design", which explains why this is a windows specific problem. Linux does not prevent the user from deleting a file if it is being used, see unlink:

If the name was the last link to a file but any processes still have the file open, the file will remain in existence until the last file descriptor referring to it is closed.

Examples

Deleting when a process owned by the current user is using it

❯ forceops rm .\bin\
[14:55:33 INF] Could not delete file "C:\Users\user\myprogram\bin\Debug\net6\myprogram.dll". Beginning retry 1/5 in 500ms. ForceOps process is not elevated. Found 1 process to try to kill: [100724 - myprogram.exe].
[14:55:34 INF] Could not delete file "C:\Users\user\myprogram\bin\Debug\net6\myprogram.dll". Beginning retry 2/5 in 500ms. ForceOps process is not elevated. Found 0 processes to try to kill: [].

Deleting when a process owned by another user is using it (e.g. a windows service)

❯ forceops rm .\bin\Debug\net6\myprogram.exe
[15:07:34 INF] Could not delete file "C:\Users\user\myprogram\bin\Debug\net6\myprogram.exe". Beginning retry 1/5 in 500ms. ForceOps process is not elevated. Found 1 process to try to kill: [115744 - ].
[15:07:34 WRN] Failed to kill process 115744: Access is denied.
[15:07:35 INF] Could not delete file "C:\Users\user\myprogram\bin\Debug\net6\myprogram.exe". Beginning retry 2/5 in 500ms. ForceOps process is not elevated. Found 1 process to try to kill: [115744 - ].
[15:07:35 WRN] Failed to kill process 115744: Access is denied.
[15:07:36 INF] Could not delete file "C:\Users\user\myprogram\bin\Debug\net6\myprogram.exe". Beginning retry 3/5 in 500ms. ForceOps process is not elevated. Found 1 process to try to kill: [115744 - ].
[15:07:37 WRN] Failed to kill process 115744: Access is denied.
[15:07:37 INF] Could not delete file "C:\Users\user\myprogram\bin\Debug\net6\myprogram.exe". Beginning retry 4/5 in 500ms. ForceOps process is not elevated. Found 1 process to try to kill: [115744 - ].
[15:07:38 WRN] Failed to kill process 115744: Access is denied.
[15:07:38 INF] Could not delete file "C:\Users\user\myprogram\bin\Debug\net6\myprogram.exe". Beginning retry 5/5 in 500ms. ForceOps process is not elevated. Found 1 process to try to kill: [115744 - ].
[15:07:39 WRN] Failed to kill process 115744: Access is denied.
[15:07:39 INF] Exceeded retry count of 5. Failed. ForceOps process is not elevated.
[15:07:39 INF] Unable to perform operation as an unelevated process. Retrying as elevated and logging to "C:\Users\user\AppData\Local\Temp\tmp9C14.tmp".
[15:07:42 INF] Successfully deleted as admin

Supported operations

Currently, only delete is supported.

Operations like move and copy can have similar issues if they are overriding files or the source file is in use. It would be reasonable to support these operations in a similar way.

For copying, consider using Microsoft.Build.CopyOnWrite.

Usage: As a CLI

To install the CLI, use the latest exe from releases.

Alternatively, it can be installed as a tool, using the .NET 7 SDK.

dotnet tool install -g forceops

To delete a file:

forceops delete file.txt

Usage: As a library

See the ForceOps.Lib package.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.1 214 12/6/2023
1.3.0 105 12/3/2023
1.2.1 113 9/25/2023
1.2.0 131 9/7/2023
1.1.0 136 8/17/2023
1.0.4 136 7/11/2023
1.0.3 142 7/6/2023
1.0.2 123 7/5/2023
1.0.1 135 7/4/2023
1.0.0 122 7/3/2023
1.0.0-pre 126 7/2/2023