• VS2005在开发Addin(外接程序)时自动生成的bug


    注:当前VS2008正式版只有英文版本,所以我的vs2005是中文版本,VS2008是英文版。



             我的VS2005一直无法使用Visual Studio 外接程序,也无法开发,不是写不出来,而是写出来了什么反应也没有。一直很纳闷,网上查了很多资料,没有找到解决办法。甚至于我专门花半天时间安装了VS2005 sp1。这个补丁叫个难装,430M不说,装起来贼慢贼慢的。而且如果你不会装,至少要装2-3次!为什么?要设置策略才可以装,要不然会提示个没有什么什么签名就装不下去了。当然这是我Window2003 EE sp2下的反应,其他系统不知道了就。
             不知道是不是我机器安装了VS2008的原因,我建立Visual Studio 外接程序是可以选择四个VS版本的,其中有2个是08的程序。
    mm.gif

    但是调试的时候就是死活没反应,我尝试把addin加到vs2008上面却出来了。

    以前一直没注意,还以为VS2005下难于配置,相当于放弃了开发点自己玩玩的小工具的想法。而现在突然可以在VS2008里使用了,在05里却不能用,莫非真的是2005存在缺陷?

    具体过程不说了,今天尝试调试一下,发现
        try
        {
         //若要将此命令移动到另一个菜单,则将“工具”一词更改为此菜单的英文版。
         //  此代码将获取区域性,将其追加到菜单名中,然后将此命令添加到该菜单中。
         //  您会在此文件中看到全部顶级菜单的列表
         //  CommandBar.resx.
         ResourceManager resourceManager = new ResourceManager("MyAddin1.CommandBar", Assembly.GetExecutingAssembly());
         CultureInfo cultureInfo = new System.Globalization.CultureInfo(_applicationObject.LocaleID);
         string resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools");
         toolsMenuName = resourceManager.GetString(resourceName);
        }
        catch
        {
         //我们试图查找“工具”一词的本地化版本,但未能找到。
         //  默认值为 en-US 单词,该值可能适用于当前区域性。
         toolsMenuName = "Tools";
        }

    toolsMenuName 根本得不到值,是null。怎么回事?

         //我们试图查找“工具”一词的本地化版本,但未能找到。
         //  默认值为 en-US 单词,该值可能适用于当前区域性。

    这句注释引起了我的注意,en-US ,那不是还有zh么?而我的VS是中文版本,估计就是中文版本下的问题吧。


    关键是不知道要怎么设置,关键语句是
    string resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools");
    构造了字符resourceName ,而这个字符 是取得toolsMenuName (= resourceManager.GetString(resourceName);)的关键要素

    如果贪图方便,直接把上述代码改成
    toolsMenuName = "工具";  就可以了。不过那样就又不支持英文版了。

    那么改下
         //若要将此命令移动到另一个菜单,则将“工具”一词更改为此菜单的英文版。
         //  此代码将获取区域性,将其追加到菜单名中,然后将此命令添加到该菜单中。
         //  您会在此文件中看到全部顶级菜单的列表
         //  CommandBar.resx.
         ResourceManager resourceManager = new ResourceManager("MyAddin1.CommandBar", Assembly.GetExecutingAssembly());
         CultureInfo cultureInfo = new System.Globalization.CultureInfo(_applicationObject.LocaleID);
         string resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools");
         toolsMenuName = resourceManager.GetString(resourceName);
    这部分,改成
         ResourceManager resourceManager = new ResourceManager("MyAddin1.CommandBar", Assembly.GetExecutingAssembly());
         CultureInfo cultureInfo = new System.Globalization.CultureInfo(_applicationObject.LocaleID);
         //string resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools");
          if(cultureInfo.TwoLetterISOLanguageName == "zh")
               toolsMenuName = "工具";
          else
                toolsMenuName = "Tools";


    这样就能解决问题了。不过是只适合在中英文环境下。

    我藏式用VS2008建立项目发现,2008这个地方改了。以下是2008生成的代码:
        try
        {
         //If you would like to move the command to a different menu, change the word "Tools" to the
         //  English version of the menu. This code will take the culture, append on the name of the menu
         //  then add the command to that menu. You can find a list of all the top-level menus in the file
         //  CommandBar.resx.
         string resourceName;
         ResourceManager resourceManager = new ResourceManager("MyAddin1.CommandBar", Assembly.GetExecutingAssembly());
         CultureInfo cultureInfo = new CultureInfo(_applicationObject.LocaleID);
         
         if(cultureInfo.TwoLetterISOLanguageName == "zh")
         {
          System.Globalization.CultureInfo parentCultureInfo = cultureInfo.Parent;
          resourceName = String.Concat(parentCultureInfo.Name, "Tools");
         }
         else
         {
          resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools");
         }
         toolsMenuName = resourceManager.GetString(resourceName);
        }
        catch
        {
         //We tried to find a localized version of the word Tools, but one was not found.
         //  Default to the en-US word, which may work for the current culture.
         toolsMenuName = "Tools";
        }
    这段代码是可用的。原来05比08差在少了个判断。


  • 相关阅读:
    ASP.NET MVC Framework 系列
    点站点链接出现短时间白屏或闪屏现象
    Asp.net Mvc Framework 一 (安装并建立示例程序)
    LINQ: Reconciling objects, relations and XML in the .NET framework
    乱学MonoRail A(问题随笔)
    可爱的MicrosoftAjax.js精简版(47K)
    成幻SNS(CHSNS#) 仿Facebook 风格发布,让您体验更专业的风格
    Asp.net Mvc Framework 二 (URL Routing初解)
    CHSNS# 1.05 正式发布 帮您创建您的Facebook
    Asp.net Mvc Framework 五 (向View传值以及Redirect)
  • 原文地址:https://www.cnblogs.com/birdshover/p/1009429.html
Copyright © 2020-2023  润新知