简体   繁体   中英

The “GenerateBindingRedirects” task failed unexpectedly. The specified path, file name, or both are too long

The "GenerateBindingRedirects" task failed unexpectedly.

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

Easiest solution is to:

  1. Unload the .csproj file of the project that's giving you the issue.
  2. Add this at the end of the .csproj file

     <Target Name="WorkaroundAppConfigPathTooLong" BeforeTargets="GenerateBindingRedirects"> <PropertyGroup> <_GenerateBindingRedirectsIntermediateAppConfig>$(IntermediateOutputPath)$(TargetFileName).config</_GenerateBindingRedirectsIntermediateAppConfig> </PropertyGroup> </Target> 
  3. Save and reload the project. Rebuild.

You're basically asking Visual Studio to cut down the path length of the intermediate app config file that's giving you the issue.

This issue is related specifically to GenerateBindingRedirects, and is being tracked here: https://github.com/Microsoft/msbuild/issues/1786

It looks like this exception can be triggered with project names even a third of MAX_PATH. I have a project with a 55-character name. According to the issue linked above, that project name is appended three times, and added to the full project location, to create the name of a config file.

For me the solution was to make sure the path to my solution was less than about 70 characters.

This issue happens when you have any folder path inside of you application which has more 259 characters.

I had this issue in my .Net Core 1.0 app . Thing is, I started designing the UI using a lite server from NODEJS also with some other .JS library packs, this was only for quick launch and it wouldn't go to any other environment than my PC. So, I was using NPM to install those libraries + the lite server components into my wwwroot . When installing the packs through NPM, it created a folder named node_modules and a bunch of other sub-folders tree.

Because of this bunch of large path folders, I was getting this error. The problem is not in your namespace fully qualified name, the problem is the folders your project has.

I removed the node_module folder from my project and it compiled fine. Another thing, when compiling through the console with dotnet build , I wasn't getting any error, only when through IDE.

I had some issues to remove node_module from my PC as windows was throwing the same exception, and actually this is a very known exception for windows users. I got this many times when doing other things with long folder paths.

Anyways, I tried del folder_path command, Remove-Item folder_path either of them didn't work, I founded out that NPM has a package named rimraf which does the job, also there is another tool named 7zip (I didn't test that) which supposed to do the same.

So, using NPM, run -> npm install -g rimraf than rimraf folder_path and happy days :)

Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM