Visual Studio Team Services – NuGet Packages

Since a couple of months you can download an extension for Visual Studio Team Services (VSTS) to manage your own NuGet packages. The extension is called Package Management. It’s is still in preview, but Microsoft supports it already as were it released. With this tooling you can host your own NuGet feed, containing your – or other custom NuGet packages. The big advantage is that you can share NuGet packages with your organization. They are available for consuming from your Team Build too. Beside version control, workitem management and tracking bugs, in my opinion Team Build is a key feature of VSTS, so this is really great news!

Continue reading

Started a new MCSD certification : Azure Solutions Architect

Last week I decided to get started with a new MCSD certification: Azure Solutions Architect. In a world where more customers want to take advantage of Microsoft Azure, it’s important to get my knowledge up-and-running. At my own company we are using Microsoft Azure for almost all our backend tasks. We are hosting sites, web services, SQL Azure databases and for example Virtual Machines with a regular SQL Server installation. We can manage them fine, but for some real troubleshooting our knowledge is not sufficient.

Continue reading

Missing dropdown controls in the code editor

Today I encountered a strange behavior in the code editor of Visual Studio 2015. The dropdown controls with the list of controls and procedures were missing! I thought it was a glitch in the software; as it still not officially released, you could expect some issues. But no… I discovered today that it is a feature you can enable and disable. Go to Tools > Options > Text Editor > All Languages and simple check the option ‘Navigation bar’. Some research on the Internet learned me that this is a feature that already exists since years, so it is not only available in Visual Studio 2015. Sometimes I’m still amazed by what I NOT know about my favorite piece of software on my machine.

missingnavigationbar_1

Year first date literals in Visual Basic .NET

Since I write on a daily base unit tests, I’m wondering more and more why there is not an easy – and especially unambiguous – way to provide a hardcoded date to a variable or procedure argument. Do you know, without any doubt, what this date actually means?

Dim thisYearsBirthday As Date = #5/6/2015#

Was I born on the 5th of June or the 6th of May? Visual Basic .NET will support now a good ISO-standard, which starts with the year. It follows the convention of ‘yyyy-MM-dd’ and you can even use slashes as separators. You can also provide the time if you want.

Dim todayDateWithDash = #2015-02-13#
Dim todayDateWithSlash = #2015/2/13#
Dim nowDateTime24 = #2015-02-13 19:59:00#
Dim nowDateTime12 = #2015-02-13 7:59:00 PM#

Console.WriteLine(todayDateWithDash.ToLongDateString())
Console.WriteLine(todayDateWithSlash.ToLongDateString())
Console.WriteLine(nowDateTime24.ToString("yyyy-MM-dd HH:mm:ss"))
Console.WriteLine(nowDateTime12.ToString("yyyy-MM-dd hh:mm:ss"))

The results are shown in the screenshot below. Please note that you can specify the time part as 24-hour format as well as the 12-hour format. The ToLongDateString() extension methods formats the dates to the Dutch language, but I’m sure that you will understand the concept.

vb2015yearfirstliteralnoshadow_thumb

BTW… for the people who are still doubting about my birthdate… I was born on a 6th of May!

Show generated SQL of Entity Framework in Visual Basic .NET

When you are writing LINQ queries against an Entity Framework context, you don’t have to worry about the SQL which is generated and executed. However, in some cases you may be interested in this SQL. It’s quite easy to switch on a logging mechanism which will be display all executed SQL in your Debug window. You have to provide an Action to the DbContext.Database.Log property. You provide a lambda with the functionality you want. If you want you can log this output also to a file or for example the Clipboard.

Continue reading

Query a CSV file with LINQ and Visual Basic .NET

Once in a while I’m still surprised by the functionality of LINQ. I saw a question on the Internet from a developer who asked if it is possible to query against Comma Separated Values (CSV) in a file. Based on one of the answers I wrote this post, because it’s really great what you can do with so less source code. As you probably already knew, I’m a big fan of LINQPad, which I will use to demo my examples. One of the nice features is the extension method .Dump(). As you can imagine, this will dump (or write) the data to the Results window of LINQPad. It works only in LINQPad, so, if you want to try this source in Visual Studio, you have to remove the .Dump() statements and write your own code to display the results.

Dim path = GetAndCreateFilePath()
 
Dim results = (From line In File.ReadAllLines(path).Dump("Lines read")
               Let value = line.Split(",").
                                Skip(1). ' Skip the RowNumber
                                Select(Function(x) Integer.Parse(x))
               Select New With {.MinimumValue = value.Min(),
                                .MaximumValue = value.Max(),
                                .Average = value.Average(),
                                .RowTotal = value.Sum()}).ToList().
                                                          Dump("Statistics")
  
File.Delete(path)

As you can see in the VB.NET code above, first we create a file, then we read and query this file and in the last statement we delete this temporary file. Before diving more deep in this code, you have to see what we are writing to disk in the GetAndCreateFilePath() procedure. The lines starts with a row number and four numeric values.

Private Function GetAndCreateFilePath() As String
 
    Dim filePath = Path.GetTempFileName()
 
    Dim stringBuilder As New StringBuilder
    With stringBuilder
        .AppendLine("1, 309, 88, 125, 825")
        .AppendLine("2, 458, 258, 198, 189")
        .AppendLine("3, 87, 587, 675, 136")     
    End With
 
    File.WriteAllText(filePath, stringBuilder.ToString())
 
    Return filePath
 
End Function

In the first code snippet we querying a LINQ statement against a List(Of String), the line variable. With help of the Split() function, we divide this line into an array of String, with in each element a value from the line. Because we are not interested in the first value, the Row Number, we skip this value with Skip(1). As a side note it’s good to mention that starting from Visual Basic.NET 2015 you can use inline comments. In this example it really helps to explain why we are skipping the first element of the array. If we have selected the correct range of data, we can easily project this data, and calculations on it to an anonymous type. And as earlier said, the Dump() method writes the data to the Results window of LINQPad. You can use this method more than once in one LINQ statement. First we are writing the actual lines read and at the end the statistics of the data. The power of LINQ is really amazing!

querycsvwithlinqandvisualbasicnet

Saving customized Window Layouts

I think it’s not new for you that in Visual Studio you can customize the position, size and behavior of windows to create window layouts that work best for various development workflows. When you customize the layout, Visual Studio remembers it. For example, if you change the docking location of the Properties Window and then close Visual Studio, the next time that you start, even if you are working on another computer, the Properties Window will be docked in that same location.

Continue reading

Left Outer Join in LINQ with Visual Basic .NET

Many developers encounters problems when trying to mimic the functionality of a Left Outer Join in LINQ. To be honest, the needed code is on first sight a bit strange. You can use a Group Join … Into .. and the DefaultIsEmpty() method. Let’s start with a regular (Inner) Join example. It uses the NorthWnd database and will retrieve all customers with at least one order.

Continue reading