我想以编程方式创建以下 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
<
>
我也试过使用XElement.parse("<?include \"" + constantfileloc + "\"?>")
,但我无法让它工作,
可以使用 XDocument 吗?因为我真的不想用文字作家