本文介绍了Visual Studio 2008代码片段未添加参考程序集和/或导入命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一些代码段,并且我体验到Visual Studio不会自动将引用添加到指定的程序集,也不会导入指定的名称空间。

I'm developing some code snippet, and I experienced that Visual Studio doesn't automatically add Reference to specified assembly and doesn't import the specified namespace.

我的代码段定义是:

    <?xml version="1.0" encoding="utf-8"?>
    <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
        <CodeSnippet Format="1.0.0">
            <Header>
                <Title>MyTryCatch</Title>
                <Shortcut>myTryCatch</Shortcut>
            </Header>
            <Snippet>
                <References>
                    <Reference>
                    <Assembly>MyAssembly.dll</Assembly>
                </Reference>
                </References>
                <Imports>
                    <Import>
                        <Namespace>MyNamespace</Namespace>
                    </Import>
                </Imports>
                <Declarations>
                    <Object Editable="true">
                        <ID>Message</ID>
                        <Type>String</Type>
                        <ToolTip>Error message</ToolTip>
                        <Default>message</Default>
                        <Function></Function>
                    </Object>
                </Declarations>
                <Code Language="csharp" Kind="" Delimiter="$">
    <![CDATA[try
    {

    }
    catch (Exception exception)
    {
        throw new MyNamespace.MyException("$Message$", exception);
    }]]>
                </Code>
            </Snippet>
   </CodeSnippet>
</CodeSnippets>
</CodeSnippets>

请注意,我所引用的是自定义MyAssembly.dll,可从添加引用弹出窗口中看到( .NET标签)。

Note that I'm referencing a custom MyAssembly.dll that is visible from "Add Reference" popup (.NET Tab).

当我通过 myTryCatch 快捷方式使用上述代码段时,可以看到代码段,但未添加参考,也未进行导入。

When I use the above snippet by myTryCatch shortcut, I'm able to see the snippet code but no Reference added and no Import made.

我该如何解决或调试此问题?

How I can fix or debug this issue?

谢谢!

推荐答案

听起来问题出在您选择的语言上。仅VB.Net支持参考程序集和从代码段导入名称空间。 C#引擎将忽略这些元素。

It sounds like the problem is your choice of language. Only VB.Net supports reference assemblies and importing of namespaces from a code snippet. The C# engine will ignore these elements.

参考:

这篇关于Visual Studio 2008代码片段未添加参考程序集和/或导入命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 17:21
查看更多