This project is read-only.

Preserve XML comments

Mar 4, 2009 at 3:38 AM
Edited Mar 4, 2009 at 3:39 AM

Hi Loren,

First to congratulate you on this extremely useful tool. I have to maintain a project that gets deployed to many environments with different settings and thus tool really helps me.
However is there a way to preserve XML comments inside a <!-- ifdef  --> block

e.g if the input file is:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!--ifdef ${_xml_preprocess}-->
  <Target Name="Build">
    <!-- some comment -->
    <Exec  Command= "UpdateDatabase.exe  ${Database} Verbose RunAll" />
  </Target>
  <!--endif-->
</Project>

I run this command
XmlPreprocess.exe /nologo /c /f /i input.proj /o output.proj /d:Database=Northwind

I want the output to be:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="Build">
    <!-- some comment -->
    <Exec  Command= "UpdateDatabase.exe  Northwind Verbose RunAll" />
  </Target>
</Project>

Currently the output has the comment removed

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="Build">    
    some comment
    <Exec  Command= "UpdateDatabase.exe  Northwind Verbose RunAll" />
  </Target>
</Project>

Pratik

Jun 4, 2009 at 2:03 AM

The feature I just added in RC2 actually may solve this by eliminating the need for the ifdef completely. So if you remove the ifdef/endif in your input file

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="Build">
    <!-- some comment -->
    <Exec  Command= "UpdateDatabase.exe  ${Database} Verbose RunAll" />
  </Target>
</Project>

And add the /noDirectives (or /n) switch

XmlPreprocess.exe /nologo /c /f /i input.proj /o output.proj /d:Database=Northwind /noDirectives

You should achieve

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="Build">
    <!-- some comment -->
    <Exec  Command= "UpdateDatabase.exe Northwind Verbose RunAll" />
  </Target>
</Project>