Friday, April 29, 2016

About Xamarin build with VSTS Hosted Agents

Last friday (22/04/2016), during an event organized by DotNetToscana, I had a talk about the build of Xamarin apps with Visual Studio Team Services' Hosted Agetn 

To make the build works, I had to add two tasks to manage the Xamarin License to the build definitoin: one to activate the license and another one to deactivate it after the build operation. 

There is a small (and big at same time) news about these two tasks: they are no more required now
Indeed, with the most recend update of the VSTS platform, the Hosted Build Agents have already an internal Xamarin license which is automatically activated when they have to perform some build opreations against Xamarin projects. 

So, to sum up, if you have or want to create a Xamarin build definition (and use VSTS Hosted Agent) now you don't have to add the license activation and deactivation tasks anymore. 

Have a good build :)

Tuesday, April 5, 2016

Introducing BugGuardian.MVC and BugGuardian.WebForms

Today I'm very excited to announce that I have released two additional modules for BugGuardian.

For who doesn't know it, BugGuardian is a library that allows to easily create a Bug or a Task work item on your Visual Studio Team Services account or on your on-premises Team Foundation Server 2015 in the case your application throws an Unhandled Exception.

To better support the integration of this library with web projects, today I'm announcing the availability of BugGuardian.MVC and BugGuardian.WebForms.

BugGuardian.MVC (GitHub, NuGet) is an extension for BugGuardian specifically written to support MVC applications. 
It adds an Action Filter to your application to let you automatically intercept all the exceptions.

BugGuardian.WebForms (GitHub, NuGet), instead, is an extension for BugGuardian specifically written to support WebForms applications.

They are based on the new BugGuardian version 1.3.0 and they support projects written with the .Net Framework v4.0 and above.

As it is for BugGuardian, these two additional libraries are OSS so feel free to see their code on GitHub.

If you encounter any issue using these libraries, please let me know through the GitHub Issues pages and I'll fix the problem as soon as possible!

Again, I want to thanks my friend and fellow MVP Marco Minerva (@marcominerva, GitHub) for the support and the suggestions.

Thursday, August 20, 2015

Welcome BugGuardian

Someone of you has maybe noticed the I did only few post in the last months. This happened because of two main reasons.

The first one is, as some of you already know, I moved in another country far away from home, with a completely different culture and language, to start a new adventure. This inevitably took a lot of time from the already small amount of spare time I have.

The second reason I wasn't so active here, that is also the reason of this post, is that I worked on a new project that I have released today: BugGuardian.

What is BugGuardian
BugGuardian is an Open Source library, written in C# like Shared Project, that allows to easily create a Bug work item on your Visual Studio Online account or on your on-premises Team Foundation Server 2015 in the case your application throws an Unhandled Exception.
It can also be invoked manually in try/catch blocks to keep track of handled exceptions.

It supports applications written with the .Net Framework v4.0 and above, and it can be used on every kind of project, including:
  • MVC
  • WPF
  • Windows 8 / 8.1 Apps
  • Windows Phone 8 / 8.1 Apps
  • Universal App
  • Universal Windows Platform Apps (Windows 10)
  • and so on...

As I mentioned, it is OSS so you can find the sources on GitHub.

To let you install and use it without having to build the sources by your own, I have published it on NuGet. Just search for BugGuardian in the Package Manager GUI or run the following command in the Package Manager Console:
Install-Package DBTek.BugGuardian

Usage, support and Feedback
Refer to the project documentation to find examples about how to use this library. You can also find some code samples in the TestApps folder.

Anyway, just to make an example and to show it's really simple to use, this is the code you need to manage an exception and to open a Bug on your VSO / TFS:

using (var creator = new DBTek.BugGuardian.Creator())

If you encounter any issue using this library, please let me know through the Issues page and I'll fix the problem as soon as possible!

I'm waiting for your feedback :)

I want to thank you my friend and fellow MVP Marco Minerva (@marcominerva) for the support, the patience and the Code Review.

Monday, July 27, 2015

Deploy a Web App to Azure with the Visual Studio Online Build

In this post we are going to see from sratch how to deploy a solution to an Azure Web App using the new Visual Studio Online Build platform.
To do it, we will use only the web portal of VSO.

Connect Azure to VSO
First of all we have to let Visual Studio Online know that we have an Azure account we want to use as deploy endpoint for our solution. Go the the Team Peoject Settings page (clicking on the button in the upper right corner of the project page), click on the "Services" tab, then on "Add new Service Connection" and then on "Azure".

