visual-studio - Visual Studio 2008 代码片段不添加引用程序集和/或导入命名空间

标签 visual-studio visual-studio-2008 code-snippets guidance-automation-tool

我正在开发一些代码片段,我发现 Visual Studio 不会自动添加对指定程序集的引用,也不会导入指定的命名空间。

我的代码片段定义是:

    <?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 选项卡)中看到该自定义 MyAssembly.dll。

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

如何修复或调试此问题?

提前致谢!

最佳答案

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

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

关于visual-studio - Visual Studio 2008 代码片段不添加引用程序集和/或导入命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8138385/

相关文章:

javascript - 如何在 sublimetext 片段中使用 $ 字符?

c# - RegularExpression 没有按预期工作 C#

c++ - 由于错误 C2244 : "unable to match function definition to an existing declaration",智能指针模板运算符重载失败

c# - 得到错误变量 <variable name> 未声明或从未分配

winforms - 更改整个应用程序的默认 Winform 图标

visual-studio-code - 如何在 VSCode 中禁用代码片段的 Enter 按钮

c# - 具有多个列表的列表<> c#

visual-studio - 将启动脚本添加到 Azure Web 角色 - "copy to output directory"丢失

windows - 卸载后安装 Visual Studio 2010 Service Pack 1 时出现问题

code-snippets - 如何在Headerdoc中标记代码片段?