Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

There's a way to create a code snippet with automatically create a using reference?

I created a simple code snippet in c# which add the line

Debug.WriteLine("");

now the next step would be, when you use the snippet, to autocreate

using System.Diagnostic;

is there any way to automatically create the reference? I tried and set the snippets Reference and Import elements this way:

<Snippet>
  <References>
    <Reference>
      <Assembly>System.dll</Assembly>
    </Reference>
  </References>
  <Imports>
    <Import>
      <Namespace>System.Diagnostic</Namespace>
    </Import>
  </Imports>
      .
      .
      .
</Snippet>

but it doesn't work

like image 277
Fabio Marcolini Avatar asked Jul 01 '13 15:07

Fabio Marcolini


People also ask

How do I create a code snippet in Vscode?

To create or edit your own snippets, select User Snippets under File > Preferences (Code > Preferences on macOS), and then select the language (by language identifier) for which the snippets should appear, or the New Global Snippets file option if they should appear for all languages.

Which option needs to be used to generate code snippets?

On the menu bar, choose Edit > IntelliSense > Insert Snippet. From the right-click or context menu in the code editor, choose Snippet > Insert Snippet.

How do you use a snippet code?

Or, instead of using the Code Snippet Picker, use the short cut by typing “prop” in the code window and then press the Tab key. (You may need to press the Tab key twice if the auto list members drop down is open.) The following code is automatically inserted into the code window.


1 Answers

Unfortunately, Import only works for VB projects. It is explained on MSDN.

like image 193
Abe Heidebrecht Avatar answered Nov 07 '22 15:11

Abe Heidebrecht