Forcing Visual Studio to set "Insert Tabs" from a script - visual-studio

I would like to write a script to force Visual Studio 2015 to "Insert Tabs". The idea is that this script would be pushed out by our IT department and run on Windows startup to ensure that everyone is consistent. If you hate tabs, pretend I'd like to write a script to set "Insert Spaces".
The obvious way might seem to set HKCU\SOFTWARE\Microsoft\Visual Studio\14.0\Text Editor\CSharp\Insert Tabs to 1. This appears to do nothing, probably because we are using Synchronized Settings (https://msdn.microsoft.com/en-us/library/dn135229.aspx). What can I do about this, short of writing an extension to Visual Studio and pushing THAT out.

You may consider using an extension like EditorConfig or Rebracer that apply editor settings from a shared per-solution file.

Related

Can visual studio code block modifications like vim?

Is it possible to lock files in visual studio code? Similarly to what you do in vim where you have to press "i" if you want to modify files I'd like to be able to keep the files locked and then press a key that allows me to modify them and then lock them again. Is it possible to do so in visual studio just like in vim?
It looks like you're looking for a "modal editor" interface.
If using actual Vim keybindings and commands would work for you, then consider adopting Vim for VS Code, which emulates most of the Vim UI inside VS Code.
It should give you the best of both worlds.

Refactor on save in Visual Studio 2019

I love Prettier for VS Code. I want to do similar things in Visual Studio (2019).
It now has 'Wrap, indent, and align parameters or arguments' for example (https://learn.microsoft.com/en-us/visualstudio/ide/reference/wrap-align-indent-parameters?view=vs-2019); and I'd like to do this automatically whenever I save the file.
Does anyone know if this is possible? Or if there's a free extension that can do this?
Mads Kristensen (a Microsoft employee who makes scads of Visual Studio extensions and teaches you to too!) made a JsPrettier extension for "classic" Visual Studio (ie, not VS Code):
https://github.com/madskristensen/JavaScriptPrettier
It does not format on save if you set that up in its settings.
If it's literally Prettier in Visual Studio that you're after, this isn't a bad option.
I don't know of a free plugin but you can get quite a long way towards this with some muscle memory and the built in autoformat command.
CTRL+E, CTRL+D, CTRL+S
will do code indentation and formatting, and save the file.
If you have Resharper (sorry), there's a configurable code cleanup tool which will do what you want and CTRL+E, CTRL+F, CTRL+S will do the cleanup and save.
The Format document on Save VS extension does exactly what you want, with one exception. It automatically runs Visual Studio's code cleanup command on save.
Visual Studio's code cleanup commands covers many code style preferences and can be configured with a .editorconfig file. Unfortunately one thing that is not supported by VS yet (not counting Resharper) is line wrap preferences. There is an open ticket for this: dotnet/roslyn#33872
If and when Roslyn supports line wrap preferences (presumably as a new .editorconfig preference), then Visual Studio code cleanup will enforce it and the extension will apply it on save.

visual studio 2010 confirmation on close

I want VS2010 to ask me when I am closing the whole environment whether I am sure about closing VS2010 or not.
Unfortunately I couldn't find this setting anywhere
Anybody knows?
AFAIK, there is no such option. However, there is an old tool called NoClose that can disable the (X) button for you (see LifeHacker article about this tool)
Though I haven't used it under Windows 7/8, I'm not sure if it is compatible.
I haven't tried this in Visual Studio 2010, but you can achieve this in Visual Studio 2008 at least by using an Automation Macro. The instructions below work for 2008, and shouldn't be too hard to translate to 2010 (hopefully).
Open up the Macro IDE (Tools->Macros->MacroIDE), and in the list of Macros you should see an item EnvironmentEvents. Double-click this to get a module containing the existing Environment Event macros.
In the drop-down list select SolutionEvents, and then in the Declarations list select QueryCloseSolution. What we're doing is creating a macro that is run whenever you try to close a Solution. We'll create a messagebox to ask the user if they really want to do it, and optionally cancel the shutdown - you should end up with something like this:
Private Sub SolutionEvents_QueryCloseSolution(ByRef fCancel As Boolean) Handles SolutionEvents.QueryCloseSolution
If (MsgBox("Close the solution?", MsgBoxStyle.OkCancel) = MsgBoxResult.Cancel) Then fCancel = True
End Sub
Save the Macro project, and try closing the solution, or shutting down Visual Studio. If the stars are aligned you'll see a confirmation message box. If you click "Cancel", the solution won't close, and VS won't shut down.
Now, perhaps someone can confirm in the comments if this works for VS2010?

Is there a visual studio automatic save configuration setting?

I use the java IDE IntelliJ IDEA and one of the features I like is that there's no saving. Everything's always saved and you just use history navigation. I tend to have both editors open and I'm always forgetting to save in VS.
I'm running vs 2008 with resharper 4.5 but as far as I can tell this isn't achievable or configurable.
Any suggestions?
For VS 2019, the Auto Save File extension seems to work as expected.
It saves individual files on lost focus, can save all files when VS loses focus and can also save all after an inactivity delay.
In VS 2015, I used to use NoMorePanicSave2015.
It does an equivalent of Ctrl+Shift+S when Visual Studio loses focus, which saves all your files, including solution and projects.
Another plugin: CBAutoSave
This extension can automatically save modified documents, projects, and the solution whenever Visual Studio loses focus.
Saving of modified documents is on by default, while automatically saving projects and the solution is not. All options are configurable through the Visual Studio options dialog.
In VS2017/19 Community there is Auto-Recover option under tools->options->autorecover. It will not autosave unless there is a crash, so it may be a good compromise.
In VS2019 its under tools->Options->Environment-AutoRecover.
how-to-auto-save-work-on-visual-studio
Visual Studio 2008 will probably be the same:
http://www.howtogeek.com/howto/programming/configure-autosave-autorecovery-of-crashed-projects-in-visual-studio-2005/
However, it's not "no saving" but you can set it down to 1 minute.
Visual Studio 17.2 can now automatically save code documents whenever the application loses focus. This feature can be accessed via Tools > Options > Environment > Document.
There is an autosave, but I must admit that it doesn't seem to always work for me - notably I suspect that it only saves files, but not projects/solutions, or the .user and .suo files. I don't have any links to prove this mind you.
Visual Studio 2022 (Enterprise) has auto save option. But you have to enable it.
Navigate from Tools > Options > Environment > Preview Features and Enable the autosave.
here is a screenshot

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