Overwriting default Code Snippets - c#

I have been making several improvements on code snippets that are typically built into VS2010. Is there any way to either "prefer" certain snippet directories over others, or to overwrite the defaults without manually removing the references from the Code Snippets window? I would like to keep the same shortcuts.
This is mostly nit-picking, since I could remove the .snippet files manually, or remove the folder references, but I'm wondering if there is an easier way, incase I end up replacing a large amount of the default snippets yet still want to keep others.
There are two issues that come up when having similar shortcuts on code snippets.
For some snippets, such as propdp, you will be prompted that there are multiple snippets, and be asked to choose which one is appropriate.
For other snippets, such as ctor, it just uses the default snippet and pretends my own doesn't exist. Browsing the snippets using Ctrl+K,Ctrl+X clearly shows the snippet works, and the shortcut is correct.
The second issue here is a larger concern than the first.
Edit: Further experimentation shows that ctor in particular uses the default snippet no matter what. I haven't tried overwriting the code in the original snippet file, but removing the reference to Visual C# snippets folder still uses the default and ignores my replacement.
Edit 2: Even replacing the original snippet, ctor uses the default and ignores the .snippet file. This is after restarting Visual Studio as well. Now I have no idea where it's even retrieving this code snippet from. As a test, you can rename the snippet ctors and it will display properly. ctor is no longer a suggestion at this point. If you rename it back to ctor, it will once again display the default snippet. Either this snippet is cached somewhere, or it's built in to VS2010.

Have you tried simply overwriting the original files, replacing the snippet with your own?
They're located here: C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC#\Snippets\1033\Visual C#

On my system, the C# snippets are stored in two places at least:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC#\Snippets\1033\Visual C#
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC#\Snippets\1033\Visual C#
I think you're right that Microsoft's snippets always "win" when you have snippets in other directories, so to use customized snippets, you end up having to overwrite the originals. But every couple of weeks when an update to Visual Studio is released, the update will obliterate your versions in favor of MS's. (Why did they bother to expose this functionality if they're going to disrespectfully ignore or obliterate your customizations?)
I ended up just writing a program that starts running at login time to watch these two directories. When something changes in one of them, it compares the snippets there to ones I have stored in a "snippet override" directory, and if they aren't the same, it restores my versions of the snippets.

Have you looked at the plug-in for Code Barrel? It has revision support, tagging, etc... Looks like that may be what you need. ~shrug~ it is free, so is the plugin, go to codebarrel.com to get it.

Related

Merge two versions of C# projects

I am working on documenting a winForms project that isn't completely done being written, meaning there is another programmer who write the code right now. So I've already wrote some importent comments in a copy of the project.
In addition I use sandcastle to bulid the help file.
My question: what is the best way (if there is one) to copy the comments from the old copy of the project to the new version of it?
Maybe sandcastle can do something like import a documentation to a project?
I know it wasn't so smart to do so, still I have to check if there is a way to save the documentation work.
Visual Studio has a built in file difference function you can use to see where the two files are different. It should be then a matter of copy and paste of the changes you have made over to the "gold" copy of the file your other programmer has changed.
This link shows how to Compare two files in Visual Studio 2012
"You can invoke devenv.exe /diff list1.txt list2.txt from the command prompt or, if a Visual Studio instance is already running, you can type Tools.DiffFiles in the Command window"

How to run the code generated by Altova Mapforce in Visual Studio?

