This project is read-only.
1
Vote

MSBuildWorkspace fails to open solution if a C# project is missing a compilation target

description

I am trying to use Roslyn to compile a VS2013 solution for code analysis purposes. The solution has many projects, one of which has no .CS files (we just use it to store JS and CSS files. It has a bunch of MSBuild steps to minify, lint, etc. these files).

When I run the solution through Roslyn, I get the following error:
Microsoft.Build.Exceptions.InvalidProjectFileException : The target "Compile" does not exist in the project.
Here's the code I'm using to compile:

await MSBuildWorkspace.Create().OpenSolutionAsync(solutionFilePath);

The solution builds just fine in VS2013; I would expect Roslyn to be able to handle it as well.

EDIT: as requested, here's the stack trace

at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at [My Code]
--InvalidProjectFileException
at Microsoft.CodeAnalysis.MSBuild.ProjectFile.<BuildAsync>d__1.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.CSharp.CSharpProjectFileLoader.CSharpProjectFile.<GetProjectFileInfoAsync>d__1.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.MSBuildWorkspace.<LoadProjectAsync>d__1.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.<GetOrLoadProjectAsync>d__1.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.<OpenSolutionAsync>d__1.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`1.GetResult()
at [My Code]

My stackoverflow post on this topic: http://stackoverflow.com/questions/28889029/using-roslyn-to-compile-a-solution-with-an-empty-project-gives-an-error?noredirect=1#comment46042017_28889029

comments