Run Code Analysis task fails on long file paths, even when windows support for long file paths is enabled

Versions used:

  • OS: Windows 10 Enterprise N (x64)
  • OS configured with LongPathsEnabled: yes
  • Run Code Analysis task (azure devops) version 1.29.1

Error observed: “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”

Steps to reproduce:

  1. create an azure devops code repo with a 40-character name e.g. “devops.microservice.externalusersstore”
  2. check code into that repo where some of the code has a long path, e.g. 240 characters long
  3. configure an azure pipeline including a dotnet build task
  4. run the pipeline, and confirm that the dotnet build task creates files with an overall path longer than 260 characters, without problems
  5. add sonar tasks to the pipeline: Prepare Analysis Configuration, and Run Code Analysis after the dotnet build
  6. run the pipeline

Expected result: the Run Code Analysis task analyses all the files without problems

Actual result: the Run Code Analysis task errors and fails:

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.LegacyNormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.GetFullPathInternal(String path)
   at System.IO.FileInfo.Init(String fileName, Boolean checkHost)
   at SonarScanner.MSBuild.Common.ProjectInfoExtensions.<>c.<GetAllAnalysisFiles>b__8_0(String path)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at SonarScanner.MSBuild.Shim.PropertiesFileGenerator.ToProjectData(IGrouping`2 projectsGroupedByGuid)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at SonarScanner.MSBuild.Shim.PropertiesFileGenerator.TryWriteProperties(PropertiesWriter writer, IEnumerable`1& allProjects)
   at SonarScanner.MSBuild.Shim.PropertiesFileGenerator.GenerateFile()
   at SonarScanner.MSBuild.PostProcessor.MSBuildPostProcessor.GenerateAndValidatePropertiesFile(AnalysisConfig config)
   at SonarScanner.MSBuild.PostProcessor.MSBuildPostProcessor.Execute(String[] args, AnalysisConfig config, ITeamBuildSettings settings)
   at SonarScanner.MSBuild.BootstrapperClass.PostProcess()
   at SonarScanner.MSBuild.BootstrapperClass.<Execute>d__8.MoveNext()

Note: this problem has previously been raised in this forum (e.g. 18057, 23060 ), and the response given was that this was a windows limitation and nothing could be done about it. This is only part-right; it is a windows limitation, but windows does also offer long-file-paths support - but the application must explicitly take advantage of it; for example:

The application manifest must also include the longPathAware element.

Hi @vincebowdren. There is an open scanner issue for this - S4NET #939.

I’ll cross-reference this thread as a possible solution. Thanks!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.