Visual Studio Default Open File Action - c#

I am using Visual Studio 2008 with C#. Is there a way to set the default editor for a class file containing a DataTable derived class? Whenever I double click on one of these classes to open the file VS attempts to open a component designer. Since my class isn't compatible with that editor this is a rather useless default. I would like these files to open up in the normal code editor.

In the solution explorer within VS you right click the file, select "Open With ...", select CSharp Editor in the window, then click the button to set as default.

You can disable Visual Studio designer for certain classes by using an
attribute.
[System.ComponentModel.DesignerCategory("")]
Credit goes to http://vanguard-against-confusion.blogspot.com/2007/05/disable-design-time-support-in-visual.html where I originally found out about this.
One interesting thing though is that if I just write
using System.ComponentModel;
[DesignerCategory("")]
it won't work in my VS2010. Does anyone know why?

Why not just go RightClick->View Code, OR once it's open in the designer press F7.

As a work around: Right-click, open-with...
Unless the class file has a different extension, I think you're stuck with this.
Edit: Could you make a small interim command line program that can determine the correct editor by looking at the content, and then open the file with that editor. Then associate that filetype with the interim program. This seems complex, but I've done it before in a similar case.

Related

Xamarin studio : class not visible, yet in solution

Has anyone had this issue:
I have a class for which code autocompletion works (it can see its members, properties, etc.), I can hit F12 and see the class code. But, the class cannot be seen in the solution explorer, nor can I add it because Xamarin Studio claims it has already been added to the solution.
Switching tabs in the notebook usually highlights the classes in the solution explorer, but for this single class, it doesn't work.
Any ideas ?
Thanks.
Your class already exists in the file system. In VisualStudio you can choose to show hidden files in solution explorer and include it back in to the project. In Xamarin Studio you could right click on solution and choose Open Containing Folder, find the file on the disk and delete it, so you can add it again.

Extend file renaming in VS 2010

I want to be able to rename classes with associated file in VS without loosing file history in Perforce.
I thought I could include an Perforce command (p4 move...) in file renaming of Visual Studio
or in class-renaming of ReSharper.
I see 3 options:
Wrap Visual Studio's file-renaming
I extend the file renaming (I mean with file renaming: right-clicking file in Solution Explorer and selecting Rename.) by an own VS add-in or a macro that wraps the existing Rename menu command and calls p4 move....
Extend Visual Studio's file-renaming
I extend the file renaming by any kind of hooking into existing Rename command.
Extend ReSharper's class-renaming
I extend ReSharper's class-rename action (Ctrl+R,R) (with enabled option: Synchronize file names accordingly to changes) by calling p4 move....
Which option is the best one to rename a class with associated file in VS without loosing file history in Perforce?
I have no experience with VS add-ins and ReSharper plug-ins. So if anybody knows that an option is not possible at all than a hint would help me very much.
Any idea?
You can extend file renaming in VS 2010 by using a macro for adding a "p4 move -k" action to the rename event.
See answer of "How to keep change history while renaming files in Visual Studio using Perforce".
This macro calls automatically a p4 rename/move when you do any rename or move action in Visual Studio. So you keep the file history in Perforce.
Git handles these types of changes pretty well. Could you move to using Git for your development and using Git-P4 to get the source into Perforce? I don't know Perforce so I'm unsure how well this solution works, but it is definitely something to look into.
Do you have the new P4VS plugin? I believe it supports renaming pretty well.

Visual c# nothing is appearing

This might sound extremly strange, but i have no idea what to do.
Visual studio 2008
c# windows form
I've been working on a project for a while, and it's all been rosy. Now, anything i add to the windows form in terms of labels, picturebox's ect don't appear at runtime. They are visible in the designer view, but do not appear at run time. Now, even when i move things that were already there, they don't move at runtime.
I'm guessing this is the cause of a windows update messing with visual studio again, but i can't find anything on the problem
Just a note, The project runs exactly how i left it yesterday every single time. Regarless if i move objects, add labels.
Anyone know of anything like this, know of a fix.
Thank you
I think you should Clean your solution and then rebuild it.
As you are using Express Edition, Clean option might not be added by default.
Go to Tools -> Settings and Select "Express Settings".
Now go to Tools -> Customize. And select Commands tab in the dialog.
In the dropdown next to Menubar radiobutton, select Build.
Click on AddCommands and add "Clean Solution".
Now you can go to Build -> Clean Solution. And then rebuild the project.
One time, I found the .suo file of the solution corrupted for unknown reasons.
Delete or rename it, then try again ?
The designer for classname.cs rewrites classname.designer.cs. View the code of the designer.cs and see if your changes are actually being saved into this file. Try hand-editing this file (change a label string or something else easy to spot at runtime).
Maybe the designer.cs file is read-only or perhaps there is a design-time exception that prevents saving the new .cs. I have run into issues like this when I had third-party component libraries in a project and the third-party designers were crashing.
Did you perhaps remove the call to InitializeComponent() from your Form class constructor?

Automatically call visual studio 2008 "sort using directives" on save?

Visual Studio 2008 got two great features for c#, which is called "sort using directives" and "remove unused using directives".
I'd like to call the "sort using directives" every time I format the code using ctrl+k,ctrl+d.
Or, even better, I would like to be able to reformat all c#-source files in a project, and call "sort using directives" for all source files.
How can I do this? Opening every cs-file by hand and typing these functions before every checkin is tedious!
You can do it all for a solution or project using "PowerCommands for Visual Studio 2008". After installation, you just need to right-click on a project or solution and "Remove and Sort Usings" is in the context menu.
EDIT: As noted in comments, there are also PowerCommands for Visual Studio 2010.
Another option is CodeMaid, a free and open source Visual Studio extension. It allows you to sort usings, remove usings, format document, remove/insert blank lines, remove whitespace, and quite a few more cleanups. It can run on save, solution wide, etc. Follow the link to the visual studio gallery to see more details.
It also lets you conditionally enable/disable individual portions, so with it you can disable remove unused usings and do sort only if you want as you mentioned in the comments.
Disclaimer: I wrote it ;)
ReSharper can do this for you (among other reformatting options) and it allows you to do an entire solution in one go.
I recommend you record a macro of you invoking the feature manually. Then you can just save the macro and put a button for it on the toolbar. This way you'll also have a foot in the door to get started really customizing your IDE.

In Visual Studio 2005/2008, why doesn't the ">open xxxxx.cs" shortcut work with forms?

In Visual Studio, there is a handy IDE shortcut for directly jumping to a file, i.e.
Ctrl + / (to select the Find combo-box)
Then type in >open myclass.cs
This is much quicker than navigating through the Solution explorer to open the specified class.
However, if you try and open the code part of a form (not the designer part) in this way then Visual Studio simply returns:
The operation could not be completed
... which means that I have to go through the Solution explorer to open them.
Is there any way to get this shortcut to work for forms, or is there some other shortcut?
Update: the problem seems to be with intellisense...
If I type >open form1.cs then this works...
But if I type >open form and then use the up and down keys to select from the intellisense, so that the combo reads >open "Form1.cs (OpenShortcutTest)" then that operation will fail.
Why not just use F7 to view the code behind? Maybe I'm missing something?
[edit]I just tried it in VS 2008 and ">open form2.cs" works fine.[/edit]

Categories