Wix和XmlSerialization:冒号字符被加密为x003A

本文关键字:加密 x003A 字符 XmlSerialization Wix | 更新日期: 2023-09-27 18:04:41

在花了一些时间寻找如何解决这个问题之后,找到了解决方案并决定在这个受人尊敬的论坛上发表,给予应得的荣誉。

问题:下面对XmlElementAttribute的序列化在WXS文件中产生了以下内容:

[XmlElementAttribute("bal:WixStandardBootstrapperApplication")]
public WixStandardBootstrapperApplication WixStandardBootstrapperApplication
{ get; set; }
<BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.HyperlinkLicense">
   <bal_x003A_WixStandardBootstrapperApplication LicenseUrl="" SupressOptionsUI="yes" />
</ BootstrapperApplicationRef >

Wix和XmlSerialization:冒号字符被加密为x003A

http://forums.asp.net/post/3149628.aspx找到解决方案。这样的:

序列化代码:

TextWriter tw = new StreamWriter (wxsBundleFileName) ;
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(wx.GetType());
XmlSerializerNamespaces XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", " http://schemas.microsoft.com/wix/2006/wi");
ns.Add("bal", "http://schemas.microsoft.com/wix/BalExtension") ;
xs.Serialize(tw, wx, ns);

序列化类的正确代码是:

[XmlElementAttribute(ElementName = "WixStandardBootstrapperApplication", Namespace = "http://schemas.microsoft.com/wix/BalExtension")]
public WixStandardBootstrapperApplication WixStandardBootstrapperApplication
{ get; set; }

准备好了!

<BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.HyperlinkLicense">
   <bal:WixStandardBootstrapperApplication LicenseUrl="" SupressOptionsUI="yes" />
</BootstrapperApplicationRef>