Per solution new line options for braces in Visual Studio 2017 - visual-studio

Through this answer to a question on per-solution indentation settings for Visual Studio I found out that the EditorConfig format is supported for VS 2017.
What I cannot find is how to use EditorConfig (or failing that: any alternative) to set "New line options for braces" on a per-solution basis.
Here's the relevant settings from Visual Studio:
These settings are persisted on my Visual Studio 2017 account, which is really annoying since I use defaults for my pet projects, but the project I mainly work on uses Egyptian braces style. If I change these settings on my work PC they will be synched to my home PC every time, and vice versa.
Can EditorConfig be used to have per-solution settings for "New line options for braces"? Failing that, is there another way to handle this?

I believe these are controlled by the csharp_new_line_before_open_brace property in .editorconfig. Unfortunately the closest thing I have seen to documentation on the properties used by roslyn is the source code and the issue under which they were added.
My experience with getting visual studio to use a .editorconfig file however, has been a bit hit and miss. Sometimes visual studio will ignore the file without giving any reason.

Related

'Format code' and 'sort using' on save in Visual Studio 2022

I and my team spent the last few months defining rules about C# code formatting and style for our project, so we ended up with an .editorconfig file.
Moreover, we all installed the extension Productivity Power Tools, in order to format the code when saving the file (CTRL+S) rather than having to use the VS built-in feature Code Clean Up. We took this decision when we realized that the latter requires a special shortcut (CTRL+K, CTRL+E) and that every member of the team needs to set this setting locally, since there is no way to put it in the source control.
This way of working went great with VS 2019.
But, in the last month most members of the team upgraded to VS 2022 and the extension Productivity Power Tools 22 removed - apparently without any reason - the Format On Save and Remove and Sort Usings on save features.
We apparently solved this issue with the extension VSE-FormatDocumentOnSave - by setting Edit.FormatDocument Edit.RemoveAndSort in the Commands option. It seems to work great but our concern is the fact that this is not a Microsoft tool and who knows what will happen in the future.
So, since the code style and formatting rules are a concern for every team out there, I would like to know if anyone knows a better way to manage this, considering that we are a team of 20+ developers.
Starting from VS2022-Preview2, there is no need to additional extension to "format on-save", you just run a customized code cleanup that contains "Format document" action on-save:
Customize your cleanup profile to perform "Format document" action (if not already there), in Analyze > Code Cleanup > Configure Code Cleanup
Enable "Run code cleanup profile on save" in VS configuration Tools > Options > Text Editor > Code Cleanup
Bringing Code Cleanup on Save To Visual Studio 2022 17.1 Preview 2
Unfortunately code cleanup setting is not included to .editorconfig file neither to exported config file .vssettings that could be shared across a team, maybe it will be included in the future.
Some feature requests related to this:
visual studio 2019 allow import and export Configure Code Cleanup profile
Provide a way to share Code Cleanup profiles as related to EditorConfig
Code Cleanup and EditorConfig
"Format Document On Save" worked for me.
Configuration:
Why not try the Code Cleanup On Save extension by Mads Kristensen (who works for Microsoft). I have not used it myself but all his other VS extensions are awesome.
Edit: The 'clean on save' feature has been added to Visual Studio 17.1 which is in preview at the moment. So no extensions required.

Is it possible to get a timestamp in the VS source control window?

In Visual Studio 2015 is it possible to get a timestamp included for each line when a file is updated? So for instance:
2016-06-28 10:30:45.106 Replacing....
The Visual Studio Productivity Power Tools has an option to do this (VS2013 version, VS2015 version) called "Timestamp margin".
From their site:
It also has many, many other features. You can turn each feature off separately though, so if you don't want the other features you can turn them all off.

How to make the Visual Studio 2015 text templating security warning go away?

