Chessar.LongPaths
1.0.0-rc004
See the version list below for details.
dotnet add package Chessar.LongPaths --version 1.0.0-rc004
NuGet\Install-Package Chessar.LongPaths -Version 1.0.0-rc004
<PackageReference Include="Chessar.LongPaths" Version="1.0.0-rc004" />
paket add Chessar.LongPaths --version 1.0.0-rc004
#r "nuget: Chessar.LongPaths, 1.0.0-rc004"
// Install Chessar.LongPaths as a Cake Addin #addin nuget:?package=Chessar.LongPaths&version=1.0.0-rc004&prerelease // Install Chessar.LongPaths as a Cake Tool #tool nuget:?package=Chessar.LongPaths&version=1.0.0-rc004&prerelease
Chessar.LongPaths is a .NET library that allows you to enable long path support for the main System.IO
classes:
FileStream
, File
, FileInfo
, Directory
, DirectoryInfo
, ... (and others).
The library is based on replacing the internal NormalizePath
and GetFullPathInternal
functions from the static Path
class. The replacement is done using JMP hooks
(thanks to @wledfor2), in which the long path prefix \\?\
or \\?\UNC\
is added. Adding a prefix is done by calling the internal function Path.AddLongPathPrefix
. Note also that the addition of such prefixes depends on the UseLegacyPathHandling
and BlockLongPaths
settings, which must necessarily be false
(in the AppContextSwitchOverrides
element).
In this case, your code does not need to directly add such prefixes to the paths.
Supported Platforms:
- .NET Framework 4.6.2+ (see .NET Blog)
How to use
- Add the Chessar.LongPaths NuGet package to the project.
- In the file
app.config
(orweb.config
), in the sectionruntime
, add:
<configuration>
...
<runtime>
<AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false;Switch.System.IO.BlockLongPaths=false" />
</runtime>
...
- In the code (when you start the application or at the beginning of
Main
) add code:
...
using static Chessar.Hooks;
...
PatchLongPaths();
- Usage
...
var fileInfo = new FileInfo(path);
var fullName = fileInfo.FullName; // with long path prefix
...
- At the end of the application:
RemoveLongPathsPatch();
See also Examples.
Notes
For the following list of ctors/methods, you must directly specify the prefix of long paths (because they are not supported by this library, see Unit Tests):
new DirectorySecurity(String, AccessControlSections)
new FileSecurity(String, AccessControlSections)
Directory.GetAccessControl(String[, AccessControlSections])
File.GetAccessControl(String[, AccessControlSections])
Directory.Move(String, String)
DirectoryInfo.MoveTo(String)
for example:
...
using static Chessar.Hooks;
...
var ds = new DirectorySecurity(path.AddLongPathPrefix(), acs);
or use DirectoryInfo
instead Directory
(exclude MoveTo
method) and FileInfo
instead File
.
Note that, next methods does not work for long paths, even if a prefix is added:
Directory.SetCurrentDirectory
Image.Save(String)
(useImage.Save
toStream
instead)
TODO
- Speed up MethodInfo.Invoke in the class
Hooks
, using, for example,DynamicMethod.CreateDelegate
. - Add long path support in ctors/methods from
Notes
. - Add more unit tests.
- Make hooks more thread safe.
License
MIT - See LICENSE
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
This package has no dependencies.
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.1.8 | 1,616 | 10/25/2018 |
1.1.7 | 795 | 10/2/2018 |
1.1.7-rc003 | 602 | 10/2/2018 |
1.1.6 | 770 | 9/24/2018 |
1.1.5 | 748 | 9/23/2018 |
1.1.4 | 792 | 9/21/2018 |
1.1.3 | 770 | 9/20/2018 |
1.1.2 | 824 | 9/16/2018 |
1.1.1 | 790 | 9/12/2018 |
1.1.0 | 794 | 9/10/2018 |
1.0.9 | 843 | 9/4/2018 |
1.0.8 | 810 | 8/26/2018 |
1.0.7 | 859 | 7/30/2018 |
1.0.6 | 808 | 7/25/2018 |
1.0.5 | 826 | 7/19/2018 |
1.0.4 | 904 | 7/18/2018 |
1.0.3 | 922 | 7/18/2018 |
1.0.2 | 917 | 7/18/2018 |
1.0.1 | 946 | 7/12/2018 |
1.0.0 | 921 | 7/12/2018 |
1.0.0-rc005 | 690 | 7/5/2018 |
1.0.0-rc004 | 757 | 6/20/2018 |
1.0.0-rc003 | 750 | 6/18/2018 |
Pre-release. Changed the strategy for applying the patch: now types that do not support long paths are excluded.