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

时间:2014-05-22 12:09:11

标签: c# xml namespaces wix

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

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

[XmlElementAttribute("bal:WixStandardBootstrapperApplication")]
public WixStandardBootstrapperApplication WixStandardBootstrapperApplication
{ get; set; }

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

1 个答案:

答案 0 :(得分:1)

解决方案位于: 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>