0

我想以编程方式创建以下 xml 结构

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <?include "mypath\Constants.wxi"?>
    <Product Id="*" Name="$(var.ProductName)" Language="$(var.ProductLanguage)" Version="$(var.ProductVersion)" Manufacturer="$(var.ProductManufacturer)" UpgradeCode="$(var.ProductUpgradeCode)">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
        <MajorUpgrade DowngradeErrorMessage="A newer vesrion of [ProductName] is already installed" />
        <UIRef Id="WixUI_Minimal" />
        <MediaTemplate />
    </Product>
</Wix>

我尝试使用 XDocument

  XDocument xmldoc = new XDocument(
        new XElement("Wix",
            new XText("<?include \"" + constantfileloc + "\"?>"),
            new XElement("Product",
              new XAttribute("Id", "*"),
              new XAttribute("Name", "$(var.ProductName)"),
              new XAttribute("Language", "$(var.ProductLanguage)"),
              new XAttribute("Version", "$(var.ProductVersion)"),
              new XAttribute("Manufacturer", "$(var.ProductManufacturer)"),
              new XAttribute("UpgradeCode", "$(var.ProductUpgradeCode)"),
              new XElement("Package",
                  new XAttribute("InstallerVersion", "200"),
                  new XAttribute("Compressed", "yes"),
                  new XAttribute("InstallScope", "perMachine")
              ),
              new XElement("MajorUpgrade",
                    new XAttribute("DowngradeErrorMessage", "A newer vesrion of [ProductName] is already installed")
              ),
              new XElement("UIRef",
                  new XAttribute("Id", "WixUI_Minimal")
              ),
              new XElement("MediaTemplate")
           )
        )
  );

问题当然是<?include?/>which 不能被创建,XElement因为它不允许元素以 ? 所以我想我可以通过使用它来使它工作,但显然它在and的声明中XText替换了我的and 。<>XText&lt&gt

我也试过使用XElement.parse("<?include \"" + constantfileloc + "\"?>") ,但我无法让它工作,

可以使用 XDocument 吗?因为我真的不想用文字作家

4

1 回答 1

3

是的,这是可能的。您看到的不是文本部分。他们正在处理指令。您必须使用 XProcessingInstruction 而不是 XText。查看MSDN 站点上的文档。您可以类似于以下方式使用它:

XDocument xmldoc = new XDocument(
    new XElement("Wix",
        new XProcessingInstruction("include", constantfileloc),
        new XElement("Product",
          new XAttribute("Id", "*"),
          new XAttribute("Name", "$(var.ProductName)"),
          new XAttribute("Language", "$(var.ProductLanguage)"),
          new XAttribute("Version", "$(var.ProductVersion)"),
          new XAttribute("Manufacturer", "$(var.ProductManufacturer)"),
          new XAttribute("UpgradeCode", "$(var.ProductUpgradeCode)"),
          new XElement("Package",
              new XAttribute("InstallerVersion", "200"),
              new XAttribute("Compressed", "yes"),
              new XAttribute("InstallScope", "perMachine")
          ),
          new XElement("MajorUpgrade",
                new XAttribute("DowngradeErrorMessage", "A newer vesrion of [ProductName] is already installed")
          ),
          new XElement("UIRef",
              new XAttribute("Id", "WixUI_Minimal")
          ),
          new XElement("MediaTemplate")
       )
    )
);
于 2013-10-17T20:32:52.270 回答