2016-09-29 24 views
0

因此,我正在用Xamarin Forms App使用Grial UI工具包。我遵循iOS & Android的说明mentioned here。它适用于iOS。但是,它会在Colors.tt文件的第2行上引发错误。使用Xamarin Forms与Grial UI工具包解析XML错误

的Colors.tt文件具有以下代码:

<#@ template language="C#" hostspecific="True" #> 
<#@ output extension=".xml" #> 
<#@ assembly name="System.Core" #> 
<#@ assembly name="System.Drawing" #> 
<#@ assembly name="System.Xml" #> 
<#@ import namespace="System.Linq" #> 
<#@ import namespace="System.Text" #> 
<#@ import namespace="System.Collections.Generic" #> 
<#@ import namespace="System.Xml" #> 
<#@ import namespace="System.Drawing" #> 
<#@ import namespace="System.Globalization" #> 
<#@ import namespace="System.Text.RegularExpressions" #> 
<#@ assembly name="System.Windows" #> 
<#@ import namespace="System.Windows" #> 
<# 
string path = Host.ResolvePath("../../../PCLFolderName/App.xaml"); 
XmlDocument doc = new XmlDocument(); 
doc.Load(path); 

Dictionary<string, Color> knownColors = new Dictionary<string, Color>(); 
List<string> exports = new List<string>(); 

XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); 
nsmgr.AddNamespace("artina", "clr-namespace:UXDivers.Artina.Shared;assembly=UXDivers.Artina.Shared"); 
nsmgr.AddNamespace ("xamarin", "http://xamarin.com/schemas/2014/forms"); 

XmlNode resources = doc.DocumentElement.SelectSingleNode("/xamarin:Application/xamarin:Application.Resources/xamarin:ResourceDictionary", nsmgr); 

if (resources != null) { 
    foreach (XmlNode node in resources.ChildNodes) { 
     if (node.NodeType == XmlNodeType.Comment) { 
      var comment = node.InnerText.Trim(); 

      Match match = Regex.Match(comment, @"Export\s([A-Za-z0-9\-]+)$", RegexOptions.IgnoreCase); 

      if (match.Success) 
      { 
       exports.Add (match.Groups[1].Value); 
      } 
     } 
     else if (node.Name == "Color") { 
      string colorName = null; 

      foreach (XmlAttribute attribute in node.Attributes) { 
       if (attribute.LocalName == "Key") { 
        colorName = attribute.Value; 
        var colorDefinition = node.InnerText.Trim(); 
        Color color; 

        if (colorDefinition.StartsWith ("#")) { 
         if (colorDefinition.Length == 7) { 
          colorDefinition = "FF" + colorDefinition; 
         } 

         int argb = Int32.Parse (colorDefinition.Replace ("#", ""), NumberStyles.HexNumber); 
         color = Color.FromArgb (argb); 
        } else { 
         color = Color.FromName (colorDefinition); 
         string colorString = string.Format("#FF{0:X2}{1:X2}{2:X2}", 
         color.R, color.G, color.B); 

         color = System.Drawing.ColorTranslator.FromHtml(colorString); 
        } 

        knownColors.Add (colorName, color); 
       } 
      } 
     } 
    } 
}    
if (exports.Count > 0){ 
#> 
<?xml version="1.0" encoding="utf-8" ?> 
<resources> 
    <!-- Artina Exported Colors --> 
<# 
    foreach(var name in exports){ 
    Color color; 

    if (knownColors.TryGetValue(name, out color)){ 
#> 
    <color name="<#= name #>">#<#= color.A.ToString("X2") #><#= color.R.ToString("X2") #><#= color.G.ToString("X2") #><#= color.B.ToString("X2") #></color> 
<# 
    } 
    } 
#> 
</resources> 
<# 
} 
#> 

该错误是在线路#2抛出: “XML” <#@输出扩展=#>

该错误消息是:

错误解析XML:没有很好地形成(标记无效)

有anyb ody之前面对过这个?任何解决方案或意见非常感谢。

谢谢。 诺埃尔

PS:

  1. 开发使用VS2015 + Xamarin VS + 10的Windows在Mac上完成的。
  2. 所有SDK的已更新。

回答

0

所以这是通过将colors.tt文件上的构建动作更改为无。