Visual Studio 2010 加载项问题

发布于 2024-11-29 04:10:12 字数 2239 浏览 1 评论 0原文

我刚刚创建了一个程序集和一个 Visual Studio 加载项,如下所示:

首先,程序集

  • File =>新项目
  • 新类库

在我将“Class1.cs”文件的内容更改为

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClassLibrary1
{
    public class Class1
    {
        public void Test()
        {
            Console.WriteLine("Wohooo!");
        }
    }
}

现在,加载项

  • 文件=>;新项目
  • Visual Studio 加载项 单击向导

“Connect.cs”文件的内容更改为:

public class Connect : IDTExtensibility2, IDTCommandTarget
{
...
    public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
    {
    // Adding a button to thet tools menu
// i can provide the source if needed
    }           

    public void QueryStatus(string commandName, vsCommandStatusTextWanted neededText, ref vsCommandStatus status, ref object commandText)
    {
        if (neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
        {
            status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported |
                     vsCommandStatus.vsCommandStatusEnabled;
        }
    }

如果我从 Exec 方法调用新类,则不会发生任何情况。 (没有调试断点被触发)

    public void Exec(string CmdName, vsCommandExecOption ExecuteOption, ref object VariantIn, ref object VariantOut, ref bool Handled)
    {
        Action action = GetAction(CmdName);

        if (CmdName == "MyAddin2.Connect.SampleAddin2")
        {
            new ClassLibrary1.Class1().Test();             
            Console.WriteLine("");
        }

        Handled = true;
    }

如果没有,它可以工作!

    public void Exec(string CmdName, vsCommandExecOption ExecuteOption, ref object VariantIn, ref object VariantOut, ref bool Handled)
    {
        Action action = GetAction(CmdName);

        if (CmdName == "MyAddin2.Connect.SampleAddin2")
        {
            // new ClassLibrary1.Class1().Test();             
            Console.WriteLine("");
        }

        Handled = true;
    }

但是为什么呢?问题是什么 ?

提前致谢!!

I just created a Assembly and a Visual Studio Add-In like this:

At first, the assembly

  • File => New Project
  • New Class Library

After i have changed the content of the "Class1.cs" file to

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClassLibrary1
{
    public class Class1
    {
        public void Test()
        {
            Console.WriteLine("Wohooo!");
        }
    }
}

And now, the Add-In

  • File => New Project
  • Visual Studio Add-In
  • Clicking through the Wizard

After i have changed the content of the "Connect.cs" file to:

public class Connect : IDTExtensibility2, IDTCommandTarget
{
...
    public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
    {
    // Adding a button to thet tools menu
// i can provide the source if needed
    }           

    public void QueryStatus(string commandName, vsCommandStatusTextWanted neededText, ref vsCommandStatus status, ref object commandText)
    {
        if (neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
        {
            status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported |
                     vsCommandStatus.vsCommandStatusEnabled;
        }
    }

If i call the new class from the Exec Method, nothing happens. (No debug break point get fired)

    public void Exec(string CmdName, vsCommandExecOption ExecuteOption, ref object VariantIn, ref object VariantOut, ref bool Handled)
    {
        Action action = GetAction(CmdName);

        if (CmdName == "MyAddin2.Connect.SampleAddin2")
        {
            new ClassLibrary1.Class1().Test();             
            Console.WriteLine("");
        }

        Handled = true;
    }

if not, it works!

    public void Exec(string CmdName, vsCommandExecOption ExecuteOption, ref object VariantIn, ref object VariantOut, ref bool Handled)
    {
        Action action = GetAction(CmdName);

        if (CmdName == "MyAddin2.Connect.SampleAddin2")
        {
            // new ClassLibrary1.Class1().Test();             
            Console.WriteLine("");
        }

        Handled = true;
    }

But why ? What is the problem ?

Thanks in advance!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

皇甫轩 2024-12-06 04:10:12

检查“用于测试”插件文件中的程序集标记。
检查它指向的文件夹以及该文件夹是否包含“ClassLibrary1.dll”。我在此处遇到了类似(或相同)的问题。

Check Assembly tag in "For - Testing" addin file.
Check the folder it points to and if that folder contains 'ClassLibrary1.dll'. I had a similar (or identical) problem here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文