OS: Windows 7 Professional.
We are using Roslyn for opening .csproj file to get its Compilation details using following code:
using (var workspace = MSBuildWorkspace.Create())
{
Project currentProject = workspace.OpenProjectAsync(projectPath).Result;
Compilation compilation = currentProject.GetCompilationAsync().Result;
}
The code works for .csproj files having file path less than 260 characters. But the code throws following exception while opening a .csproj file having file path greater than 260 characters.
System.AggregateException: One or more errors occurred. --->
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.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
at System.IO.Path.GetFullPathInternal(String path)
at Microsoft.CodeAnalysis.MSBuild.ProjectFile.IsDocumentGenerated(ITaskItem documentItem)
at Microsoft.CodeAnalysis.CSharp.CSharpProjectFileLoader.CSharpProjectFile.MakeDocumentFileInfo(String projectDirectory, ITaskItem item)
at Microsoft.CodeAnalysis.CSharp.CSharpProjectFileLoader.CSharpProjectFile.<>c__DisplayClass5_0.<CreateProjectFileInfo>b__1(ITaskItem s)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
at System.Collections.Immutable.ImmutableArray.ToImmutableArray[TSource](IEnumerable`1 items)
at Microsoft.CodeAnalysis.CSharp.CSharpProjectFileLoader.CSharpProjectFile.CreateProjectFileInfo(CSharpCompilerInputs compilerInputs, BuildInfo buildInfo)
at Microsoft.CodeAnalysis.CSharp.CSharpProjectFileLoader.CSharpProjectFile.<GetProjectFileInfoAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.<LoadProjectAsync>d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.<LoadProjectInfoAsync>d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.<OpenProjectAsync>d__23.MoveNext()
But this limitation has to have some workaround. We are looking out for some certain option in resolving this issue.
Note:
- We cannot change the file paths to shorter file paths.
- We have already tried the subst option but it still is not a full proof option.