Dot-Net

SSDT(SSRS 和 SSAS)項目的 MSBuild 15.0 (Visual Studio 2017) 錯誤 MSB4067:“元素 <Project> 下的元素 <State> 無法辨識”

  • August 5, 2019

在建構包含 SSDT 項目(rptproj 或 dwproj 項目)的解決方案時,MSBuild 14.0(Visual Studio 2015 中包含的版本)會記錄警告 (MSB4078)。例如:

警告 MSB4078:項目文件“Reports.rptproj”不受 MSBuild 支持,無法建構。

這很好,MSBuild 不支持 SSDT 項目,我們不得不退回到使用 Visual Studio(即devenv.com)建構它們。例如,請參閱此答案

但是,在使用 MSBuild 15.0(Visual Studio 2017 中包含的版本)時,建構相同的解決方案文件會出現以下錯誤

Reports.rptproj(3,3):錯誤 MSB4067:元素 <Project> 下的元素 <State> 無法辨識。

雖然我可以從建構配置中刪除 SSDT 項目,但這並不理想,因為我希望在從 Visual Studio 中建構解決方案時建構它們。

有沒有辦法將錯誤 MSB4067 降級為警告,或者在建構解決方案時跳過某些項目?

更新(2017 年 10 月)

最新版本的 Microsoft Reporting Services Projects for Visual Studio (1.18)添加了對 SSRS 項目的 MSBuild 支持。安裝後,可以將 SSRS 項目更新為 MSBuild 支持的格式,從而防止發生此問題。


原始答案

這是 MSBuild 15 中的一個錯誤,在“基礎更新 2”中標記為修復。

MSBuild 維護者之一在GitHub 問題執行緒中給出的解決方法是:

.sln將包含這些內容的文件放在具有特殊名稱的文件旁邊:

after.{yoursolutionname}.sln.targets

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

.csproj如果其他項目與項目之間沒有項目依賴關係,這似乎可行.rptproj

引用自:https://stackoverflow.com/questions/43735390