Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build error MSB4067 (UnrecognizedChildElement) when building a solution with rptproj or dwproj projects #2064

Open
AndrewBennet opened this issue May 5, 2017 · 28 comments
Labels
Area: Solution (.sln) Issues related to parsing .sln files or building solutions bug regression triaged

Comments

@AndrewBennet
Copy link

AndrewBennet commented May 5, 2017

When using MSBuild 15.0, cleaning or building a solution which contains rptproj or dwproj projects gives the following error:

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

When using MSBuild 14.0, the behaviour is better: it logs warnings (MSB4078) about unsupported projects:

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

The latter behaviour is more desirable (for me, at least): I would like to able to build a solution in a configuration which includes the .rptproj files. This would allow me to include these projects when building the solution in Visual Studio, and to be able to use the same configuration when building the solution via an MSBuild script.

Is this change of behaviour a bug? The message certainly seems like it is attempting to parse the rptproj file into some structure to which it doesn't belong. If it is not, is there a way to downgrade the error MSB4067 to a warning, or to skip certain projects when building a solution? The /ignoreprojectextensions:.rptproj option does not prevent the error.

Note: this issue relates to this Stack Overflow post.

@DaveSlinn
Copy link

I recently added our .rptproj back into our solution file once I saw the availability of the Reporting Services extension for VS 2017. Our solution builds fine on the dev boxes, but is broken on our build server - even though I have installed the Reporting Services Projects on the build machine as well. It's concerning that no one from the team has commented for almost 2 months.

@MgSam
Copy link

MgSam commented Jul 17, 2017

This is a big breaking change. We too now have broken solutions on our build machines because of this. Can someone please triage?

@rainersigwald
Copy link
Member

Thanks for the report!

MSBuild has some code that attempts to detect whether projects referred to from the solution are MSBuild projects or some other format.

In #1089, this logic was simplified to support the new simplified project files, which removed a check that the project specified the MSBuild namespace.

A simple .rptproj looks like this:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" ToolsVersion="2.0">
  <DataSources />
  <Reports />
</Project>

