msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

Preprocessed output of a new project that imports a file with an xmlns is littered with xmlns

Open rainersigwald opened this issue 7 years ago • 5 comments

When the entry-point project doesn't specify an xmlns (as new "clean" templates don't), but it imports a file that uses the xmlns (like, say, Microsoft.Common.targets), the resultant preprocessed output puts an xmlns= attribute on every known-to-MSBuild element in the output.

I noticed this on a new-web-template project where it's amazingly verbose, but here's a minimal repro:

S:\work\xmlns>type *proj

imported.proj


<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup />
</Project>

project.proj


<Project>
  <Import Project="imported.proj" />
</Project>

S:\work\xmlns>S:\msbuild\bin\Bootstrap\15.0\Bin\MSBuild.exe /pp project.proj
<?xml version="1.0" encoding="IBM437"?>
<!--
============================================================================================================================================
S:\work\xmlns\project.proj
============================================================================================================================================
-->
<Project>
  <!--
============================================================================================================================================
  <Import Project="imported.proj">

S:\work\xmlns\imported.proj
============================================================================================================================================
-->
  <PropertyGroup xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />
  <!--
============================================================================================================================================
  </Import>

S:\work\xmlns\project.proj
============================================================================================================================================
-->
</Project>

rainersigwald avatar Dec 08 '16 16:12 rainersigwald

This seems to break using the preprocessed file to build. I get this error:

C:\Users\daplaist\Documents\Visual Studio 2017\Projects\ConsoleApp30\ConsoleApp30\msbuild.xml(26,18): error MSB4066: The attribute "xmlns" in element <PropertyGroup> is unrecognized

dsplaisted avatar Feb 28 '17 02:02 dsplaisted

That's unfortunate, but IMO doesn't raise the priority on this much. Building using the preprocessed file rarely works for other reasons.

rainersigwald avatar Feb 28 '17 15:02 rainersigwald

Building using the preprocessed file rarely works for other reasons.

So I discovered after fixing the xmlns :-)

dsplaisted avatar Feb 28 '17 19:02 dsplaisted

Took a quick look at this this morning. Sadly, the easy fixes I tried didn't work.

I tried updating Preprocess() to always add the namespace to the <Project> element, both by just adding an attribute to it, and by using

            XmlSchema schema = new XmlSchema();
            schema.Namespaces.Add("xmlns", XMakeAttributes.defaultXmlNamespace);
            outerDocument.Schemas.Add(schema);

Neither corrected the problem.

rainersigwald avatar Apr 17 '17 17:04 rainersigwald

This isn't going to make it for 15.3.

rainersigwald avatar Jun 07 '17 15:06 rainersigwald