At this point a pop-up will appear and we have to insert the ID of the Azure subscription which contains or will contain the Web App to publish, a name for it and the authentication mode.
We can use either a subscription certificate or the credentials.

When done, our Azure subscription and our VSO account will be connected (for this project).

Create the build definition
Now that we have linked VSO and Azure, let's go to the Build section of the project and create a new deployment build definition.

We eant to deploy to Azure, so in the "Deployment" section click on "Azure Website" (like shown in the image).

This creates a new build definition with some steps to configure.

Let's see how to proceed step-by-step.

The first one is the "real" build task. It's completely customizable but the most important thing is to define the solution file it has to use as build source. Select it like shown in the image, near the red arrow.

In the second step we have to set the how to execute the post-build Unit Tests. If we don't have unit tests (that is bad...) or we don't want to execute them (also this is bad :) ), we can safely remove this step using the "X" button that appears when the mouse pointer is over it.

The third step is the most important one for our scenario, because it publishes the build result to the Azure Web App.

In its settings there is a drop down where to select the target Azure subscription (if the previous Azure service connection worked properly). Then, in the "Web App Name" textbox, we have to write the name of the Web App we want to deploy. In theory this also appears as a drop down itself, but currently it doesn't load the existent Web Apps names (don't forget that the new Build platform is still in preview)

For this reaso, here I've written down some notes about the Web App name
  • If we use a non-existent Web App name, it will create it on our Azure subscription using the selected region
  • If we use a Web App name that doesn't exist in our subscription but which already exist in the selected region, the deploy process will fail
  • If we use a Web App name that already exists in our subscription but it is in a region different from the selected one, the deploy process will fail
  • If we use a Web App name that already exists in our subscription and it is in the selected region, the deploy will use it as target and will update it.

So pay attention about what we write :)

The two remaining steps allow us to index and to publish the application symbols (suggested, to have more information in the case of unhandled exceptions) and to publish the build artifacts somewhere.

When all the parameters are set we can go ahead and save our build definition, giving it a name.

We can also change all the default parameters in the upper tabs to customize the build process accordingly our needs.

Let's deploy!
Now that we have completed all the customizations, it's the moment to launch the build and to verify that the deploy works fine.

To start the build, click on the "Queue build" button in the build definition toolbar or in the contextual menu.

When we click on that button, VSO will queue a build based on our build definition and will execute it either on our servers or in a Microsoft Datacenter (if we have chosen to do it with the hosted agents).
Anyway, the build progress will be shown in the real time web console that appears as soon as the build is queued.

When is starts, it firstly execute the build and test tasks:

Then, if both are successful, the deploy to Azure:

When all the tasks will successfully finish, we have our web application deployed and running on Azure. Easy!

Tuesday, June 16, 2015

Create a RSS reader in an Umbaco 7 MVC Partial View

There are several way to create and embed a RSS reader in an Umbraco page: using custom controllers, using XSL macros, etc...

But wath if we want to use a normal MVC Partial View without to develop a custom controller?

Well, it is really simple to achieve this goal with just a few C# lines.

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@using System.ServiceModel
@using System.ServiceModel.Syndication
@using System.Xml
 string url = "http://your_blog_rss_url";
 XmlReader reader = XmlReader.Create(url);
 SyndicationFeed feed = SyndicationFeed.Load(reader); 

@foreach(var feedItem in feed.Items)
 <div class="col-md-6">
   <div class="date">
    <span class="day">@feedItem.PublishDate.Day</span>
    <span class="month">@GetMonthName(feedItems[i].PublishDate.Month)</span>
   <h4 class="heading-primary"><a href="@feedItem.Links[4].Uri">@feedItems[i].Title.Text</a></h4>
   <p>@(feedItem.Summary.Text + "... ") <a href="@feedItem.Links[4].Uri" class="read-more">read more <i class="fa fa-angle-right"></i></a></p>

As you can see, only a couple odlines are required. At this point we just have to include this partial view in the page where we want to see our RSS feed.
Obviously, you can change the layout (the one here is what I used in my project).

Only 2 notes:
  1. I used "feedItem.Links[4].Uri" to retrieve the blog post url, this works if you use blogger. If you use other blogging platforms as sources, you'll have to check the Links collection to know "where" is the url you want.
  2. The "@GetMonthName" is just an Helper to convert the "number" of the month into its name.