The fact that its top-level element is <Project> now gets a false positive (I stepped through MSBuild 14.0.25420.1 and observed it failing out because the namespace didn't match).

/ignoreprojectextensions:.rptproj is deceptively unrelated; it controls MSBuild's search-for-a-project-to-build behavior when no project is specified on the command line, not what projects from the solution get built.

@rainersigwald
Copy link
Member

rainersigwald commented Jul 17, 2017

Workarounds

  • 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>
  • Build with devenv {path_to_solution.sln} /build
    • This uses Visual Studio to handle parsing the solution and building each individual project, so it will behave much more like "Build" from the UI.
    • This can be slower and harder to debug than using MSBuild.
  • Use a solution configuration to prevent the .rptproj files from building

@rainersigwald rainersigwald added bug regression Area: Solution (.sln) Issues related to parsing .sln files or building solutions labels Jul 17, 2017
@rainersigwald rainersigwald added this to the MSBuild 15 "foundation update" 2 milestone Jul 17, 2017
@rainersigwald
Copy link
Member

Spoke to @AndyGerlicher about this. The more-permissive namespace check in the real MSBuild project parser requires that the namespace be either the MSBuild namespace or not specified. The same check could be applied in the solution parser.

@AndrewBennet
Copy link
Author

Thanks for the workarounds! I'm trying out the after.solution.sln.targets one now.

I'm currently still hitting the issue at a later point in the build due to a solution Project Dependency: one of my csproj projects depends on an rptproj project (this was done to cause the build of the csproj to trigger the build of the rptproj).

The error shows the steps:

msbuild script -> solution file -> csproj.metaproj -> rptproj

Is there a way to similarly exclude rptproj references from the generate project metaproject? I tried the same pattern of after.project.csproj.targets alongside my csproj file, but it didn't work.

@rainersigwald
Copy link
Member

@AndrewBennet Unfortunately, no, I don't see a nice way to prevent emitting those references into the .csproj.metaproj that is generated to handle the solution dependencies, and as you discovered that metaproject doesn't have extensibility hooks like after.project.sln.targets. I think you'll have to either drop the solution dependency or use a solution configuration to avoid the .rptproj.

@AndrewBennet
Copy link
Author

OK - I'll remove the solution dependency for now. Thanks 👍

@reicher001
Copy link

Any updates or timeline on when this issue will be resolved?

@AndyGerlicher AndyGerlicher self-assigned this Sep 28, 2017
AndyGerlicher added a commit to AndyGerlicher/msbuild that referenced this issue Oct 5, 2017
* Check that the schema matches either empty or the MSBuild default schema
when building a solution file.

* Special case .rptproj files. This file format looks like a standard
MSBuild file but specifies ToolsVersion=2.0 and a default XML schema.
Since the XML parser treats that schema as equivalent to empty and empty
is now allowed, there's no good way to determine if it's an MSBuild file
until we try to parse. This results in an error in MSBuild 15 rather
than a warning in MSBuild 14 for solutions with a .rptproj file. To
solve this, the sln build will now allow projects where the schema is
the default MSBuild schema or empty and ToolsVersion is not 2.0.

Partial fix for dotnet#2064
@AndrewBennet
Copy link
Author

AndrewBennet commented Oct 16, 2017

Just discovered that the ability to build rptproj projects with MSBuild has been added in the last few weeks: https://blogs.msdn.microsoft.com/sqlrsteamblog/2017/09/25/msbuild-support-for-reporting-services-projects-now-available/

Have not tried this out yet, but upgrading the rptproj projects to the latest format would presumably get around this problem.


Update: Having updated the SSRS Visual Studio plugin and upgraded the SSRS projects to the latest format, this issue no longer occurs. I can restore the solution dependecies 🎉

AndyGerlicher added a commit to AndyGerlicher/msbuild that referenced this issue Jan 4, 2018
* Check that the schema matches either empty or the MSBuild default schema
when building a solution file.

* Special case .rptproj files. This file format looks like a standard
MSBuild file but specifies ToolsVersion=2.0 and a default XML schema.
Since the XML parser treats that schema as equivalent to empty and empty
is now allowed, there's no good way to determine if it's an MSBuild file
until we try to parse. This results in an error in MSBuild 15 rather
than a warning in MSBuild 14 for solutions with a .rptproj file. To
solve this, the sln build will now allow projects where the schema is
the default MSBuild schema or empty and ToolsVersion is not 2.0.

Partial fix for dotnet#2064
@fenngineering
Copy link

Are .dtproj projects being added in the same fix?

@benjiadell
Copy link

Any updates for *.dtproj ? We have this issue on our customer and we need to build as soon as possible.

@richardlhughes
Copy link

I am seeing the same error with my .dtproj

Error MSB4067: The element <DeploymentModel> beneath element <Project> is unrecognized.

Should I open a new issue for building ispac's from dtproj?

@samsmithnz
Copy link

@richardlhughes: This workaround does work for dtproj too.

@donuwm
Copy link

donuwm commented Mar 26, 2019

@richardlhughes: This workaround does work for dtproj too.

Confirmed.

@StingyJack
Copy link

@rainersigwald - is this workaround still the only way to make this work on an Azure DevOps hosted build agent?

@shalmali30
Copy link

Workarounds

  • 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>
  • Build with devenv {path_to_solution.sln} /build

    • This uses Visual Studio to handle parsing the solution and building each individual project, so it will behave much more like "Build" from the UI.
    • This can be slower and harder to debug than using MSBuild.
  • Use a solution configuration to prevent the .rptproj files from building

HI, I am having .dtproj and .rptproj in a solution. i was getting errors for SSRS as well as SSIS. with this workaround, i could solve ssrs error message. Now SSIS is still there. I added :

Can you please let me know how to add .dtproj referance ?

@soroshsabz
Copy link

Is there any plan to resolve fundamentally this issue?

@madibaT
Copy link

madibaT commented May 13, 2021

Is there any update on this issue?

@soroshsabz
Copy link

@arielman what is helping TFS update 2 ?

@kartheekp-ms
Copy link

kartheekp-ms commented Mar 22, 2022

How about adding SkipUnsupportedProjects like SkipNonexistentProjects to MSBuild task? Related NuGet/Home#7796 FYI.. @dotnet/msbuild team

@aortiz-msft
Copy link

FYI.. @marcpopMSFT @dotnet/msbuild team this issue has 23 upvotes from the community in NuGet/Home#7796. In summary, NuGet.exe invokes msbuild.exe during restore to identify the project references for a project. As per @kartheekp-ms's analysis NuGet/Home#7796 (comment), it looks like something changed in msbuild version after 15.9 where msbuild.exe started returning a failure exit code when trying to read project references for a custom project (for example vdproj in this case). This happens even when ContinueOnError is set to WarnAndContinue (new behavior after 15.9 version). NuGet raises an exception in this case causing restore failures.

@rainersigwald rainersigwald removed this from the MSBuild 15.6 milestone Apr 12, 2022
@thelaziestgenius
Copy link

@rainersigwald I'm upgrading some SSAS dwproj files from 2019 to VS 2022, and I'm getting a build failure that just says Object reference not set to an instance of an object.
Currently, there isn't an official extension to support loading up SSAS projects, but I did try to install the latest release candidate:
https://marketplace.visualstudio.com/items?itemName=ProBITools.MicrosoftAnalysisServicesModelingProjects

Is there a similar workaround to get the dwproj file to build and deploy in Visual studio 2022?

@rainersigwald
Copy link
Member

@thelaziestgenius are you building from Visual Studio, or using MSBuild.exe on the command line?

@thelaziestgenius
Copy link

thelaziestgenius commented Apr 18, 2022

@rainersigwald

I'm building from Visual Studio. Is there a way to build in MSBuild.exe to get more logging?

@rainersigwald
Copy link
Member

@thelaziestgenius If you're building from Visual Studio, you're not hitting the problem tracked by this issue, which manifests only for command-line builds. I think you'll have to ask in the support channels for that plugin.

@thelaziestgenius
Copy link

thelaziestgenius commented Apr 19, 2022

@rainersigwald I've reached out to the team that manages the Microsoft Analysis Services Projects extension.

I ran this command and got the following error:
msbuild "C:\Projects\SSAS.dwproj" /t:go /fl

Error:
MSBuild version = "16.11.2+f32259642"
Build FAILED.

"C:\Projects\SSAS.dwproj" (go target) (1) ->
C:\Projects\SSAS.dwproj(2,3): error MSB4067: The element beneath element is unrecognized.

0 Warning(s)
1 Error(s)

Time Elapsed 00:00:00.04

I've also tried running it with the 2022 exe explicitly:
MSBuild version = "17.1.0+ae57d105c" and got the same error.

@rainersigwald
Copy link
Member

@thelaziestgenius that is not expected to work, because .dwproj files are not MSBuild projects; they are a different project format recognized by the Visual Studio plugin, which also handles building them.

This was referenced Jun 14, 2022
@Forgind Forgind self-assigned this Jun 23, 2022
AR-May pushed a commit that referenced this issue Sep 23, 2022
Mitigates #2064

Context
This is an alternate way to fix the same problem. This is incomplete: it would still need to replace "dwproj" with the !projectsKnownToBeMSBuild and add a warning.
@Forgind Forgind removed their assignment Oct 21, 2022
@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Solution (.sln) Issues related to parsing .sln files or building solutions bug regression triaged
Projects
None yet