VS13/VS15 - 无法导入 SQL 片段

VS13/VS15 - can't import SQL snippet

我想在 VS2013VS2015 中创建 SQL 片段。我不知道为什么,但我在导入时出错(在两个 VS 中):

"C:\sql.snippet: Missing or unspecified Language attribute"

我的片段:

<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2008/CodeSnippet">
<CodeSnippet Format="1.0.0">
    <Header>
        <Title>
            My Snippet
        </Title>
    </Header>
    <Snippet>
        <Code Language="SQL">
            <![CDATA[select * from MyTable]]>
        </Code>
    </Snippet>
</CodeSnippet>

怎么了? 语言SQL应该没问题https://msdn.microsoft.com/en-US/library/ms171418.aspx#code

我尝试将此代码段添加到语言 "Miscrosoft SQL Server Data Tools, T-SQl..." 如果我将语言属性更改为例如CSharp 有效。

试试这个。

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
    xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>
                My Snippet
            </Title>
        </Header>
        <Snippet>
            <Code Language="SQL">
                <![CDATA[select * from MyTable]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

你也可以检查一下它是否有效但仍然给出警告。

http://providersweb.blogspot.se/2016/01/visual-studio-snippets-missing-or.html

I have been getting a list of messages in the Snippets output window when I load a project that a number of snippets had a 'missing or unspecified language attribute' and could not figure out why these messages appeared. I had checked the Language attribute on the snippets and they were correct, but still got the message. I had set up folders for each language type, but still got the messages. I finally figured out that I had specified they all were VB snippets in the Snippet manager and those that were not VB would cause the messages in the output window, ie when loading a VB project, the CSharp snippets would generate the error message. I fixed this by going into the snippet manager and specifying the Language, VB or CSharp, and adding the snippets to the correct language and removing them from the invalid language. And now these messages of invalid language attributes do not appear on my output screen.

而不是:

<Code Language="SQL">

写入:

<Code Language="SQL_SSDT">

Visual Studio 仅支持 MSSQL 服务器数据工具和 T-SQL 语言脚本,不像 SSMS 那样SQL。

您使用的语言属性值 SQL 是正确的。来自 VS2015 Code Snippets Schema Reference:

如果您直接在代码片段管理器已知的文件夹之一中编辑片段文件,就会出现您所看到的错误。显然 Visual Studio 除了片段 XML 本身的内容之外,还拥有自己的元数据。因此,最好在临时文件夹中进行编辑,然后使用“导入”按钮。

例如,在将任何编辑保存到 My Code Snippets 文件夹中的新 C# 代码段时,我一直收到错误 "Missing or unspecified Language attribute" — 或者我是这么想的。原来我在 Visual Basic\My Code Snippets 文件夹中,还有一个 Visual C#\My Code Snippets 文件夹,这是我应该去的地方。这是一个愚蠢的错误,但它说明了 "Language" XML 属性是不够的,因为 Visual Studio 有自己的内部约定来处理不同片段类型的不同文件夹(谁知道还有什么)当使用“导入”按钮时,所有这些都会发生。

我将代码片段文件删除到一个临时位置,然后使用“导入”按钮从那里添加它。一旦我这样做了,问题就消失了,片段开始正常工作。