因为要做wix安装包,要一行一行copy Components的xml描述太麻烦了,个人有点懒,不愿重复劳动;所以写了个小工具;来生成xml;原来一个小时的工作,因为有了小工具,一秒就搞定,何乐而不为?
FolderBrowserDialog dlg = new FolderBrowserDialog();
DialogResult ret = dlg.ShowDialog();
if (ret == DialogResult.OK)
{
textBox1.Text = dlg.SelectedPath;
}
XmlDocument doc = new XmlDocument();
DirectoryInfo rootDir = new DirectoryInfo(this.textBox1.Text.Trim());
int i = 1;
XmlElement rootElement = doc.CreateElement("Components");
doc.AppendChild(rootElement);
foreach (FileInfo fi in rootDir.GetFiles())
{
XmlElement element = doc.CreateElement("Component");
XmlAttribute xaDir = doc.CreateAttribute("Directory");
xaDir.Value = "VHSoft.VHSyndesignServer.DwgFunc";
element.Attributes.Append(xaDir);
XmlAttribute xaGuid = doc.CreateAttribute("Guid");
xaGuid.Value = Guid.NewGuid().ToString();
element.Attributes.Append(xaGuid);
rootElement.AppendChild(element);
XmlElement childElement = doc.CreateElement("File");
XmlAttribute xaId = doc.CreateAttribute("Id");
string ki = "00" + i.ToString();
string Id = string.Format("SynDsn..003.{0}", ki.Substring(ki.Length - 3, 3));
xaId.Value = Id;
childElement.Attributes.Append(xaId);
XmlAttribute xaName = doc.CreateAttribute("Name");
xaName.Value = fi.Name;
childElement.Attributes.Append(xaName);
XmlAttribute xaKeyPath = doc.CreateAttribute("KeyPath");
xaKeyPath.Value = "yes";
childElement.Attributes.Append(xaKeyPath);
XmlAttribute xaSrc = doc.CreateAttribute("Source");
string src = string.Format(@"VHSyndesignServer_32\DwgFunc\{0}", fi.Name);
xaSrc.Value = src;
childElement.Attributes.Append(xaSrc);
element.AppendChild(childElement);
i++;
}
doc.Save(@"c:\Components.xml");