code formatting in VS and command line - visual-studio

I need a tool that would allow developers to format code using Visual Studio and also check if this formatting was applied from command line (for using in pre commit hook, CI builds, etc.) I am totally fine with default VS formatting or ReSharper formatting or any other sane default, but I need support from both VS and command line for the same style. Right now some developers use ReSharper, some use plain VS and 10s of lines of code get moved right or left with every commit with no actual change whatsoever.

I once heard about on a conference, but did not use it myself, because I usually do solo. Take a look at StyleCop

Related

How to make sure we are both formatting in the same way?

I'm working on a project with another developer. I am using Visual Studio and he is using Intellij I think. When I push in the code tho, there are always changes in the way the code formats. We have editorconfig and this is all we have in there:
{
"formatOnPaste": false
}
How do I make sure we are both formatting the code in the same way?
Code format is affected by several settings and possibly plugins, per user, per workspace, that may even be overridden by the user.
Prettier does a very good job for most languages: here's a link for VSCode, the same may apply to the full Visual Studio: https://www.digitalocean.com/community/tutorials/code-formatting-with-prettier-in-visual-studio-code
Put the prettier settings in a .prettierrc and commit that along with your source code.
Git line endings might be another reason why code changes upon committing, especially if you're on different OSes. Here's an accessible explanation to make git consistent: https://docs.github.com/en/github-ae#latest/github/using-git/configuring-git-to-handle-line-endings
Hope this puts you in the right direction.

How do I merge text in visual studio 2010?

