VS13/VS15 - can't import SQL snippet
Asked Answered
T

3

2

I would like to create SQL snippet in VS2013 and VS2015. I don't know why, but I've got an error while importing (in both of VS):

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

My snippet:

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

What's wrong? The language SQL should be OK https://msdn.microsoft.com/en-US/library/ms171418.aspx#code

I tried to add this snippet to language "Miscrosoft SQL Server Data Tools, T-SQl..." If I've changed the language attribute to e.g. CSharp it works.

Tiptop answered 29/7, 2016 at 11:39 Comment(0)
P
0

Instead of:

<Code Language="SQL">

Write:

<Code Language="SQL_SSDT">

Visual Studio supports only MSSQL Server Data Tools & T-SQL Language Scripts, not SQL like SSMS does.

Parshall answered 29/7, 2016 at 13:8 Comment(0)
J
0

Try this.

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

You could also check this out if it works but still gives a warning.

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.

Japan answered 29/7, 2016 at 11:43 Comment(1)
I tried this and it doesn't work as well (in VS13 and 15). Did anyone try to add sql snippet in VS?Tiptop
P
0

Instead of:

<Code Language="SQL">

Write:

<Code Language="SQL_SSDT">

Visual Studio supports only MSSQL Server Data Tools & T-SQL Language Scripts, not SQL like SSMS does.

Parshall answered 29/7, 2016 at 13:8 Comment(0)
I
-1

The language attribute value you used, SQL, is correct. From the VS2015 Code Snippets Schema Reference:

enter image description here

Errors such as you're seeing can happen if you're editing a snippet file directly in one of the folders known by the Code Snippets Manager. Evidently Visual Studio holds its own metadata in addition to what's in the snippet XML itself. For this reason, it can be best to do the edits in a temporary folder and then use the Import button.

For example, I kept getting the error "Missing or unspecified Language attribute" when saving any edit to my new C# snippet in the My Code Snippets folder—or so I thought. Turned out I was in the Visual Basic\My Code Snippets folder, and there's also a Visual C#\My Code Snippets folder which is where I should have been. This was a silly mistake but it illustrates that the "Language" XML attribute isn't enough, as Visual Studio has its own internal conventions to do with different folders for different snippet types (and who knows what else) which all happens when the Import button is used.

I removed my snippet file to a temporary location, and then added it from there using the Import button. As soon as I did this, the problem went away and the snippet started working normally.

Inopportune answered 13/7, 2018 at 16:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.