msbuild
msbuild copied to clipboard
Preprocessed output of a new project that imports a file with an xmlns is littered with xmlns
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>
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
That's unfortunate, but IMO doesn't raise the priority on this much. Building using the preprocessed file rarely works for other reasons.
Building using the preprocessed file rarely works for other reasons.
So I discovered after fixing the xmlns
:-)
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.
This isn't going to make it for 15.3.