码迷,mamicode.com
首页 > 其他好文 > 详细

修改config中的assemblyBinding

时间:2019-10-11 12:30:08      阅读:57      评论:0      收藏:0      [点我收藏+]

标签:ati   class   row   soft   mic   return   manage   dna   测试   

修改config中的assemblyBinding

 

未测试这段代码

 

private void SetRuntimeBinding(string path, string value)
    {
        XmlDocument doc = new XmlDocument();

        try
        {
            doc.Load(Path.Combine(path, "MyApp.exe.config"));
        }
        catch (FileNotFoundException)
        {
            return;
        }

        XmlNamespaceManager manager = new XmlNamespaceManager(doc.NameTable);
        manager.AddNamespace("bindings", "urn:schemas-microsoft-com:asm.v1");

        XmlNode root = doc.DocumentElement;

        XmlNode node = root.SelectSingleNode("//bindings:bindingRedirect", manager);

        if (node == null)
        {
            throw (new Exception("Invalid Configuration File"));
        }

        node = node.SelectSingleNode("@newVersion");

        if (node == null)
        {
            throw (new Exception("Invalid Configuration File"));
        }

        node.Value = value;

        doc.Save(Path.Combine(path, "MyApp.exe.config"));
    }

-

修改config中的assemblyBinding

标签:ati   class   row   soft   mic   return   manage   dna   测试   

原文地址:https://www.cnblogs.com/runliuv/p/11653213.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!