Visual Studio ALM Links–Week 15/2013


Warning: sizeof(): Parameter must be an array or an object that implements Countable in C:\HostingSpaces\fcusccqp\codewrecks.com\wwwroot\blog\wp-content\plugins\ad-injection\ad-injection.php on line 824

Warning: count(): Parameter must be an array or an object that implements Countable in C:\HostingSpaces\fcusccqp\codewrecks.com\wwwroot\blog\wp-content\plugins\ad-injection\ad-injection.php on line 831

Gian Maria.

Visual Studio ALM Links–Week 14/2013


Warning: sizeof(): Parameter must be an array or an object that implements Countable in C:\HostingSpaces\fcusccqp\codewrecks.com\wwwroot\blog\wp-content\plugins\ad-injection\ad-injection.php on line 824

Warning: count(): Parameter must be an array or an object that implements Countable in C:\HostingSpaces\fcusccqp\codewrecks.com\wwwroot\blog\wp-content\plugins\ad-injection\ad-injection.php on line 831

Gian Maria

Visual Studio ALM Links – Week 12 / 2013


Warning: sizeof(): Parameter must be an array or an object that implements Countable in C:\HostingSpaces\fcusccqp\codewrecks.com\wwwroot\blog\wp-content\plugins\ad-injection\ad-injection.php on line 824

Warning: count(): Parameter must be an array or an object that implements Countable in C:\HostingSpaces\fcusccqp\codewrecks.com\wwwroot\blog\wp-content\plugins\ad-injection\ad-injection.php on line 831

Gian Maria Ricci

How to configure diff and Merge tool in Visual Studio Git Tools

If you are using Visual Studio plugin for Git, but you have also configured Git with MSys git, probably you could be surprised by some Visual Studio behavior. The most obvious one is that commits are done using the wrong user.name and user.email configuration as I’ve described in Visual Studio Tools for Git, a primer, other one can be: tools used to do merge and diff during conflicts.

Suppose you are working with Visual Studio, you issue a pull and find that there is some conflicts in repository.

image

Figure 1: Pull operation has a conflict

Now you should resolve all conflicts before being able to continue work: you can click on file name that is conflicting and you are presented with a UI different from the one you are used with standard TFS Source control.

image

Figure 2: Ui to manage conflicts when you are using Git in Visual Studio

If you press “compare files” to visualize diff of files, it could happen that kdiff3 is opened to visualize the difference, instead of resolving directly inside Visual Studio.

image

Figure 3: File compare is done with Kdiff3 instead of visualizing them inside Visual Studio

This happens because Visual Studio Git Plugin uses standard git configuration, your local repository probably does not have any specific tools for diff and merge (unless you configured them), so global settings are honored. To verify actual settings you can open a Git Bash on the repository, issue a git config –list command and look at merge.tool and diff.tool settings

image

Figure 4: Actual configuration for merge and diff tools

Since I’ve configured kdiff3 as standard conflict resolution tool after I installed msysgit, Visual Studio honors this settings and opens kdiff3 to do the diff, even if I’m inside the IDE of VS. If you prefer using Visual Studio you should configure VS as diff and merge tools and you can choose to configure this at repository level or at global level. To change only a local repository, open .git folder and edit config file adding this piece of configuration.

Edit: Due to a strange problem with my blog that alters the content of the configuration,

The exact configuration to use visual studio 2013 is found into this gist: https://gist.github.com/alkampfergit/fca40445f118095e37f549f7058e71cd

The exact configuration to use visual studio 2017 is found into this gist: https://gist.github.com/alkampfergit/46883dcef9fb4bee39a56ce0e69dcf24

If you want to change global configuration, you should edit a file named .gitconfig usually located inside your profile folder (c:\users\yourname).

You can edit config file with a standard notepad or text editor, it is a simple text configuration file. Once saved, return to Visual Studio and choose again to compare files, you should now being able to resolve conflicts directly from Visual Studio. If you like this option you can setup Visual Studio as diff and merge tool in global git configuration, so it will be available for every repository you are working with.

image

Figure 5: Once configured, Visual Studio is used as a diff tool for Git repository

You can use Visual Studio not only for diff, but also for merge; press Merge button and you will be prompted with a merge UI.

image

Figure 6: Merge tool of Visual Studio

Once a file is merged, you can Press the “accept Merge” button in the top left area to resolve conflict and once all conflicts are resolved, you can go to commit pane and commit locally result of merge operations, and everything is done from inside Visual Studio.

Gian Maria.

Unable to build on TFS with a project managed with Nuget and automatic restore

To reduce the size of the repository and to easy dependencies management, nuget is a good solution, and when is time to create a build in TFS you can simply Enable Nuget Package Restore and let the build machine download the dependency for you. This works perfectly even on TF Service (tfs.visualstudio.com) because the Elastic Build is configured to restore packages during build.

This is really cool, until your build start to fail for missing references. If you look at detailed build log you can find error like this one.

warning MSB3245: Could not resolve this reference. Could not locate the assembly “EntityFramework”. Check to make sure the assembly exists on disk.

First of all you should verify if your build agent correctly restored nuget packages during the build. You should find messages like this in the build log.

PrepareForBuild:
   Creating directory “obj\Debug\”.
RestorePackages:
   “C:\a\src\src\.nuget\nuget.exe” install “C:\a\src\src\xxxx.Entities\packages.config” -source “”  -RequireConsent -o “C:\a\src\src\packages”
  Successfully installed ‘EntityFramework 5.0.0’.
ResolveAssemblyReferences:
   Primary reference “EntityFramework”.

If packages are restored correctly, but TFS builds still fails, probably your projects are referencing packages from a wrong location (this can happen if  you moved your solution in different folder of your source control repository). Do not worry, the solution usually is a simple reinstallation and reconfiguration of all packages; go to Package Manager console and type

PM> Update-Package -Reinstall

Now if you check-in your code again, after nuget reinstalled and reconfigured everything, build should be fine.

Gian Maria.