TeamCity plugin for Visual Studio

When working with TeamCity and Visual Studio, we can do a lot of things right from within our IDE. We can trigger a remote run, fetch dotCover code coverage information from the server, view changes and builds from a tool window, navigate to unit tests and a lot more. In this post, we’ll be looking at some of these features. But first things first: let’s install this nifty tool!

Installing the plugin

Every TeamCity installation ships with several tools for IDE integration (with our IntelliJ IDEA based tools as well as with Visual Studio). We can find the plugin on every TeamCity server under the My Settings & Tools page. We can download the plugin right there!

Finding the TeamCity plugin for Visual Studio

After downloading and installing the plugin, we can find a new menu item in our Visual Studio.

TeamCity plugin for Visual Studio menu entry

From this menu, we can connect to our TeamCity server using the Login… menu item. After entering the URL to our TeamCity server and providing the correct credentials, we can start exploring.

Login to TeamCity

Remote run from Visual Studio

When developing a project in Visual Studio, we can initiate a personal build using the TeamCity plugin for Visual Studio. We call this a “remote run” because the build that is triggered runs on a TeamCity build agent, not on the developer’s machine. The interesting thing here is that this remote build uses the current version control repository sources plus the changed files in the developer’s IDE. All steps from the build configuration are executed for this personal build as well.

After changing some files locally, we can use the TeamCity | Remote Run (Local Changes) menu to trigger a remote build. In the dialog that opens, we can select the changes we made locally that should be included in this personal build. We can select all changes or cherry-pick just the changes we want to verify on the build server.

Local changes for personal build - remote run

Note that we’re using Subversion as the source control system here. Remote Run is available for TFS, Subversion and Perforce. When using Git or Mercurial, the workflow is slightly different. Check the documentation on branch remote run for more information.

When we click the Configure personal build… icon in the toolbar, we have to make some other decisions. First of all, we must select the build configuration we want to use for the personal build. Next, we can provide a comment for this personal build. This comment will be shown in the TeamCity web UI afterwards to describe the personal build.

One interesting option is the Pre-tested Commit checkbox and its related commit if setting. Using this, submitted code changes first go through testing. If all tests pass, TeamCity will automatically commit the changes to version control and integrate it in the next build. When tests fail, the code is not committed and the developer who made the change is notified about this. Here’s a chart of the pre-tested commit workflow.

Personal build configuration and pre-tested commit

We can even customize our build: put it at the top of the queue or add additional build parameters.

After clicking the Run button, TeamCity will run the selected build configuration for the included changes. We can see the results in the TeamCity web UI, consult the build log, check unit test results and so on.

TeamCity web UI personal build

My Changes

Since this post is about the TeamCity plugin for Visual Studio, we can also verify the status of builds triggered because of our changes by using the TeamCity | My Changes menu.

Overview of My Changes

Build log

From the toolbar, we can consult the build log for every personal build listed in the My Changes window. Clicking the Show Build Log icon (or right-clicking the build and selecting the appropriate context menu) will instruct the TeamCity plugin for Visual Studio to download the build log directly from TeamCity.

Build log from TeamCity downloaded in Visual Studio

Open Failed Tests

Did your changes cause a unit test to fail? No worries: we can use the Open Failed Tests context menu from the My Changes window in order to see what is going on. From the window that opens we can re-run the failing tests locally using the ReSharper test runner.

Unit tests

Code Coverage

When you have dotCover installed on your machine, the TeamCity plugin for Visual Studio enables us to view code coverage results. Using the TeamCity | Coverage menu item we can select a code coverage snapshot to open.

TeamCity dotCover code coverage

After selecting and opening a snapshot, we get dotCover’s test runner showing code coverage. We can even double-click a class from the snapshot shown and explore code coverage at the statement level.

dotCover snapshot from TeamCity

Investigate a build

Whenever a build fails, we can volunteer to fix the build by starting an investigation. From the TeamCity | My Investigations menu, we can manage our investigations and take action on open investigations by either fixing it or giving up (when working in developer teams in Belgium, that last option typically results in having to bring pastries for the team).

Investigate a build

Open in IDE

The TeamCity web UI features an Open in IDE button on many places. For example, when inspecting changes that were included in a build, we can open the file that was built in our IDE by clicking the IDE icon.

Open in IDE from TeamCity web UI

We can open tests in the IDE as well, again using the Open in IDE function. When working with tests, this will trigger Visual Studio to open the ReSharper test runner and display the selected test.

Open test in IDE

Give the TeamCity plugin for Visual Studio a go and let us know what you think!

This entry was posted in How-To's and tagged , , , , , . Bookmark the permalink.

10 Responses to TeamCity plugin for Visual Studio

  1. Michael Teper says:

    It would be great if the VS plugin was available via the VS gallery, and automatically notify of updates, like NuGet.

    http://visualstudiogallery.msdn.microsoft.com/

    -Michael

  2. Joe White says:

    Question about your first screenshot under “Remote run from Visual Studio”, where you’re selecting which changes you want to include in the build. I notice that window is showing a bunch of things that don’t belong in version control, like the bin and obj directories and the .suo file.

    Normally things like bin and obj and *.suo would be listed in svn:ignore. Is this just a hastily-put-together sample where you hadn’t got around to adding svn:ignore yet, or is this showing that the plug-in doesn’t actually honor svn:ignore and shows ignored files even though they don’t belong in the build?

  3. Maarten.Balliauw says:

    Hi Joe,

    Indeed I haven’t specified any of the ignore rules in this sample, the plugin does honor svn:ignore like you would expect. I will be updating the screenshots accordingly.

    Best regards
    Maarten

  4. Daniel says:

    I’d love to use this feature but there doesnt appear to be support or mercurial source control. Is there a plugin for this I can get a hold of?

    Thanks
    Danny

  5. jk says:

    After installing the Visual Studio addin from the TeamCity “My Setting & Tools” page, all the menu entries are grayed out except for “Help”. I can’t log into the server or do anything else because of this. Is there some version conflict with this TFS 2012 or with Resharper perhaps?

    Here is the info for the TeamCity Addin:
    ===================
    TeamCity Addin 8.0
    Version: 8.0.2 (build 27482)

    Visual Studio 11.0.60610.1.
    ===================

    And I also have Resharper installed (which works):

    ===================
    JetBrains ReSharper 7.1.1 C# Edition
    Build 7.1.1000.900 on 2012-12-13T21:22:48

    License server at http://vopcedts02.global.ual.com:8090/licenseServer is used
    Plugins: none
    Visual Studio 11.0.60610.1.
    ===================

    • Kevin says:

      I had this too. It turned out that I just needed to load a solution. Once I’d done that, all the options were available as per the instructions above :)

      • Fran says:

        I have the same issue, except I have it in VS2010 even with a solution loaded. You can see the green icon on the bottom-right that I’m logged in and I can also see my local changes window pulling the changes but all options are grayed out in the VS menu as well as on the green icon and the menu in the local changes window. Very strange. It’s like it is not recognising that a solution is loaded.

  6. Morgan Larosa says:

    Are there any plans to better integrate the mercurial/git remote-run functionality with the Local Changes feature? I’d love to be able to use it for a ‘pre-tested push’ for unpublished commits in my local repo.

  7. Syed Salman Qadri says:

    Can you guys please also add git support in the plugin?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">