Replace tabs with spaces in Visual Studio project files (sln & vcproj) - visual-studio

I'm trying to have a strict no-tab policy at my company by adding blockers on commits which introduce tabs.
Problem is visual studio uses tabs for their .sln & .vcproj files even when your settings are set to use spaces instead of tabs in the VS editor.
Anyone know how I can change that or am I stuck making another microsoft exception?

For your information, spaces are supported in vcxproj but not in sln files. Replacing tabs by spaces in .sln will make it load incorrectly (not generate exceptions or anything).
There are no settings in visual studio itself to change that though.
There are scripts that can do it before submitting in a source control but keep in mind that .sln files must keep the tabs to work correctly.

This is fixed in Visual Studio 2019.

Related

Project scripts not saved in the Visual Studio list

When I edit the Unity scripts, it opens up visual studio for me, and I manage the code there. Each script opened in visual studio has an x ​​next to its name, so you can remove it from view.
When I don't press the x and leave the script open in visual studio, if I close visual studio and open another script from Unity, the last script selected is shown, and alongside the previous script that I had not deleted with the x (it shows me the previous scripts that I had opened and had not removed).
What I just said happens with 6 of my projects.
The seventh however (not in order), does not behave like this. When I open a script and, without deleting it (from view, not from Unity), I close visual studio, the next time I reopen, the recent scripts are not displayed. I would like them to be displayed.
This is because I have about thirty scripts in the project, and managing the openings from visual studio is much faster than doing it from Unity, as first you have to search for the exact path of the script, and then you must also wait for it to load.
I searched for solutions and tried looking at visual-studio / unity settings, but didn't understand what may be causing this.
I have done the "Reimport All"
I have regenerated the project files
I have reinstalled Unity and Visual Studio Community 2019 from the Unity Hub
There's a .sln file, which references .csproj files, which contain the files within your project. These files are those listed in your solution explorer. These files are generated by Unity and are related to Project files. In Visual Studio in the Solution Explorer, you will see the Solution (.sln file) which contains one or more projects (.csproj), and the files within a project.
Now besides of that, Visual Studio has a lot of settings besides the actual solution and project. These settings are for instance:
How you arrange your view in VisualStudio
Which tabs are opened (Your question refers to the file tabs)
These settings are stored within a .suo file. These .suo files are located within a hidden directory .vs inside your project folder (next to the .sln file). Usually the .suo files and the .vs folder are part of the .gitignore list so they don't get added to the repository, because they are machine specific settings. E.g. you want your VisualStudio to be set up differently than that of another developer in your project.
I think you need to make sure that your .suo files don't get overwritten/changed by any other mechanism. For instance, if the .suo file is added to a git repository, another developer closes all the tabs, and pushes it's .suo file, and you pull that. Then after you reopen Visual Studio all the tabs will be closed. If you open 5 tabs, and push your .suo file, and the other developer pulls it, next time that developer opens VS the 5 tabs will be opened.
You can also try to delete the .vs folder to reset everything. Don't forget to make a backup though.

Remove Whitespace Before Committing Files to TFS