I am using MapForce for the first time. I was able to successfully create an XML mapping. However, I am not sure how to run the generated code in Visual Studio, so that I can use it and see the output. I generated the code for the mapping in C# and did try to run the "Mapping" Project in VS.
Unfortunately, I am not able to due to few errors. There isn't a good documentation on the folders that are created in the project. If I can get a documentation link that I can refer to or if somebody can define why those folders are there and how can I use them/ how I should be running those projects.
Please correct me if I am wrong anywhere.
If you generated code to C:\MyFolder\, then you need to open in Visual Studio the solution C:\MyFolder\Mapping\Mapping.sln. Note that the "Mapping" is the default name, if you configured it to be something else from MapForce settings, then it may be different.
Solutions in other generated folders are supporting libraries, and you should never edit them (or at least do so at your own risk). The only file you can (but you don't normally need to) modify is called MappingConsole.cs. For example, you may want to change the paths of the mapping input/output files. In any case, after you build and run the solution, a Mapping.exe application is created in the Bin\Debug folder.
It would have been helpful if you indicated which errors you get. Perhaps the paths to the mapping input files cannot be resolved relative to the Mapping.exe application?

Visual Studio testc, how to get rid of it?

I could have asked this question years ago, but I think it has finally annoyed me enough to ask this question. Many times while I am coding, Visual Studio tries to Intellisense my deal with testc. I know that testc is a snippet for a test class, but it is something I will never use in anything except maybe a test project, and likely not even then. So, how do I prevent this annoyance from ever appearing in my Intellisense options again? Yeah I know... stupid thing to worry about...
On the Tools menu, click Code Snippets Manager.
Select the directory Test.
Click Remove.
Press CTRL + K, CTRL + B. This will bring up the code snippets manager. In the Visual C# directory, you can remove the snippets (testc in your case) that you don't want to include. Note that system generated snippets cannot be removed by this method, although per mojits answer you could remove the entire directory of snippets.
One way around this is to delete the snippet file manually, by finding / deleting its actual file. I am using Visual C# express 2010 right now, and this is the directory they are in for me (you may have to modify slightly, and restart VS for changes to take effect).
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC#\Snippets\1033\Visual C#

MS VS 2012. my code is not showing up (C#)

I am working on a project and while compiling, my laptop handed up and I have to turn it off manually.
After the restart I found that my code is not showing up. There is no line of code in program.cs file.
I am working on that code since a month. And all of it vanished.
Need help. I have the executable file working properly. But i need the code. Is there any way to find that code ?
Use ILSpy to decompile your executable. You will get the source code back, minus the comments. This is possible because assemblies (like your exe) actually contain "Intermediate Language" (IL), and not native machine code/assembler. From the IL it is possible to get a reasonable representation of the original source code. You may need to recreate the csproj file manually, if you do not have it.
If you have the .exe you must have compiled it, if you compiled it you must have saved it.
Where it is depends on where you saved it. Easiest thing would be to use the search function in Windows – search for whatever you called your program, or failing that, *.csproj. Then you can open the csproj file with Visual Studio and you should get most of it back.

Long load time in Visual Studio for Large Project

Is there a way to turn off intellisense in Visual Studio 2008? I know about deleting a DLL to turn off intellisense in C++, but that doesn't work for C#. I also know about the preferences but that just turns off the visual display. I want to turn off ALL of intellisense so it does not scan my code at all.
Update 10/14/09: Eric was kind enough to take a look so I sent him some log info. I'll post the resolution here when we get one.
Update: updated title to reflect the changed direction of the thread
Related Question
Turning off Intellisense for a single project in Visual Studio 2008
The guys on the VS team looked at this for me and found a problem with intellisense. Here's their description:
"It looks like both of the files you gave me contain a part of static partial class EntityPropertyDescriptors, and I would guess that all the rest of the 500 files do too. What’s happening is that as we build up our IntelliSense cache, each time we parse one of these files, we see that it has a static class in it, and we decide to see if that static class has any extension methods. In order to look for the extension methods, we look through each method in each part to see if it’s an extension method. This causes us to reparse every file in order to see if the type has any extension methods."
They found a similar problem with VS2010 but are fixing it now. Unfortunately, they are not going to fix it in VS2008, so we are left with the workaround of putting all the partial classes into a single file. They can still be partials, but they must be in the same physical file to get around the problem.
After combining all partial classes into a single file, load time for this problem project when from 30 minutes to about 10 seconds.
Big thanks to Eric Lippert and Kevin Pilch-Bisson for helping me with this.
You need to switch off background compilation.
Here is a HowTo:
http://ira.me.uk/2008/09/01/switch-offon-visual-studio-2008-background-compilation/
Tools -> Options -> Text Editor -> C# -> Advanced -> Show live semantic errors
You will still get error underlining, but you must hit the Build button before they show up.
In tools > options > Text Editor > C# there is a Intellisense section which looks like it does what you want.
Have you tried cleaning your solution from all temporary files created by Visual Studio? Sometimes these files could get corrupted, the chances might especially be high if you migrated from VS 2005.
Close your solution, look for all *.suo and *.ncb files and remove/rename them, and then re-open the solution.
Just another thing to make sure: Are there any third-party add-ins installed? Try to start VS in SafeMode using the /SafeMode command-line option.

Categories