在我处理一些文件之前,我试图从 git 中删除 lfs 跟踪标签,只有一些文件在我们公司的詹金斯服务器中使用时包含超过 260 个字符的文件路径。因此,我试图让 C# 使用长文件路径。我似乎在为下面的代码苦苦挣扎,我得到“找不到文件”,但是我 100% 不存在该文件,并认为我在使用 @"\?\" 方面做错了什么任何建议将不胜感激.
static int removeLFSTracking(string path)
{
int rC = STATUS_OK;
string lfsTracked = ".lfs.tracked";
List<string> files = new List<string>();
getFiles( path, files );
foreach(string file in files)
{
if(file.Contains(lfsTracked))
{
string newFileName = file.Replace(lfsTracked, "");
try
{
System.IO.File.Move( @"\\?\" + file, @"\\?\" + newFileName );
}
catch(SystemException e)
{
Console.WriteLine( "Failed to remove lfs tracked from file " + file );
Console.WriteLine( e.ToString( ) );
}
}
}
return rC;
}
我的 XML app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="Extensions" type="System.Configuration.AppSettingsSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</configSections>
<runtime>
<AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false;Switch.System.IO.BlockLongPaths=false" />
</runtime>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
答案是:我使用的是相对路径,这似乎不适用于语法,当我更改为绝对路径时,我的代码运行良好。