Code-Snippet not refreshed in Visual-Studio - visual-studio

I am creating Code Snippet in Visual-Studio 2010 using "Snippet Editor". All is working fine when i first save the snippet in the folder ... Visual Studio 2010\Code Snippets\Visual C#\My Code Snippets.
The snippet is executed when i do CTRL-K CTRL-X and choose it in the list, and also by intellissence using the snippet Shortcut.
My problem comes when i only change the code of the snippet and save it again :
the new code is executed when i hit CTRL-K CTRL-X
the old code is executed when using intellisense ??
the problem is still here when i reopen VS
I don't think this is a "Snippet Editor" issue. Is there any "Intelissence Cache" i would have to reset ?

I have the same issue in visual studio 2019.
I have a custom ( My Code ) snippet file with multiple CodeSnippet elements added with the Code Snippets Manager and recognized and working in visual studio.
I make two changes.
The first I add a comment to an existing CodeSnippet just to demo that the change has been recognized.
I then change the Shortcut element of another CodeSnippet and completely change the Code.
Import again with Code Snippets Manager and Overwrite.
Use both snippets.
The first now has the additional comment.
The second does not have the code that is in the CDATA of the Code element but has what was there before !
Put the two CodeSnippet elements in separate snippet files and all ok.

Seems to be a bug in Visual Studio 2010, no more problem on the next version of VS

Related

Add custom code snippet to visual studio intellisense

There is this nice program that enable you to easily create code snippets. I already managed to create snippets but it will be nice if the snippet where to show up in visual studio's intellisense.
For example visual studio already has several built in code snippets such as the one for creating the constructor of a class:
note that it was really easy and fast to use it.
On the other hand when I create my custom snippet with the program that I provided on the first link, these are the steps that I have to do in order to use it:
on step 3 I have to select the folder where the snippet that I created is located then on step 4 locate it.
It will be nice if I could use the code snippet that I created just like the ones that visual studio provides like the constructor one that I showed on the first image. Maybe if I place the snippet that I just created and place it where visual studio store the built in onces it works.
I had to add a shortcut to the snippet.
after adding the shortcut it appears on the intellisense without having to navigate to the folder where it was located by pressing ctrl+k and ctrl+x

Visual studio 2010, how to use code snippets in a method call

I moved from Visual Studio 2008 to Visual Studio 2010.
My code snippets work good in Visual Studio 2010 on the start of a line, but not when adding parameters to a methodcall. This did work in Visual Studio 2008.
So when i type this : "DoSomeMethod([nowiwantmycodennippets!]", the code snippets are not in the intellisense list.
Does anyone know if this is a setting, or just not working anymore, and if it can be fixed?
This appears to be bug. If you type your snippet name (i.e. noiwantmycodesnippets) and press ESC to dismiss the completion list (if open), then you can press Tab to insert your code snippet. So it's just a matter of the code snippets missing from the completion list.
You can use the Control+K, Control+X key chord to show the code snippets' list also. But this isn't as nice as using it through the completion list.
Are you using ReSharper? If so, Resharper Intellisense overwrites the VS default one, so that i.e. code snippets do no appear in the completions. Try turning off ReSharper Intellisense in the ReSharper Options (Environment->Intellisense->General, choose Visual Studio).
If ReSharper Intellisense is a must, you'll have to create a ReSharper "Live Template" which opens up for "code snippets" behaviour, only ReSharper is way more advanced -- see for example this one http://www.brianlow.com/index.php/2009/04/06/resharper-live-templates-for-nunit/.
On my machine I just type "public void Test(" and than ctrl+space and type the name of my snippet. Works like a charm. I've got the C# keyboard shortcuts, I think.

Missing snippet in Visual Studio

I have the same installation of Visual Studio on two machines, but on one, I can't find the snippet "propdp" for DependencyProperty. I only have prop/propg, can't really understand why. Is there an addon I have to install?
Came across this same issue myself today after a fresh install of VS2008 on Win7 64
All I had to do to fix it was to
Go to Tools > Code Snippets Manager
Select Visual C# from the drop down menu
Click Add
Select the NetFx30 directory containing the code snippets, in my case it was...
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC#\Snippets\1033\NetFX30
You should immediately be able to use the code snippet.
I think ReSharper hides some of the default snippets. It should be enough to enter the snippet and press tab twice.
In my case, the snippet showed up in IntelliSense but nothing worked on selecting it and pressing enter or clicking on it, until I pressed tab+tab then it work. (I guess I was used to CodeRush).
Just in case anybody have this problem and the previous answer didn't fix it, if you have two folders inside C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC#\Snippets: 1033 and 3082. Copy and paste the whole content from one to the other and started to work.
Trying to import didn't fix it for me but maybe I didn't do it right... don't know...
I found it here: https://stackoverflow.com/a/36829804/5761877 (thanks be given to "elmonopascual")
I'm using VS2017 and had the same problem. The only thing that worked for me was:
Go to Tools > Code Snippets Manager
Select CSharp from the dropdown menu
Remove all folders in the listview (save the complete path of them for later steps)
Hit OK
Reopen the Code Snippets Manager
Select CSharp from the dropdown menu
Insert all the folders again with the Add button.
If I don't close and reopen the Manager before add the folders again, the VS2017 will crash and restart when I hit OK, and the snippets still won't work.
in my case i went to tools -> Code Snippet Manager, i realized that the path to the snippet i wanted has changed. So when the Path has changed the Snippet folder will be shown with an error. So i copied the Path and followed until i found out where it was missing. Then i browsed all the folders until i located snippet i wanted and my issue was solved.

Visual Studio 2008 doesn't generate itself code for added control in .aspx.designer.cs

I added a control on my .aspx page and set Id and runat=server for it but, it doesn't render on my page when I open it in browser as well it doesn't generate code for it in designer file.
Try that:
1) Remove your_page.designer.cs file.
2) Go to the ASPX page and cut markup, then paste it.
This should force Visual Studio code generation from scratch.
Another try would be check that your control compiles. Sometimes the whole control doesn't compile and you can't add it to the page with success.
Finally, if non of these works for you, you can clean and rebuild your Visual Studio solution.
Matias's appraoch should work another way of doing this is:
Delete the designer.cs file that is causing issues
Right click on the aspx file and "make application" (or something to that effect)
This will regenerate the file.

IntelliSense has forgotten my code snippets!

I have a stack of code snippets imported into Visual Studio. Just recently, they have stopped displaying in Intellisense.
If the keyboard shortcut doesn't bring up anything else on IntelliSense, then I can tab and the code snippet is inserted just fine.
However, if the keyboard shortcut for the snippet happens to also bring up other items in IntelliSense, tabbing will select the first of those items, so I actually can't use the code snippet at all!
Does anyone have any ideas why IntelliSense would be unable to list my code snippet shortcuts? I started using ReSharper recently, but that wouldn't be the problem surely?!
Thanks for your help
David
It is certainly connected to installing Resharper. First thing it does is turn IntelliSense off. Check this question for help with preserving your snippets.
I know I am late to the party but you can use snippet editor to copy your snippet then paste it into Resharper through the live template editor. The code appears to be compatible. I did that with several of mine and it works just fine.
Since ReSharper 4 Visual Studio code snippets are imported into ReSharper as live templates. That means you can invoke any code snippet by pressing Ctrl+J.
All the scripts imported in Vs are available on this popup menu.

Resources