Moving an arbitrary setting to a toolbar in Visual Studio - visual-studio

I want to be able to modify a certain setting of Visual Studio right from the toolbar.
Specifically, the number of parallel builds (Tools | Options | Projects and Solutions | Build and Run | maximum number of parallel project builds).
It can be either an edit box right on the toolbar or two buttons setting it to certain values.
I use Visual Studio 2005.
Any suggestions?

Write macros which will modify the two settings, then put macro on toolbar using "Cusomtize"

(almost) any VS command or property has a corresponding scriptable object that you can call in macros.
Do Alt-F11, go into the macro editor, open the object model window and start sniffing around. You can use search to look for the relevant class/function for a given property (e.g. the number of builds). Once you find it, it's just a matter of writing a few VBA lines that change it and, as Ilya suggested, put that macro in your toolbar.
Btw, it should be possible to put an edit box in the toolbar to get the value; but it would probably be much easier just to call InputBox or something to ask the user for the input.

Related

Can I save multiple command arguments for VS2012 debugging

Summary: Is there an easy way to save alternate command arguments used by the Visual Studio debugger?
Details:
Visual Studio has an option to set Command Argument that are used by the debugger. For example in the screenshot shown here I've set them to FOO BAR. Sometimes when debugging a project I want to switch the arguments to test different input sets. And often the arguments are much longer than just FOO BAR. It would be nice if there was a way to save the arguments that I've typed and switch between them quickly. Ideally it would also be possible to change the working directory at the same time. But I haven't found a way to do this yet so that's why I'm asking here. I'm using Visual Studio Professional 2012.
You can just create new configuration(s) for this project. I see that your current active configuration is Debug (top left corner of project settings dialog). You can create new configuration(s), which will be based on this one, and name them like Debug-Test1, Debug-Test2, etc. After you will do this you will have a choice to switch between this configurations in VS Debug Toolbar.

Cleanup spacing - C++ / Visual Studio 2010

Is there a built-in feature or available add-on for Visual Studio 2010 that will clean up spacing in C++ code so that annoying blocks like this:
RandomVar=RandomList.RandomMethod();
will become
RandomVar = RandomList.RandomMethod();
(Same goes for spacing in loops, etc.)
...or do I need to do this myself with find/replace and regex?
I think You are looking for Edit->Advanced->Format document. This will re-format your current document according to settings in Tools->Options->Text Editor->c/c++->Formatting.
It's keyboard shortcut Ctrl+E+D in my case.
Although originally for C code formatting lint has been modified to cover C++ and ported to many platforms.
Some lint variants only report inconsistent layout, others can fix it for you. some are free others paid for versions.
This would be an outside the IDE fix as this is a sperate tool (at least traditionally it is!)
This wikipeadia article lists a few possible sources for lint tools
(this was a footer in my orginal question, but as that posed two solutions I extracted it here so you can accept a specifc answer should you find one apropriate)
This is not a proper "Solution" but a possible work-around without the need for finding external tools
In the "Tools" menu pick "Options..."
In this dialog navigate to
"Text Editor -> C/C++ -> Formatting"
Set the layout options as you
would like your code to look.
Click OK.
Now in a unit with "bad"
formatting from the menu select "Edit->Advanced->Format document" and the IDE wil reformat the
document to match your settings.
For C#, VB etc the "Formating" option has several sub nodes that provide a fine grain of control for the sort of spacing options you ask for. The list for C/C++ is flat and very limited by comparison. I suspect there is not enough flexability for the layout you want.
So you probably cannot get the formatting you want directly. How about...
Set the spacing rules you want for C++ in the C# settings
Temporarily adding a C# project to your solution
adding a class to that
emptying it.
paste the C++ in (causing a reformat)
copy back to the original file
rinse and repeat
remove the temporary C# project
I have to say this is not pretty, but given the syntactical similarities between C++ and C# its probably a close match.
The auto-formatting settings for C++ in Eclipse are more extensive than in Visual Studio, so I ended up using that instead.

How do I record a Visual Studio macro to set Options settings?

