Problem: I am working on a program to take the output of tree and re create the directory structure on a different system. My code works for test sets of files that I have created at random. However when dealing with Systems with detailed/long folder names I run into a System.IO.IOException '(the filename or extension is too long) on this code
String path = @".\" PreviousDirectory @"\";
int errorCheck = path.Length;
Directory.SetCurrentDirectory(path, PathFormat.LongFullPath);
Attempted Solutions: I have found this thread which describes several options. I have tried many of these I am currently not using System.IO I am using AlphaAeonis.Win32.Filesytem which supposedly has support for 32,000 chars in a path however my error occurs on a path that is 282 chars long.
I am also attempting to use .Net Framework 4.6.2 or higher which removed the path limit. I changed my target framework to 4.6.2 in Visual Studio 2017 which I am using I also have .NET SDK 6.0.0 installed. My app.config file which controls how Visual studio runs the code this looks like this
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
<runtime>
<AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false"/>
</runtime>
If I change to anything except version = v"4.0" I am asked to install that version of .NET despite having higher version frameworks installed. I assume that the v4.0 is what is actually running.
Questions:
a. How can I ensure that all Directory functions use the Override from the imported Alphaleonis Library?
b. How can I ensure a minimum .Net Version upon Runtime?
c. What else could I set to allow long Paths?
CodePudding user response:
The Solution was switching from .NET Framework to .Net Core. Thank You to pcalkins