How to use different tab settings in different projects in Visual Studio - visual-studio

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.

Related

Export Visual Studio's 'Code Style settings' as .editorconfig

Our team works with Visual Studio 2017 Professional.
I've been trying to unify the Code Style across the team and apparently the industry standard right now is to use .editorconfig files. Even Visual Studio in it's settings windows suggests to use that configuration file and links to a useful page on how to write an editorconfig file.
but I don't want to write all the settings that I already have configured in VS by hand. I would like a tool that exports those settings as a .editorconfig file to distribute them.
I haven't been able to find any tool to do just that so I thought on righting it myself and share it with other people like me. But apparently if go to "Tools -> Import and Export Settings..." you can't download your current Code Style settings.
Is there a way around this?
do you know any tool to convert my settings to an editorconfig file or a way to export my current Code Style settings?
Edit
I have created my own version of the .editorconfig file based on the information found in here
You can find it in my github repo
I realise this isn't much help for VS2017 users, but VS2019 has a button "Generate .editorconfig file from settings" on the Code Style options page:
This options page is available at Tools > Options > Text Editor > [C# or Basic] > Code Style > General.
I know this question is ancient but worth an answer...
The latest Visual Studio extension allows you to do this (Guide here):
Basically install the extension and right click on the solution or project (you can restrict the rules to solution/project or even folder) and click add > new EditorConfig (IntelliCode)
There are still some restrictions about what you can do in the latest releases of Visual Studio, but Visual Studio 2017 15.8 Preview 3 or higher allow you to use a new extended “Format Document” command to perform additional code cleanup for the current document.
It's a shame you can't make all your rules cause build errors, only some of the options allow this - without this, a lot of the styling options can be ignored.

Visual Studio replace tab with 4 spaces?

Is there a way to set TAB button to work as 4 spaces in Visual Studio 2010 instead of going to Edit->Advanced->Untabify Selected Lines?
You can edit this behavior in:
Tools->Options->Text Editor->All Languages->Tabs
Change Tab to use "Insert Spaces" instead of "Keep Tabs".
Note you can also specify this per language if you wish to have different behavior in a specific language.
First set in the following path Tools->Options->Text Editor->All Languages->Tabs
if still didn't work modify as mentioned below
Go to Edit->Advanced->Set Indentation ->Spaces
For VS2010 and above (VS2010 needs a plugin).
If you have checked/set the options of the tab size in Visual Studio but it still won't work. Then check if you have a .editorconfig file in your project! This will override the Visual Studio settings. Edit the tab-size in that file.
This can happen if you install an Angular application in your project with the Angular-Cli.
See MSDN blog
None of these answer were working for me on my macbook pro. So what i had to do was go to:
Preferences -> Source Code -> Code Formatting -> C# source code.
From here I could change my style and spacing tabs etc. This is the only project i have where the lead developer has different formatting than i do. It was a pain in the butt that my IDE would format my code different than theirs.
If you don't see the formatting option, you can do Tools->Import and Export settings to import the missing one.
For Visual Studio 2019 users:
By the comment under accepted answer, link:
Well... This is "almost" still the same in VS 2019... if you already done that and seems not to work, go to: Tools > Options, and then Text Editor > Advanced > Uncheck "Use adaptive formatting" as seen here

Share a custom made Visual Studio 2010 toolbar

I've created a new Toolbar in Visual Studio 2010 and added some custom buttons to it (mainly utilising the External commands).
I'd now like to share that toolbar with others, or be able to "save" it so that I could re-import at a later date.
I know that you can use the Import and Export Settings Wizard to back-up all your settings and re-import them elsewhere, but it does not allow you to Export a single toolbar instance.
Can anyone point me in the right direction of how I might be able to do this? I don't mind if it's just a settings file I have to save, a VS Extension I have to write, or an installer package I have to create - I'd just like to be able to share my toolbar!
I'm working in 2008, but in the Import Export Settings Wizard, limiting it to
General Settings > Menu and Command Bar Customizations
will narrow it down to just your toolbars.
The settings file is all just XML so you can look at stripping out your personal preferences and leaving just the elements of your custom toolbar.

Visual Studio: Varying tab width/options by .VCPROJ or .SLN file?

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.

How to Export/Import Toolbars in Visual Studio

I export my settings in Visual Studio and if I ever move to a new machine or have problems, I use those backed up settings to restore Visual Studio to the way I like it. It also allows me to maintain a consistent development environment between the various machines that I use.
This works great for keybindings, syntax highlighting, user tools, pretty much everything except for the toolbar locations and customizations. Whenever I move to a new machine and restore the settings, the toolbars are not affected. I have spent a fair amount of time setting up toolbars with my macros, external tools, etc and cut'n'pasted icons in for them. I hate losing all that work.
Does anybody know how to back up and restore the toolbars' locations and customizations? If it is not a feature of Visual Studio, is there an addin that will do the job?
Edit
As mentioned below, the Menu and Command Bar Customizations in Import and Export Settings is supposed to do this, but when I re-import my previous settings, I get
Error 1: Menu and Command Bar Customizations: The version of command bar settings being imported is not supported. All the command bar settings have been ignored.
The settings I am trying to re-import were exported earlier this month with the same version of Visual Studio. The only difference is that I am now running 64 bit as opposed to x86. I didn't think that would make a difference though since the settings files are XML.
Any ideas?
I have finally found the solution to this. There is a known bug in Visual Studio and there are two workarounds given. The first workaround does not apply, but the second worked.
To Backup your toolbars:
Copy the file CmdUI.PRF from the path %AppData%\Microsoft\VisualStudio\X.Y\1033 to the same directory as your exported .settings file.
where X.Y is either of 8.0, 9.0, 10.0 or 11.0 depending on your visual studio version (2005, 2008, 2010 and 2012 respectively).
To Restore your toolbars:
Make sure Visual Studio is closed and copy the backed up file back to the original location.
For the benefit of others, as you mentioned this feature doesn't seem to be supported across versions of Visual Studio, presumably because of a change in the DTD/XSD for the settings file? At any rate, here's where the settings for your custom toolbars lie in the "Import and Export Settings..." dialog:
Note: Your options may look different, depending on the settings you exported.
I have not tried it, but "Tools\Import and Export Settings..." maybe will let you export a .vssettings file you can then take to another box.
See also
http://blogs.msdn.com/saraford/archive/2005/04/19/409887.aspx
and other Sara 'export' tips.

Resources