I've just tried to record a macro to help me switch word-wrap in editors on and off quickly, but all the macro records is DTE.ExecuteCommand("Tools.Options"), which leaves me with a big, dumb open dialogue when I try and execute the macro.
How can I record or write macros to help me quickly set options, without the rudeness of the modal options dialogue? Are there any extensions I could use for this?
For a bonus point, is there a way I can automate Options changes without using macros, and without having to write a big VS extension?
switch word-wrap in editors on and off quickly
Maybe I'm confused, but word wrap is toggled by Ctrl-E, Ctrl-W.
is there a way I can automate Options changes without using macros
You can use the Visual Studio command window here:
View > Other Windows > Command Window
In addition to the Visual Studio Commands list, you can enter any Menu command in the command window. I found Edit.ToggleWordWrap, which toggles word wrap in the currently-focused text editor.
To bind a command (or several commands) to a shortcut key, create an Add-In (not a big VS extension ;). In your case, the relevant line would look like this:
cmd = cmds.Item("Edit.ToggleWordWrap", 1);
There's really no way to record a macro to set anything in the Options dialog. The macro recording infrastructure in general can't handle modal dialogs and essentially ignores them. The options dialog is no exception here.
The best hope here is to
Save the options out to a vssettings file
Hand code a macro which manipulates the low level IVs interfaces to set the options you want.
The vssettings file is the more viable, and far simpler, option

How can avoid having a solution specific hard coded macro in Visual Studio?

Background
I have a macro AttachToRemoteProcess that I use to attach the debugger to a running process on a remote computer. The macro use hard coded names for the process and the computer. I use the macro from a toolbar button on a custom toolbar. I consider this a sub par solution and I don't really like to have such a macro in my Visual Studio environment since it only works for the specific program/environment it was hard coded for.
I am using Visual Studio 2008.
Solutions
I can imagine two solutions but I do not know if they are possible to implement.
Alternative 1
I would like to either have the macro AttachToRemoteProcess being part of the solution (.sln) or one of the projects (.csproj) and have the toolbar appear when the solution or project has been loaded into Visual Studio. In this case it is OK to have hard coded settings such as process and computer name.
Alternative 2
The macro AttachToRemoteProcess is made reusable by taking process and computer as parameters.
The custom toolbar, button and the macro are always available in Visual Studio. This is just like my current solution, except for the parameterized macro.
When the button is clicked the computer name and process name is looked up from somewhere in the solution or the current project.
Questions
Would any of the alternative work and how can I go about doing it?
Are there any other alternative solutions for what I want to achieve?
The second alternative seems to work. Instead of retrieving the parameters from the solution (perhaps using VBA and the class EnvDTE.DTE.Solution), you could display a small form to select the process and computer and use this input as parameters to your macro. The button would be displayed in a personal toolbar all the time.
I'm not sure whether you can "attach" macros to particular solutions. If that's not possible, you will have no way to implement alternative 1.

How to control VS window positions and state from a macro

I want to set up some hotkeys in Visual Studio to control the window layout.
For example, F10 would collapse all windows (such as the command from the windows main menu called - Auto Hide All) and then F11 which would dock and position certain windows of my choice at certain positions. This would be so I can jump to specific layouts quickly.
So how to control window layout from visual studio macros?
Probably not optimized but couldn't you consider using vssettings and Import/Export Settings to achieve your goal? (I know this isn't exactly the answer to your question...)
****Update****
You can check out my blog post which provides the ability to list and switch window layouts in Vs2008 and Vs2010: http://www.brianschmitt.com/2010/09/save-and-change-tool-layout-in-visual.html
****Old Answer Below****
If you are looking for a repeatable setup, then a Macro may be your best option. AutoHideAll may already be bound to CTRL+Shift+~ - I cannot remember if that is the default. If not, you can bind it in your Tools-->Options-->Keyboard dialog. In there you can also bind the Macro below to your F11.
Here is a Macro that will accomplish the layout for you:
Public Sub SetupMyPersonalLayout()
DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Visible = True
DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).AutoHides = False
DTE.Windows.Item(Constants.vsWindowKindTaskList).Visible = True
DTE.Windows.Item(Constants.vsWindowKindTaskList).AutoHides = False
End Sub
This will show the window and then "pin" it.
Another option that comes to mind is to take advantage of the different views that Visual Studio offers (Standard, Full Screen, Debug, and some others).
Lastly, if you are on 2005 or earlier (or if you want to update the code) there is an add-in that will do it for you: http://www.codeplex.com/VSWindowManager

Resources