VSCode Swagger Diff. This is a Visual Studio Code Extension that compares the Working Tree changes made to a Swagger 2.0 spec and shows the Breaking and other changes in a table format. It will help Developers to know the impact of the changes they applied. To view the changes: Open any Swagger 2.0 spec file with working changes. Tip: You can diff any two files by first right clicking on a file in the Explorer or OPEN EDITORS list and selecting Select for Compare and then right-click on the second file to compare with and select Compare with 'filenameyouchose'. The default tool used to diff sources is Visual Studio, but any other source diff tool like WinMerge can be used by navigating to Options Source File Compare Tool. Code Change Review through Global Code Diff. In the main menu, there are three options related to the baseline.
- Visual Studio Diff Git
- Visual Studio Diff Code
- Visual Studio Diff Branches
- Visual Studio Difference Between Build And Rebuild
- Visual Studio Code Diff
- Visual Studio Difference Between Project And Solution
- Default Rules
- Code Coverage Rules
- Default Trend Metrics
- Default Architecture Rules
- Code Smells Regression Rules
- API Breaking Changes Rules
- Code Diff Summary Queries
This document explains how to use the NDepend build comparison features, directly in Visual Studio and VisualNDepend.exe. This allows users to easily compare code in Visual Studio between the current version and a previous version without leaving VS. To use build comparison features specifically for reporting, please see Reporting Code Diff. |
Watch this video on comparing code changes since a baseline in Visual Studio (4 minutes)
Introduction to Comparing Code
Code evolution and maintenance are some of the most prominent characteristics of software engineering.Nowadays, Visual Studio relies mostly on Git to explore code changes. But there is mismatch: Git and other Source Control Managers deal with textual changes while Visual Studio deals with lines of code.These tools don't distinguish between comment changes, formatting changes, refactored code in methods, added types, method visibility changes or removed fields.In short, SCMs only look at code as text and don’t see the structure of purpose of the code
NDepend has advanced code evolution and code diff features that can distinguish between code changes (like method behaviour changes) and text changes (like comment changes).These features are not meant to compete with or replace the Source Control Manager.Instead, these features can be used as a complementary tool to track changes with a focus on code quality.
NDepend’s code diff tool for Visual Studio includes many features
- The code diff feature is based on the concept of a baseline: the current analysis result is compared against an older analysis result, which is called the baseline.
- Zipped source files are parsed. This way a source code diff can be performed against the baseline out-of-the-box, with no upfront configuration needed.
- The code comparison can be queried.This allows code rules to be enforced for code diff, like the API Breaking Changes rules.More on querying diffs here.
The default tool used to diff sources is Visual Studio, but any other source diff tool like WinMerge can be used by navigating to Options > Source File Compare Tool.
Code Change Review through Global Code Diff
In the main menu, there are three options related to the baseline
- New Issues since Baseline (self explanatory)
- Source Diff since Baseline
- Code Diff since Baseline
The option Source Diff since Baseline edits a code query that matches all code elements.The result of this code comparison is formatted specifically for an easy code review:
- Code elements are grouped in directories and source files.
- Directories and source files that contain changes are underlined.
- Directories and source files that are new since baseline are bolded.
- Directories that contain changes are expanded.
- Source files are not expanded by default, but expanding them shows any code element changes with the same font-based conventions.
- Double clicking a source file change automatically displays source comparison.
The option Code Diff since Baseline opens the search panel where you can perform a Search Change.The Search Change Panel is actually a CQLinq code query generator related to code changes.For example, in the screenshot below, we can see that asking for Method + Change + Code was Changed or was Added generates this code query:
The result can help your development team to perform Code Diff Reviews.Not only are all code changes easily identifiable at a glance, but for each method refactored, the developer is just one click away from seeing the code diff in the source files.Moreover, formatting and comment changes are not taken into account here.
Visual Studio Diff Git
The Search Change Panel’s options offer various possibilities to explore a code comparison in Visual Studio, including searching for code elements where only code was changed or where only comments were changed, where visibility was changed, where methods or classes were added or removed, and many more possibilities.
An extra option is to search a diff in third-party code, like asking for which library types are not in use anymore.There is often something interesting to learn by reviewing the API usage diff.
Typically, developers write tests for testing automatically refactored and new code.Another useful option is to search for diff coupled with code coverage by tests ratio, like asking for methods where the code was changed (i.e. refactored methods) and where it is not actually properly covered by tests.Reviewing how code diffs are covered by tests is made easy thanks to the Search by Coverage of Changes function.
Code Comparison from within the Source Code
In the Visual Studio Code Editor Window, you can run a Diff since Baseline from the right click menu. This menu is enabled only if the source has been changed since the baseline:
Also, since NDepend recognizes the code element currently being edited and right-clicked in source, the user can, for example, right click a namespace or a class and generate a query to list what was changed:
Code Diff from within the Solution Explorer
Clicking most of items in the Visual Studio Solution Explorer lets users explore the Diff since Baseline. The following items are supported:
- Solution
- Project
- Project Reference
- Folder
- Source File
- Code Element in Source File
One point to note, is that NDepend proposes a heuristic to infer namespaces from Solution Explorer folders.Indeed, it is a popular good practice to organize source code in a folder hierarchy that mirrors the namespace hierarchy.Right-clicking a folder can result in asking for code changes in a namespace, narrower in scope than looking at the entire project.
Exploring Architecture Changes with the Dependency Matrix
The Dependency Matrix shows a red tick on a cell when the dependency represented has been changed since the baseline.
- If it contains a plus character, it means that the represented dependency has been added since the baseline.
- If it contains a minus character it means that the represented dependency has been removed since the baseline.
- If it doesn't contain a character it means that the represented dependency has been removed since the baseline.
When hovering over a cell with a red tick, the dependency description explains how the dependency has changed.
Also, when right clicking such a cell, the pop-up menu proposes to initialize the matrix horizontal and vertical headers with the code elements involved in the dependency change.
Defining the Baseline for Comparison
Earlier in the post we introduced the concept of a Baseline for Comparison.This represents the previous snapshot version of the code base against which the comparison is done.Typically, the Baseline for Comparison will be the latest version of the code in production.
The Baseline for Comparison can be specified through the menu: Visual Studio > NDepend > Diff > Define the Two Snapshots to Diff > Define a Baseline for Comparison.The dialog shown below appears and lets us choose different options to define the baseline. The Baseline for Comparison option then persists throughout the NDepend project file.
Enjoy live code diffing in Visual Studio!
Learn more about configuring Visual Studio for Git.
Join the DZone community and get the full member experience.
Join For Freeafter almost six years, the post on how to configure diff and merge tool in visual studio git tools is still read by people that found it useful, but it is now really really old and needs to be updated.
that post was written when visual studio 2012 was the latest version and the integration with git was still really young, made with an external plugin made by microsoft and with really basic support. if you use visual studio 2017 or greater, you can simply go to team explorer and open settings of the repository.
figure 1: git repository settings inside visual studio team explorer figure 2: git settings inside visual studio figure 3: diff and merge tool configuration inside visual studio. Create bootable usb on mac.
settings pane contains a specific section for git where you can configure settings for the current repository or global settings that are valid for all repositories of the current user. Mysql 8 for mac.
if you open the repository settings, usually, you find that no specific diff and merge tool is set. merge and diff configurations are typical settings that are made at the user level and not for each individual repository .
as you can see, in figure 3, no diff or merge tool was set for the current repository; this means that it will use the default one for the user (in my situation is none). if you use only visual studio, these settings are not so useful; if you have a conflict during merge or rebase, visual studio will automatically show conflicts and guide you during merging.
if you are inside visual studio, it will handle diff and merge automatically, even if it is not configured as diff or merge tool. the rationale behind this choice is that if you are inside a tool (like vs) that has full support for diff and merge, the tool will automatically present you with diff and merge capabilities without checking repo configuration.
Update macbook air 2011. figure 4: git diff and merge section as saved from visual studio 2019 preview
this happens because when you open a git repository, visual studio monitors the status of the repository and, if some operation has unresolved conflicts, it shows the situation to the user without the need to do anything . the settings in figure 3 is useful only if you are operating with some other tool or with the command line. if you got a conflict during an operation started from any other tool (gui or command line), the procedure is:
opening vs
from vs team explorer, localize the local git repository and open it
go to the team explorer changes pane to start resolving conflicts
if you configured instead vs as diff and tool, you can simply issue a git mergetool
command and everything will be done automatically without any user intervention.
but to be honest, the latest vs git integration is really good and it is surely better to manually open the local repository. as an example, if you are doing a rebase from the command-line and you got conflicts, it is better to manually open vs, solve the conflict, and then continue to rebase the operation inside vs. if you receive further conflicts, you do not need to wait for vs to reopen it with the git mergetool
command.
but if you really want to configure vs as diff and merge tool, if you press 'use visual studio' button ( figure 3 ), you can modify your local gitconfig. the net result is similar to what i suggested in my old post, vs just adds the six sections for diff and merge in the config file.
Visual Studio Diff Code
if visual studio is your tool of choice, i simply suggest you configure it globally (file named %userprofile%.gitconfig ) so you can invoke the merge tool from everywhere and have visual studio handle everything.
hope this helps! let us know your thoughts in the comments below.
Visual Studio Diff Branches
Visual Studio Difference Between Build And Rebuild
Published at DZone with permission of Ricci Gian Maria, DZone MVB. See the original article here.
Visual Studio Code Diff
Opinions expressed by DZone contributors are their own.