Some of our projects call for default Visual Studio tab options (width 4; keep tabs); some call for width 3; use spaces. Don't ask.
Rather than set these globally, is there anyway in which I could set this on a per-solution or per-project or even (emacs-style) per-file?
Visual Studio 2005 and 2008.
The most convenient solution I know is to create a set of Visual Studio macros to switch to the settings you want.
Go to Tools > Macros > Macros IDE. There, in the tree on the left, right-click MyMacros and choose Add > Add Module. Give the module a name such as TabSize. Within this module, create subs to change the settings you want. For instance:
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module TabSize
Sub Tab3()
SetTabAndIndentation(3)
End Sub
Sub Tab4()
SetTabAndIndentation(4)
End Sub
Function SetTabAndIndentation(ByVal value As Integer)
DTE.Properties("TextEditor", "AllLanguages").Item("TabSize").Value = value
DTE.Properties("TextEditor", "AllLanguages").Item("IndentSize").Value = value
End Function
End Module
There is no useful documentation I know of for the string parameters. If you need to set other options, such as "Keep Tabs", the easiest approach is to make these changes manually (unter Tools > Options). Then, using Tools > Import and Export Settings, save these settings as a vssettings file. This creates an XML file whose structure is the same as that needed for the method calls.
Finally, you can link these macros to command buttons or keyboard shortcuts via Tools > Customize. Giving each macro a keyboard shortcut allows you to quickly toggle between settings.
I have a similar problem: my new project needs to be set up with keep tabs, while my other projects are developed with insert spaces option.
Since this is a strictly Visual Studio setting, i didn't expect to find any per-project information that will empower this (either if one use a specific add-in for that purpose).
So i ended up having eclipse-like setup: having two shortcuts to Visual Studio with different settings each.
According to MSDN, one can use /ResetSettings switch to change the Visual Studio settings upon startup. What you need now is two shortcuts with this format:
devenv.exe /ResetSettings "d:\your-settings.vssettings"
The starting time is like 5-10 seconds longer (since it applies the change settings on every startup) but it's more convenient and less cumbersome than doing it manually, every time.
HTH
You can also use these properties to complete Daniel's example :
DTE.Properties("TextEditor", "AllLanguages").Item("InsertTabs").Value
DTE.Properties("TextEditor", "AllLanguages").Item("IndentStyle").Value
I know I'm a bit late to the game:
Since Visual Studio 2017, there's support for .editorconfig files in the IDE on a per-directory basis.
Related
In Visual Studio version 2002 and 2003 "Go To Definition" would find the selected type or member in the Object Browser. In 2005 onwards it opens a source window "generated from metadata" instead. How do I configure these newer versions to go to Object Browser? (In other words, I have the opposite problem to this one.)
Installing ReSharper makes this change, so I know it must be possible, but how do I do it without ReSharper?
As workaround you can create the following macro:
Sub GoToDefinitionUsingObjectBrowser()
DTE.ExecuteCommand("Edit.SelectCurrentWord")
DTE.ExecuteCommand("View.ObjectBrowser")
DTE.ExecuteCommand("View.ObjectBrowserSearch", DTE.ActiveDocument.Selection.Text)
End Sub
Then go to Tools/Options/Keyboard and assign hot key for this macro.
Tested in Visual Studio 2010.
I believe what re-sharper is doing is doing some hooks on that click event with the Visual Studio SDK I do not think there is any simple menu or location that can change that setting.
Instructions (pulled from CODE Magazine) edited down a bit to the part that pertainst to making the right click menus.
Creating a VSPackage
...The VS SDK installs a few more project
templates in Visual Studio, one of
them being the Visual Studio
Integration Package (Figure 1),
located under Other Project Types >
Extensibility on the New Project
dialog box.
After this standard dialog box, the
Visual Studio Integration Package
Wizard guides you through creating the
new package project:
Select a programming language. The wizard currently supports Visual
C++ and Visual C#. You can create or
pick a key file to sign the new
package.
Supply basic VSPackage information. The wizard prompts you
for details such as the company name,
VSPackage name, version, icon,
detailed information, and minimum
Visual Studio edition (such as
Professional or Enterprise) that the
package is designed to at this step.
This information goes into the Visual
Studio splash screen and About dialog
box and is also used to request a PLK
for the package (covered later).
Select VSPackage options. A package may add three types of
functionality: Menu Command, Tool
Window, and Custom Editor.
A menu command is a command added either to the menu
at the top of Visual Studio or
to a context menu (right-click).
When the wizard finishes its job, the
VS SDK adds core elements to the
solution to support the new package.
For instance, if you selected Tool
Window as part of the functionality
for the package, the project contains
a user control where you should place
the visual controls for the window.
The project also contains files for
.NET code to handle the functionality
that you will add to the package.
A CtcComponents folder contains
pseudo-C++ files (ctc files) where you
define things like menu, groups,
buttons, etc. Fortunately, Microsoft
is phasing out CTC files and replacing
them with a friendlier, XML-based VSCT
file format (which will ship in the
SDK for Visual Studio 2008).
The wizard creates a few other files
with .NET code required for the
plumbing of the package within Visual
Studio. Some of these files contain
classes that map the C++ constants to
.NET constants and other files contain
configuration information for the
package when it’s installed.
I know it has been a long time, but it appears, at least in newer versions of Visual Studio for the VB (Basic) language, to be an setting in the options.
Text Editor > Basic > Advanced
Under "Go to Definition".
I don't know why they don't have that for other languages...
Place the mouse cursor on the object you want to access on the object browser. Then, use the keyboard shortcut ctrl + alt + j, which will take you directly to the Object Browser window.
I have a project with many projects that performs miserably with ReSharper enabled, even on a pretty decent machine (8GB RAM, hybrid solid state hard drive, Core 2 Duo processor).
I was able to find out how to suspend ReSharper, but none of the default key bindings for Visual Studio (e.g. Ctrl-[comma] to navigate to type) seem to be working when I turn ReSharper off.
How do I get back the default key bindings when I disable ReSharper (and get the ReSharper bindings back when I enable ReSharper)?
Prior to resetting the keybindings in VS, export a backup copy of your current ReSharper settings:
Tools -> Options -> Environment -> Import and Export Settings -> rename file to ReSharper.vssettings -> click OK
Then repeat the previous steps but rename it back to CurrentSettings.vssettings.
Next reset the VS keybindings by:
Tools -> Options -> Environment -> Keyboard -> click the Reset button.
That should restore the settings back to the original VS default keyboard bindings and remove all of ReSharper's. (Note this also will remove any custom keybindings that you might have defined unrelated to ReSharper.)
As stated in Warren's answer you could use two VS settings files one of ReSharper and one for (non-ReSharper) default VS and import and load the one as needed.
This could be automated by creating some VS macros:
Public Sub ExportVsSettings()
DTE.ExecuteCommand("Tools.ImportandExportSettings", "-export:c:\MyVSSettings\CurrentSettings.vssettings")
End Sub
Public Sub ImportDefaultVsSettings()
DTE.ExecuteCommand("Tools.ImportandExportSettings", "-import:c:\MyVSSettings\Default.vssettings")
End Sub
Public Sub ImportResharperVsSettings()
DTE.ExecuteCommand("Tools.ImportandExportSettings", "-import:c:\MyVSSettings\ReSharper.vssettings")
End Sub
You can then assign keyboard shortcuts to these macros for ease of use.
Tools menu -> Import and Export Settings... contains the functions you need. You can create separate settings files (.vssettings) for parts of your VS configuration, and then restore them later.
If you want to quickly switch between configurations, ensure that Visual Studio is not running, then go to the user's documents directory, then into the corresponding Visual Studio version directory, then into the Settings directory underneath that. The CurrentSettings.vssettings file is what is loaded by Visual Studio. Substitute that file with another .vssettings file containing the settings you want, and you're good to go.
These .vssettings files are regular XML files, so you could devise a clever little program to rewrite the portions of the files you want to change.
I changed some parameters in a Visual Studio C++ project, and now I don't remember how to "go back". Is it possible to reset the build settings?
I don't mean the IDE settings (menu Tools -> Import and Export Settings).
Am I the only person that can read?!
The only way I know how to reset a "Parameter in a Project's Settings",,,
Is to open the Project file(csproj, vcxproj) with a text editor, and remove the block defining that parameter.
If you wanted to reset the Allow Isolation value, you would delete this text.
<AllowIsolation>true</AllowIsolation>
When project files are loaded by visual Studio, values which are not explicitly defined in the file, are assumed to be using the default. This will only work if the property has a default value(can't change some).
NOTE: This is NOT the same as Deleting the value from the Project Properties Dialog in VS. That method writes a blank value to your project file.
The command "devenv /resetsettings" will restore Visual Studio back to its original factory state.
You can find list of devenv switches here.
You may be able to get the previous/saved version of your Visual Studio project (*.vcproj) from your software version control system.
As many wrote here before, there is a need to reset your visual studio to default settings. Just follow this: https://msdn.microsoft.com/en-us/library/ms247075(v=vs.90).aspx
Here is the awful method I used in Visual Studio 2022.
In "Property" pages, expand the individual configuration you want.
Click "All Options" and find the bold options you had changed.
To restore the defaults, click the options and select "<inherit from parent or project defaults>".
Click "Apply", then it will recover its original value.
Otherwise, you can compare the *.vcxproj with the project templates.
The Visual Studio options dialog allows you to set tab preferences (size, insert-spaces, etc.) on a per-language basis. But I am regularly working on a couple of c# projects with different settings for these values.
Is there a way to override the global settings on a per-project basis, or at least toggle between them easily?
Another approach may be through the extensibility API: it should be possible to write a macro or add-in that changes these settings.
E.g. to change the tab size to 6, use the following:
DTE.Properties("TextEditor", "CSharp").Item("TabSize").Value = 6
Here's a link that explains how to find out the names of the properties: http://support.microsoft.com/kb/555445
You can open visual studio with a special "reset" settings file which overrides the default settings. Using this method it is possible to create two shortcuts, one with each tab setting. Details are here.
I'm afraid you can't do that on a per-project basis.
But, with Tools/Import and Export Settings... you can export each settings in a file and you could import the one that fits your current project.
Visual studio 2017 adds .editorconfig support, which is very handy for such settings.
Is there any way to define an IDE Layout in visual studio 2008?
Lets say that when I code in C# , I have the properties windows disabled and the output window at the bottom. Now Lets say that when I am in the visual editor of a window , I want the tools and the properties windows on the left and the output window disabled.
the problem is that If i want to work that way I have to manually rearrange the IDE layout each time I switch from code edit to visual edit.
I would like to have an option to define several IDE layout and for each assign a hotkey.
So I can quickly change between the layouts.
Is there a feature like this in visual studio 2008?
Visual Studio has a notion of layouts but they are applied automatically depending on the current mode (design, debug, etc). You could create IDE macros to show / hide your tool windows though:
Enable properties:
Sub PropertiesOn()
DTE.ExecuteCommand ("View.PropertiesWindow")
End Sub
Disable properties:
Sub PropertiesOff()
DTE.Windows.Item(Constants.vsWindowKindProperties).Close
End Sub
You can use the macro recorder (Ctrl+Shift+R) to see what commands are needed to display or hide the other tool windows. Build up your macros (using the Macros IDE - Alt+F11 or Tools | Macros | Macros IDE) to enable / disable groups of tool windows. Then you can bind the macros to your own keybinding or simply invoke them from the commands window. Alternatively, you can execute macros using the Macros Explorer (Alt+F8 or Tools | Macros | Macro Explorer).