XAP包中的配置需要手动改?
这几天到了项目小结测试的时候,需要发布到服务器上测试接口,因此silverlight的发布动作相对比较频繁,由于一些公共的WCF服务和数据库都在公司的数据库服务器上,项目中的服务引用配置文件ServiceReferences.ClientConfig需要经常改动,主要改的是IP地址,当然还有web.config和WCF服务的终结点配置等等,比较难改的是ServiceReferences.ClientConfig,因为这个配置文件是生成到RIA.xap包中的,想修改其中的配置要么在生成前修改,要么在生成后修改RIA.xap为RIA.zip然后解压后修改再压缩,这样修改起来很费时间,于是就写了一个小工具来自动完成这个操作。
写个工具自动修改RIA.xap中的服务引用配置
主要利用一个zip类解压在压缩实现。
主体代码:
string fileName = this.textBox1.Text;
if (fileName.Contains("RIA.xap")&&this.txtFrom.Text!=""&&this.txtTo.Text!="")
{
string oldString = this.txtFrom.Text;
string newString = this.txtTo.Text;
string configFileName = "ServiceReferences.ClientConfig";
System.IO.File.Move(fileName,fileName.Replace("RIA.xap","RIA.zip"));
fileName = fileName.Replace("RIA.xap","RIA.zip");
Zip.UnZipFiles(fileName,fileName.Replace("RIA.zip","result/"));
System.IO.File.Delete(fileName);
fileName = fileName.Replace("RIA.zip","result");
string strAll = System.IO.File.ReadAllText(fileName+"/"+configFileName);
System.IO.File.Delete(fileName + "/" + configFileName);
strAll = strAll.Replace(oldString,newString);
System.IO.File.WriteallText(fileName + "/" + configFileName,strAll);
Zip.ZipFiles(fileName.Replace("result","RIA.zip"),fileName);
System.IO.Directory.Delete(fileName);
System.IO.File.Move(fileName.Replace("result",fileName.Replace("result","RIA.xap"));
MessageBox.Show("替?换?完ê成é!?");
}
else
{
MessageBox.Show("请?选?择?RIA.xap文?件t并¢填?写′需è要a替?换?的?字?符?串?再ù进?行D操ù作÷!?");
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。