This problem is making me mad.
We have a set of projects that rely on T4 templates to generate code for a bunch of DSLs.
Every time I try to transform one of these T4 templates in Visual Studio 2015 I get this window, the security warning:
I have set the "Do not show this message again".
I have set the VS option "Text Templating | Show Security Message" to false.
Every time I restart Visual Studio 2015 and transform the first template the message pops up again.
This does not happen in Visual Studio 2013.
Some hints that may have something to do with this:
The actual text template that is called is published by a VS extension that is installed in the admin extensions directory ($ProgramFiles$\Microsoft Visual Studio 12.0\Common7\IDE\Extensions).
We are using our own custom code generator (that derives from TemplatedCodeGenerator).
Any ideas?
I have found the solution to this one a little by chance.
The problem was that the assembly containing the custom code generator was referencing Microsoft.VisualStudio.TextTemplating.VSHost.12.0 instead of version 14.0 as for Visual Studio 2015.
Oddly enough the transformation did not complain about the problem with the reference but completely ignored the VS option to stop showing the security dialog (may be because it was reading it from the wrong place?).
After correcting the reference, the problem never happened again.

Visual Studio 2015 Find in Files not remembering file types or locations

I rely on the Find in Files dialog in Visual Studio a great deal. (Sometimes Intellisense/Resharper just don't cut it.) Since upgrading to 2015, I've noticed that the dialog doesn't remember my custom "Look in" paths or "Look at these file types" lists between sessions.
If I close my solution and VS instance, then reopen, I have to enter my custom path and file types again. Huge waste of time. Has anyone run else run into this? Any workaround? 2013 used to remember this stuff.
Microsoft Visual Studio Professional 2015
Version 14.0.23107.0 D14REL
Microsoft .NET Framework
Version 4.6.00081
Installed Version: Professional
I've never had any problems with it not remembering my settings, but I imagine that you could run a custom registry modifier to add the appropriate keys, you could make sure your settings are always pristine. The custom search information is stored in HKEY_CURRENT_USER\SOFTWARE\Microsoft\VisualStudio\14.0\Find.
The file types are stored in a string key called Filter with whatever you would normally input into the custom file type category in the VS search window. For example searching for only .cs and .txt files you would put *.cs;*.txt.
The folders are located in a string key called Query with values such as C:\Folder1;C:\Folder2. However, it's behavior seems a little weird. You have change the value of Query and a Query+integer value (i.e. Query0) to the same value to have it appear in Visual Studio.
If you just run a script to modify the above values to the files types/folder locations you want, that should work.
I ran into this today. After much searching I found a post on the visual studio forums somehow. This pointed me towards ReSharper. This directed me towards a workaround.
Start visual studio in safe mode with the command line argument /SafeMode
Create the folder sets you want for searching
Restart visual studio not in safemode
Once I had restarted all my created custom searches remained, and the registry values were created. This might not work in the specific case, but this worked for me.
You can set these values programmatically inside Visual Studio for the Find and Replace dialog (for example with Visual Commander):
DTE.Find.FilesOfType = "*.txt";
DTE.Find.SearchPath = #"c:\temp";
If you have an earlier version of VS, export the environment settings, copy the NumberOfScopes and NamedScopes* settings from the Environment_UnifiedFind section to the same section in your VS2015 settings file and then re-import settings.
Once I did this, it allowed VS2015 to start saving folder specifications for future settings exports.
Or you could try replacing this in your VS2015 export:
<PropertyValue name="NumberOfScopes">0</PropertyValue>
With this:
<PropertyValue name="NumberOfScopes">1</PropertyValue>
<PropertyValue name="NamedScopes>0">FOLDER_SPEC_NAME>SEMICOLON_SEPARATED_LIST_OF_FOLDERS>{4A812F3C-7B1A-4987-9769-461F20EB25CB}</PropertyValue>
(Don't forget to re-import after you make the change)

Multiple Visual Studio (2012) profiles (addons + settings)

I use Visual Studio 2012 for both C# and C++ development. I also use different extensions depending on the current working project: ReSharper for C# and Visual Assist X for C++.
Is there a way of creating multiple Visual Studio profiles (or installations of the same version) that will use a specific (and different) set of extensions? Currently I have to deactivate/reactivate some manually and it's getting annoying that such a feature doesn't exist (at least something like Eclipse's workspace)
Combine this with different environment setting (e.g.: tabs and spaces settings) for each project and you'll soon get mad. I know we can use different settings files, but it's still annoying to have to re-import a specific .vssettings file each time you open a different project.
Thanks.
Have you considered "Run As" for Visual Studio and use another Windows User Account? That should allow you to disable R# and VisualAssist separately.
There used to be a way to run a Macro to import an exported settings file, but they removed the Macro functionality in VS2012 (sadly). You could write an extension that manages importing different settings I guess.

Resources