MSBuild 15.0 (Visual Studio 2017) SSDT(SSRS 和 SSAS)项目的错误 MSB4067:"The element <State> beneath element <Project> is unrecognized"

MSBuild 15.0 (Visual Studio 2017) error MSB4067 for SSDT (SSRS and SSAS) projects: "The element <State> beneath element <Project> is unrecognized"

MSBuild 14.0(Visual Studio 2015 中包含的版本)在构建包含 SSDT 项目(rptproj 或 dwproj 项目)的解决方案时记录警告 (MSB4078)。例如:

warning MSB4078: The project file "Reports.rptproj" is not supported by MSBuild and cannot be built.

没关系,MSBuild 不支持 SSDT 项目,我们必须回退到使用 Visual Studio(即 devenv.com)构建它们。例如,参见 .

使用 MSBuild 15.0(Visual Studio 2017 中包含的版本)时,构建相同的解决方案文件会出现以下 错误

Reports.rptproj(3,3): error MSB4067: The element <State> beneath element <Project> is unrecognized.

虽然我可以从构建配置中删除 SSDT 项目,但这并不理想,因为我希望在 Visual Studio 中构建解决方案时构建它们.

有没有办法将错误 MSB4067 降级为警告,或者在构建解决方案时跳过某些项目?

可以使用 /ignoreprojectextensions:.rptproj 完成跳过项目,但我仍然收到警告(在 VS2015 上),所以你可能仍然会收到错误。

可能的是指定您想要用

构建的列表
msbuild /t:myCsProj /t:mySqlProj /t:myOtherProjThatIsntaRptProj

当然,这是否可行取决于您的解决方案中有多少 "other" 个项目。

或者,有一些方法可以使 MSBuild 能够处理其他项目类型(例如 https://speaksql.wordpress.com/2013/06/07/a-journey-to-db-deployment-automaton-ssis-build-using-msbuild/)。

我见过这种方法 "in the wild" 几次,但只见过 SSIS。不过,我听说它也可以用于 SSRS/SSAS。

更新(2017 年 10 月)

Microsoft Reporting Services Projects 的最新版本 Visual Studio (1.18) adds MSBuild support for SSRS projects。安装后,SSRS 项目可以更新为 MSBuild 支持的格式,从而防止出现此问题。


原答案

这是 MSBuild 15 中的 bug,标记为在“基础更新 2”中修复。

一位 MSBuild 维护者在 GitHub issue thread 中给出的解决方法是:

Place a file with these contents next to your .sln file with the special name:

after.{yoursolutionname}.sln.targets

<Project InitialTargets="WorkAroundMSBuild2064">
 <Target Name="WorkAroundMSBuild2064">
  <!-- Work around https://github.com/Microsoft/msbuild/issues/2064 by
   removing *.rptproj from the generated solution metaproject. -->
  <ItemGroup>
   <ProjectReference Remove="%(ProjectReference.Identity)"
                 Condition="'@(ProjectReference->'%(Extension)')' == '.rptproj'" />
  </ItemGroup>
 </Target>
</Project>

如果没有从其他 .csproj 项目到 .rptproj 项目的项目依赖项,这似乎可行。