Removing Unit Test dll files when using WIX

2019-07-04 02:16发布

问题:

I'm trying to create an MSI for my project using WIX. I've got HEAT pointing to the correct directory and the file it spits out is correct, but for some reason when I actually run MSBuild on it it's also giving me all of my unit test dll files.

Anyone have any idea how to remove those from the build process?

回答1:

One option would be to write an XSL transformation modifying the generated HEAT output (e.g. removing the unwanted files):

heat.exe dir <other arguments> -t my.xsl

To remove a specific file your xsl could be something like:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="node()[child::node()[@Source='UnwantedAssembly.dll']]" />
</xsl:stylesheet>

This approach allows you to make other changes to the file as well. Though to only remove unwanted files it's usually simpler to just delete them from the build directory or to move the desired files into another directory and run HEAT there.



回答2:

Typically you wouldn't point heat.exe at your default build directory for just this reason. After you compile your product's binaries add a second step to stage the files you want into a second directory. Then, point heat.exe at the staged directory. That way you have more control over the files & paths that get harvested.