2016-04-15 49 views
3

「GenerateBindingRedirects」任務意外失敗。「GenerateBindingRedirects」任務意外失敗。指定的路徑,文件名或這兩者太長

System.IO.PathTooLongException: The specified path, file name, or both are too long. 
The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. 
    at System.IO.PathHelper.GetFullPathName() 
    at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths) 
    at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength) 
    at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) 
    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) 
    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync) 
    at System.Xml.XmlWriterSettings.CreateWriter(String outputFileName) 
    at System.Xml.XmlWriter.Create(String outputFileName, XmlWriterSettings settings) 
    at System.Xml.Linq.XDocument.Save(String fileName, SaveOptions options) 
    at Microsoft.Build.Tasks.GenerateBindingRedirects.Execute() 
    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() 
    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext() Incryptex.OMS.Workflow.MarketData.Service 
+0

這是一個預期的問題 - 因爲它表示完整的文件路徑必須<260個字符,顯然你的不是。 – BugFinder

+0

**完全限定的文件名必須少於260個字符,並且目錄名稱必須少於248個字符**它正在說明問題。 – Nitin

+1

我不認爲文件夾名稱正在創建問題,因爲我的一個名爲「Incryptex.OMS.Workflow.ExchangeEngine.Workers.Tests」的類Liabrary項目工作正常並且構建成功。 但「Incryptex.OMS.Workflow.MarketData.Service」項目給出錯誤。 如果我們比較項目文件夾名稱或目錄,發出錯誤的字符的字符數量少於。 –

回答

0

當您的應用程序中有更多259個字符的文件夾路徑時,會發生此問題。

我在我的.Net Core 1.0應用程序中有此問題。事情是,我開始使用一個精簡版服務器從設計UI的NodeJS還與其他一些.JS庫包,這僅是爲快速啓動,它不會去任何其他的環境比我的電腦。因此,我使用NPM將這些庫+ lite服務器組件安裝到我的wwwroot中。通過NPM安裝包時,它創建了一個名爲node_modules的文件夾和一堆其他子文件夾樹。

由於這堆大路徑文件夾,我得到這個錯誤。問題不在於您的名稱空間完全限定名稱,問題在於您的項目具有的文件夾。

我從我的項目中刪除了node_module文件夾,它編譯得很好。另一件事,當通過控制檯編譯與dotnet build,我沒有得到任何錯誤,只有通過IDE時。

我有一些問題,以刪除node_module從我的電腦,因爲窗戶拋出相同的異常,實際上這是一個非常着名的例外,爲Windows用戶。使用長文件夾路徑做其他事情時,我得到了很多次。

不管怎麼說,我試過del folder_path命令,Remove-Item folder_path其中一方沒有工作,我創辦了這NPM有一個名爲rimraf其做工作包,還存在另一個名爲工具7zip的(我沒」噸測試),這應該做的一樣。

因此,使用NPM,運行 - >npm install -g rimrafrimraf folder_path和幸福的日子:)

希望它能幫助!

2

這個問題專門GenerateBindingRedirects有關,這裏正在追蹤:https://github.com/Microsoft/msbuild/issues/1786

它看起來像這樣的異常可以用項目名稱MAX_PATH的甚至第三觸發。我有一個名字爲55個字符的項目。根據上面鏈接的問題,該項目名稱附加了三次,並添加到完整的項目位置,以創建一個配置文件的名稱。

對我來說,解決方案是確保我的解決方案的路徑少於約70個字符。

2

最簡單方法是:

  1. 卸載.csproj文件傳給你的問題的項目。
  2. .csproj文件

    <Target Name="WorkaroundAppConfigPathTooLong" 
        BeforeTargets="GenerateBindingRedirects"> 
        <PropertyGroup> 
        <_GenerateBindingRedirectsIntermediateAppConfig>$(IntermediateOutputPath)$(TargetFileName).config</_GenerateBindingRedirectsIntermediateAppConfig> 
        </PropertyGroup> 
    </Target> 
    
  3. 保存的末尾添加這一點,並重新加載項目。重建。

你基本上要求Visual Studio減少中間應用程序配置文件的路徑長度,這會給你帶來問題。

相關問題