Visual Studio gives us this great ability to completely customize our work environment, including how we wish to format whitespace. I am very particular about how and where I want tabs, spaces, braces, etc. to appear.
For instance, I prefer tabs to be inserted as tabs not spaces. I also prefer the indentation (Tab size/Indent size) to only be 2 spaces (frankly I don't need 4 spaces to see that the line has been indented).
This is all well and good until I work collaboratively. Everyone else I work with just seem to use the defaults for whitespace/formatting. This causes problems when using source control like TFS. If you compare files worked on by me and then a co-worker, the changes in whitespace also show up. I don't want to see these changes; they're not significant.
Please don't tell me the answer is that the entire team should use the same settings. This isn't the correct answer. That answer is a cop-out for bad design. Why have the ability to customize your environment if everyone is forced to use the same settings?
Why doesn't TFS (or any other source control) remove unnecessary whitespace before committing a file based upon the file type? This has several benefits. One, the storage required to hold the file is less. Two, the transmission of the file to the source control server should be more efficient since the file is smaller (these first two benefits are probably negligible since the files are probably compressed anyway). Three, and most importantly, TFS (or any source control) will no longer report changes in whitespace when doing a file diff.
When I view/edit the file in my environment, it will be reformatted how I've defined it. When someone else views/edits the file, it will be reformatted to their specification.
Is there a way to do this currently in TFS?
Although what you said about is very reasonable, I still want to say the best solution is to get the entire team to use the same standards for white space in code. After all, you are teams.
If you insist on it, below is a workaround that to this problem (only works on your local machine).
In Visual Studio, select Tools / Options / Source Control / Visual Studio Team Foundation System and click the Configure User Tools button.
In the dialog, Add an item with the following settings.
Extension : .*
Operation : Compare
Command : C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\diffmerge.exe
Arguments : %1 %2 %6 %7 %5 /ignorespace
Depending on your Visual Studio version and instalation path (x64/x86), the command option may be...
VS2010: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\diffmerge.exe
VS2012: C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\diffmerge.exe
VS2013: C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\vsDiffMerge.exe
VS2015: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\vsDiffMerge.exe
In the argument option leave it with the same number of arguments as the VS suggests and just add /ignorespace in the end. For example, in the VS2015 it will be:
%1 %2 /ignorespace
More details you can refer this blog: Configure Diff to Show Whitespace
You could also use another alternative. WinMerge is. It also has an option to ignore whitespace (menu Edit -> Options -> Compare -> Ignore all (under the groupbox "Whitespace" at the top)).
How to use WinMerge with TFS you can refer:
Using WinMerge with Team Foundation Server (TFS)
Using WinMerge as the default diff/merge tool in Visual Studio
2012/2013

Where are the default file/folder ignore rules for Visual Studio TFS stored?

When I add a solution to TFS through the Visual Studio 2013 "Add solution to source control" menu option certain (build output) files and folders are automatically ignored. I know I can create a .tfignore file to customise this behaviour, and that is not what I'm asking about. Can anyone tell me where the default Visual Studio standard exclusion list is stored?
See https://stackoverflow.com/a/43227500/117965
File is located at %LocalAppData%\Microsoft\Team Foundation\7.0\Configuration\VersionControl\
I don't think there is a list, Visual Studio just places common Binary files onto the "Excluded" tab. It has been this way since TFS 2010. I don't even think messing with the Team Project Collection's Source Control options for multiple checkouts can help.
If there is a list, I'd guess it is in the registry somewhere.

How do I reformat MSBUILD xml in Resharper or VS Studio?

Both ReSharper 6 and VS 2010 treat my MSBUILD files as XML when it has the .Proj extension, but it will not allow me to reformat the text. The options are greyed out in ReSharper and VS 2010. How do I turn it on? Right now, I am forced to either copy and paste the code into a file with an xml extension reformat and copy and paste it back, or rename the file with an xml extension.
You can write a Visual Studio macro that will do all the renaming and reformatting for you. Macros can be bound to the toolbar and to commands (keyboard shortcuts), so you can make this into a single click/shortcut.
JetBrains answer as of today (2013-12-02) is that project files are excluded from code cleanup. There's a discussion of the issue on their code cleanup page which contains a link to a bug named Verify that Code Cleanup works with MSBuild .proj files which contains the information that the fix version is only 9.0!
So there seems no way short of an external tool to get this done.

Hidding source control files within Visual Studio's solution tree

We use Visual Studio 2008 and Surround SCM for source control. SCM drops files into each directory named ".MySCMServerInfo" which are user specific data files that shouldn't be checked into source control. They are similar to the .scc files dropped by Visual Source Safe. We also have several WAPs (Web Application Projects) that we develop. All these .MySCMServerInfo files show up in the solution tree and the Pending Checkins window when they should not. There has to be some way to force VS to ignore files of a given extension because it ignores .scc files. How do I get VS to ignore .MySCMServerInfo files within a WAP?
I have new information about this issue. Setting the hidden bit on .MySCMServerInfo file causes Surround SCM to loose track of the modification state for files. It starts thinking files are out-of-date when they are not, and it always attemps to get new versions.
Instead, set this registry key if you're using Visual Studio 2008:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Packages\
{8FF02D1A-C177-4ac8-A62F-88FC6EA65F57}\IgnorableFiles\.MySCMServerInfo]
Set this registry key if you're using Visual Studio 2005:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Packages\
{8FF02D1A-C177-4ac8-A62F-88FC6EA65F57}\IgnorableFiles\.MySCMServerInfo]
These will tell Visual Studio to not display .MySCMServerInfo files within the Solution tree and the Pending Checkins view.
Using the file system hidden bit should work.
Late Answer but hopefully useful to others.
I began experiencing this problem when using Visual Studio 2015 with the new ASP.Net 5 Project templates. (I presume this is because the new templates automatically include everything in the folder rather than only showing the things that are listed in the project file).
Showing these files in the Solution explorer change be prevented by right clicking the file and selecting "Hide from Solution Explorer" but this didn't prevent SCM from including them in the Pending Check-ins Window.
The correct way to deal with this problem is:
Select the file(s) in Solution Explorer
Select the File > Source Control > Exclude from Source Control
Reference
NOTE: Right Click in the Solution Explorer DOESN'T have this option.

Resources