2014-05-06 129 views
0

我已經安裝vs 2013,我正在嘗試創建自定義VisualStudio工具,但在建項目中,我應付這個錯誤:「Microsoft.VisualStudio.Shell.Interop,Version = 7.1.40304.0」未註冊COM Interop,請用regasm.exe/tlb註冊

The assembly "Microsoft.VisualStudio.Shell.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not registered for COM Interop. Please register it with regasm.exe /tlb 

我試圖regasm註冊它,但這不是固定我的問題,我的代碼如下所示:

[Guid("6ECD98B5-C7E5-462E-8922-24890A8F3FE1")] 
    [ComVisible(true)] 
    public class GPFDicKeyToEnumGenerator : BaseCodeGeneratorWithSite 
    { 
     protected override byte[] GenerateCode(string inputFileName, string inputFileContent) 
     { 
      return System.Text.Encoding.ASCII.GetBytes(
@" 
using System; 

namespace My.Name.Space 
{ 
    public class foo 
    { 
    } 
} 
"); 
     } 

     public override string GetDefaultExtension() 
     { 
      return ".cs"; 
     } 

     #region Registration 
     private static Guid CustomToolGuid = 
      new Guid("{6ECD98B5-C7E5-462E-8922-24890A8F3FE1}"); 

     private static Guid CSharpCategory = 
      new Guid("{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}"); 

     private const string CustomToolName = "GAMA.gpf.SDK.Tools"; 

     private const string CustomToolDescription = "Generate Enum of Keys for GPFDictionary"; 

     private const string KeyFormat 
      = @"SOFTWARE\Microsoft\VisualStudio\{0}\Generators\{1}\{2}"; 

     protected static void Register(Version vsVersion, Guid categoryGuid) 
     { 
      string subKey = String.Format(KeyFormat, 
       vsVersion, categoryGuid.ToString("B"), CustomToolName); 

      using (RegistryKey key = Registry.LocalMachine.CreateSubKey(subKey)) 
      { 
       key.SetValue("", CustomToolDescription); 
       key.SetValue("CLSID", CustomToolGuid.ToString("B")); 
       key.SetValue("GeneratesDesignTimeSource", 1); 
      } 
     } 

     protected static void Unregister(Version vsVersion, Guid categoryGuid) 
     { 
      string subKey = String.Format(KeyFormat, 
       vsVersion, categoryGuid.ToString("B"), CustomToolName); 

      Registry.LocalMachine.DeleteSubKey(subKey, false); 
     } 

     [ComRegisterFunction] 
     public static void RegisterClass(Type t) 
     { 
      // Register for both VS.NET 2012, 2013 (C#) 
      Register(new Version(11, 0), CSharpCategory); 
      Register(new Version(12, 0), CSharpCategory); 
     } 

     [ComUnregisterFunction] 
     public static void UnregisterClass(Type t) 
     { 
      // UnRegister for both VS.NET 2012, 2013 (C#) 
      Register(new Version(11, 0), CSharpCategory); 
      Register(new Version(12, 0), CSharpCategory); 
     } 

     #endregion Registration 
    } 

請幫我解決這個問題問題。

+0

你找到一個解決方案? – PeterFromCologne

+0

是的,我解決了這個問題。 –

+0

我改變了我用來註冊我的工具的方式,我用屬性 –

回答

0

我改變了我用來註冊我的工具的方式:

我使用的屬性類的樣子:

public class GPFToolAttribute : Attribute 
{ 
     /// <summary></summary> 
protected string _description; 

/// <summary></summary> 
protected string _name; 

    // Constructors 
    public GPFToolAttribute(){ 

    } 

public string Description 
{ 
    get { return _description; } 
} 

     /// <summary> 
/// 
/// </summary> 
public string Name 
{ 
    get { return _name; } 
} 

     /// <summary> 
/// 
/// </summary> 
/// <param name="name"></param> 
public GPFToolAttribute(string name) : 

    this(name, "") 
{ 

} 

     /// <summary> 
/// 
/// </summary> 
/// <param name="name"></param> 
/// <param name="description"></param> 
public GPFToolAttribute(string name, string description) 
{ 
    _name = name; 
    _description = description; 
} 
} 

和CodeGenerator類的樣子:

[ComVisible(true)] 
// TODO: Replace with your GUID 
[Guid("24BCC6BC-D53F-497B-8455-0BE15568E6B3")] 
[GPFToolAttribute("GPFEnumGenerator", "Generate an Enum conatins all the keys of a GPF Dictionary.")] 
public class GPFEnumGenerator : BaseCodeGeneratorWithSite 
{ 

    #region BaseCode generator methods 
    public override string GetDefaultExtension() 
    { 
     // TODO: Replace with your implementation 
     return ".cs"; 
    } 

    protected override byte[] GenerateCode(string inputFileName, string inputFileContent) 
    { 

      string generatedCode = "Your code here"; 
      return Encoding.UTF8.GetBytes(generatedCode); 
     } 
    } 
    #endregion 


    #region Registration 

    [ComRegisterFunction] 
    public static void RegisterClass(Type t) 
    { 
     GuidAttribute guidAttribute = getGuidAttribute(t); 
     GPFToolAttribute customToolAttribute = getCustomToolAttribute(t); 
     using (RegistryKey key = Registry.LocalMachine.CreateSubKey(
      GetKeyName(CSharpCategoryGuid, customToolAttribute.Name))) 
     { 
      key.SetValue("", customToolAttribute.Description); 
      key.SetValue("CLSID", "{" + guidAttribute.Value + "}"); 
      key.SetValue("GeneratesDesignTimeSource", 1); 
     } 
    } 

    [ComUnregisterFunction] 
    public static void UnregisterClass(Type t) 
    { 
     GPFToolAttribute customToolAttribute = getCustomToolAttribute(t); 
     Registry.LocalMachine.DeleteSubKey(GetKeyName(
      CSharpCategoryGuid, customToolAttribute.Name), false); 
    } 



    internal static GuidAttribute getGuidAttribute(Type t) 
    { 
     return (GuidAttribute)getAttribute(t, typeof(GuidAttribute)); 
    } 

    internal static GPFToolAttribute getCustomToolAttribute(Type t) 
    { 
     return (GPFToolAttribute)getAttribute(t, typeof(GPFToolAttribute)); 
    } 

    internal static Attribute getAttribute(Type t, Type attributeType) 
    { 
     object[] attributes = t.GetCustomAttributes(attributeType, /* inherit */ true); 
     if (attributes.Length == 0) 
      throw new Exception(
       String.Format("Class '{0}' does not provide a '{1}' attribute.", 
       t.FullName, attributeType.FullName)); 
     return (Attribute)attributes[0]; 
    } 

    internal static string GetKeyName(Guid categoryGuid, string toolName) 
    { 
     return 
      String.Format("SOFTWARE\\Microsoft\\VisualStudio\\" + VisualStudioVersion + 
      "\\Generators\\{{{0}}}\\{1}\\", categoryGuid, toolName); 
    } 


    #region Properties 

    internal static Guid CSharpCategoryGuid = new Guid("FAE04EC1-301F-11D3-BF4B-00C04F79EFBC"); 
    private const string VisualStudioVersion = "12.0"; 

    #endregion // Properties 

    #endregion Registration 
}