使用Roslyn编译带有空项目的解决方案会产生错误

时间:2015-03-05 22:27:48

标签: c# visual-studio roslyn

我正在尝试使用Roslyn编译VS2013解决方案。该解决方案有许多项目,其中一个没有.CS文件(我们只是用它来存储JS和CSS文件。它有一堆MSBuild步骤来缩小,lint等这些文件)。

当我通过Roslyn运行解决方案时,我收到以下错误:

  

Microsoft.Build.Exceptions.InvalidProjectFileException:目标   "编译"在项目中不存在。

这是我用来编译的代码:

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

我该怎样防止这种情况?该解决方案在VS2013中构建得很好。

编辑:根据要求,这里是堆栈跟踪

   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]

1 个答案:

答案 0 :(得分:1)

Roslyn假设所有.csproj项目都是具有C#编译任务的实际C#项目。

对于非C#项目,您应使用其他扩展名,例如.proj

您还可以向Roslyn提交一个错误,要求他们跳过没有编译任务的项目。