To preface this I am an Emacs refugee on Visual Studio 2010's shores and am certain that I am working against the tool. Please could someone point me in the right direction. My problem is the MyProject.csproj file is kept under version control using TFS and my coworkers have made a number of changes that no longer get along with my version. Not a problem, I can just merge the changes and make things right. But I can't, or rather I don't know how to. The compare tool in VS only taunts me, it won't let me pick and choose differences like I need to.
What I would love to do is just use Merge in Emacs, run through the file hitting L(eft), R(ight), B(oth) and be done with it in no time. What I don't understand is why there are certain changes that are accepted by default, that I cannot alter. I think that what it is doing is identifying changes that I made to the ancestor document and forcing those to be made while providing me the option of merging the changes from my coworkers. My issue is that these things are contradictory and I would like to ignore my change to Line 12 while accepting the Repository's Line 42 but applying my Line 106.
But I cannot figure out how to tell it "no" to Line 12.
This has to be common, what does one do in VS to get this to work?
Thanks!
The standard diff tool that comes with Visual Studio ... blows. Its not intuitive and doesn't work all that well.
But its very easy to integrate different diff tools. I'm using this one:
http://visualstudiogallery.msdn.microsoft.com/en-us/dace3633-0b51-4629-85d4-c59cdce5bb3b?SRC=VSIDE
(no affiliation; its free so don't ding me for spam kthx). Works pretty damn good. You might find one out there better suited for your tastes, in which case you can integrate it into visual studio. (again, not associated with me!)
I advise you to use WinMerge to compare or merge files with VS
You can define as Will said.

Renaming files: Visual Studio vs Version control

The problem with renaming files is that if you want to take advantage of Visual Studio refactoring, you really need to do it from inside Visual Studio.
But most (not all*) version control system also want to be the ones doing the renaming.
One solution is to use integrated source control, but this is not always available, and in some cases is pretty clunky.
I'd personally be more comfortable using source control separately, outside of Visual Studio, but I'm not sure how to manage this question of file renames.
So, for those of you that use Visual Studio, which source control do you use? Do you use a VS integration (which one?) and otherwise, how do you resolve this renaming problem?
(* git is smart enough to work it out for itself)
I use SVN (TortiseSVN as the client) and use the Repair Move command from the commit dialog heavily. This allows me to rename the files within VS and resolve the rename when I'm ready to commit to keep version history.
As far as using the VS integration, like you, I find all VS integration clunky and do not use it.
mercurial usually prefers to do the renaming via hg rename however it can also detect renames from an outside source by using hg addremove -s 100 (or less than 100 if you want to match a rename with alterations) so clearly you can let VS do the rename and get mercurial to catchup with addremove.
We use SVN (TortoiseSVN to be exact), and i am always bothered with the renaming problem. The simplest solution i've found is to remove the files from the project, rename them via TSVN and add them back to the project. You have to manually update includes for renamed header files, but this is relatively easy using find&replace.
We use Team Foundation Server, and it works with no problems. I've also found that moving to using a fully integrated client has improved my workflow, as I don't need to flip between applications just to do trivial tasks.
We develop "Plastic SCM" and the Visual Studio Package supports move operations. But I see your point, I'm getting more and more comfortable with the idea of not having plugins/packages and then have the version control working behind the scenes and simply detecting what happened without having to be "plugged in" into the IDE. In fact we're working on it for next release...
Besides the above advice, for Visual Studio 2008 I found that after making all global changes to any file being renamed from within VS, including right clicking the file and renaming it, as well as a global search and replace for all strings, replacing the old file name with the new file name, you must, if the file is the initial startup file, right click and select it as "set as default page". Otherwise you'll may well get the "The resource cannot be found." error on runtime.

Does anyone know of a code change management tool that can highlight code changes in Visual Studio?

Hey all, I am trying to find a tool that can highlight code changes in Visual Studio so they can be easily found and reviewed. Below are some requirements for what we are looking for...
Identify and use a difference highlighting tool that meets the following criteria:
• can highlight areas that need to be reviewed
• there is a place to enter comments
• retains line numbering from code
• preference for doing within IDE
Issue addressed:
Hard to see what was changed in code - changes not identified. Coders do not provide administrators diffs. No tool that does a nice job to identify differences. Daunting/time consuming to provide a good diff. When highlighting differences was provided, loss of line numbers was a substantial issue (was worse).
A lot of source control systems offer this functionality.
Check out Subversion at
http://subversion.tigris.org/
There is visual studio integration at Visual Subversion:
http://www.visualsvn.com/
We use BeyondCompare for this. The 3 pane view for merge (original, theirs, yours) and the 2 panel pane for comparison like you want is excellent.
You can use it standalone, including just looking at file trees outside visual studio, or integrate inside and with most of the version control systems as well. Take a look here for the parameters. That example is for TFS, but you can change the command line to fir any version control.

Bazaar (bzr) integration with Visual Studio

What's the best way to use Bazaar (bzr) as the version control system in Visual Studio 2008?
The best I found is TortoiseBZR and the command-line - nothing integrated with VS.
I wouldn't even bother with TortoiseBZR; bzr is very easy to use from the command line.
BTW: The last time I tried it, TortoiseBZR used to lock up windows explorer while it went off to a remote repository to determine the status of files, not sure if it still does this ... ? See also this SO question.
There is no native integration to Visual Studio, but there is good GUI application, called Bazaar Explorer. It's the part of official standalone installer, and also can be installed separately as bzr plugin.
Old, I know, but since this shows up on the top for Google search, the best way to integrate is a combination of Visual Studio's External Tools, and tbzrcommand.exe and bzr.exe. You can set up things like Status to go to the output window, and things like Diff to go to the tbzrcommand GUI window.
(I'm assuming you've installed TortoiseBzr here.) Using these as examples, in VS open Tools->External Tools, then Add. For the program, browse to the Bazaar directory and select bzr.exe. Name the command Status. For arguments, type "status" (sans quotes). Select that the output should be directed to the vs output window, that the command should be terminated when complete. Open a simple file under code control and add a space somewhere and save, then under external tools, choose status to verify that it shows up as a pending commit action. (You can add these to their own menu later, once they work.)
Next, add another external command and name this Diff. For the program, browse to the Bazaar directory, and choose tbzrcommand.exe. For arguments, type "--command=diff --file=$(TargetPath)" (sans quotes). Leave the options all unchecked. Then, for the file above that you added a space, select it in the solution explorer window and choose Tools->Diff. A TortoiseBzr window should appear (along with an annoying DOS window), and show differences between the working version and the latest commit version of the file.
For something like a commit, which requires a comment, you'll have to put in arguments like "commit -m " (sans quotes) and check the box to prompt for arguments (to allow the entry of a message for the commit).
There's a project in Launchpad, but it looks like it's abandoned, and when I downloaded it, I couldn't get it to build.
This is something I'm interested in myself. Tracking adds, drops and renames automatically in an IDE is the way to go. Seeing status is nice too.
If you don't need the SCC integration, just the ability to use the tool, try the setup in this article:
http://www.codeproject.com/KB/macros/Bazaar4VS.aspx
I've ported VisualHG to work with Bazaar:
https://launchpad.net/visualbzr
It's currently an alpha version, and has only been built and tested for Visual Studio 2010, but common operations should work OK.
Edit:
This plugin hasn't moved on much, but it does now support Visual Studio 2012.
Unified SCC has support for bzr. It is commercial but claims to be free for OSS projects.
UnifiedSCC
I too was trying to use this, and found that visual studio has an option of "External Tools", which can be found under the tools tool bar. Upon trial, I found that one could create a link to the bzr.exe (or any other exe tools you may want to use). Then, it asks for arguements. It is here where you can begin to use magic.
For me, to commit changes directly, I have created an arguement of commit -m "", which commits without message to the bzr branch if one exists in the working directory (to achieve this, you also have to change the starting directory to solution directory).
I also created a push command to my launchpad using similar idealogy

Resources