Visual Studio 2008 code snippet doesn't add Reference Assembly and/or Import Namespace

心不动则不痛 提交于 2019-12-24 03:32:46

问题


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.

My snippet definition is:

    <?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>

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

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?

Thanks in advance!


回答1:


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.

Reference: http://msdn.microsoft.com/en-us/library/ms171438.aspx



来源:https://stackoverflow.com/questions/8138385/visual-studio-2008-code-snippet-doesnt-add-reference-assembly-and-or-import-nam

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!