Getting started with kpm

•November 20, 2014 • Leave a Comment

1,2,3, contact!

I’m not sure if there’s anyone still reading this, but I’ve decided to restart writing here again. I’ll be using this blog to document my experiences with the new ASP.NET 5.0 (for which there’s already a VS 2015 preview version). I’ve decided to do this since I won’t be updating my PT books on these subjects.

If you haven’t been living under a rock, you’ve probably heard about the latest release of ASP.NET, aka ASP.NET vNext. vNext is supposed to use a new stack, where you’ll find several of the traditional .NET features split into several packages that you’ll only load when you really need them (pay-for-play model). You’ll also find a new unified web stack, with simple packaging and versioning rules which should ease the problems associated with side by side run of different versions.

The new platform uses a new runtime/SDK, known as KRuntime. In order to get a specific version of the runtime (yes, there are several versions, based on architecture – 32 vs 64 bits – and features – CLR vs CoreCLR), we’ll need to resort to the K Version Manager tool (aka kvm). The docs already have all the details on how to install the kvm tool, so I’ll concentrate on looking at what we can do with it. Before going on, it’s worth it pointing out that kvm is simply a Powershell script, so nothing prevents you from opening it in your favourite text editor and seeing what it does.

One of the first things we’ll need to do is update the runtime to the latest version by using the upgrade option:

kvm upgrade

Running this command will end up upgrading the x86 CLR K runtime and setting it as the default runtime that is being used by your profile. You can always update the amd64 version (64 bits) by writing the following:

kvm upgrade –amd64

Notice that this will also promote the 64 bits as the default active runtime for your profile. And sure enough, you can also update the Core CLR by using the –r option. For instance, here’s how to upgrade the 64 bits Core CRL K runtime and set it as the default:

kvm upgrade –amd64 –r CoreCLR

Since you can have lots of runtime versions installed in a machine, it would be really great to have a way to list all of them. And that’s why there’s a list option:

kvm list

Running the previous command on my machine results in the following:

Active Version     Runtime Architecture Location                    Alias
—— ——-     ——- ———— ——–                    —–
       1.0.0-beta1 CLR     amd64        C:\Users\Luis\.kre\packages
       1.0.0-beta1 CLR     x86          C:\Users\Luis\.kre\packages
  *    1.0.0-beta1 CoreCLR amd64        C:\Users\Luis\.kre\packages default
       1.0.0-beta1 CoreCLR x86          C:\Users\Luis\.kre\packages

As you can see, we’ve ended up getting the Core CLR 64 bit version set up as the default active runtime. Notice also that the active runtime is aliased to the default name. kvm supports aliases operations by using the alias parameter. When used without any more info, it will simply report all the current aliased versions:

PS C:\code\git\home> kvm alias

Alias   Name
—–   —-
default KRE-CoreCLR-amd64.1.0.0-beta1

You can also pass a name to the alias and that will return its associated runtime version. For instance, if I pass it the default name, here’s what I’ll get on my machine:

PS C:\code\git\home> kvm alias default
Alias ‘default’ is set to KRE-CoreCLR-amd64.1.0.0-beta1

Now, as we’ve seen, we have 4 versions installed by default and nothing prevents you from creating alias for them. For instance, here’s how we can create a new alias for the 64 bits Core CLR runtime version:

PS C:\code\git\home> kvm alias CoreCLR64 1.0.0-beta1 -amd64 -r CoreCLR
Setting alias ‘CoreCLR64′ to ‘KRE-CoreCLR-amd64.1.0.0-beta1′

And just to be sure that we did end up getting what we wanted:

PS C:\code\git\home> kvm alias

Alias     Name
—–     —-
CoreCLR64 KRE-CoreCLR-amd64.1.0.0-beta1
default   KRE-CoreCLR-amd64.1.0.0-beta1

PS C:\code\git\home> kvm alias CoreCLR64
Alias ‘CoreCLR64′ is set to KRE-CoreCLR-amd64.1.0.0-beta1

Now, aliases are quite useful because we can use them with the other options that can be passed to kvm. For instance, let’s say that we want to use the Core CLR 64 bits version as the default runtime. Since we’ve created the CoreCLR64 alias, them we can simply pass that name to the kvm use command:

PS C:\code\git\home> kvm use CoreCLR64
Adding C:\Users\Luis\.kre\packages\KRE-CoreCLR-amd64.1.0.0-beta1\bin to process PATH
PS C:\code\git\home> kvm list

Active Version     Runtime Architecture Location                    Alias
—— ——-     ——- ———— ——–                    —–
       1.0.0-beta1 CLR     amd64        C:\Users\Luis\.kre\packages
       1.0.0-beta1 CLR     x86          C:\Users\Luis\.kre\packages
  *    1.0.0-beta1 CoreCLR amd64        C:\Users\Luis\.kre\packages CoreCLR64, default
       1.0.0-beta1 CoreCLR x86          C:\Users\Luis\.kre\packages

If we didn’t had the alias, we’d have to specify the version, CPU and flavour of the CLR we want to use (sure, there are defaults, but my brain is already lagging for my daily tasks, so I won’t really be memorizing any of them):

PS C:\code\git\home> kvm use 1.0.0-beta1 -amd64 -r CoreCLR
Adding C:\Users\Luis\.kre\packages\KRE-CoreCLR-amd64.1.0.0-beta1\bin to process PATH
PS C:\code\git\home> kvm list

Active Version     Runtime Architecture Location                    Alias
—— ——-     ——- ———— ——–                    —–
       1.0.0-beta1 CLR     amd64        C:\Users\Luis\.kre\packages
       1.0.0-beta1 CLR     x86          C:\Users\Luis\.kre\packages
  *    1.0.0-beta1 CoreCLR amd64        C:\Users\Luis\.kre\packages CoreCLR64, default
       1.0.0-beta1 CoreCLR x86          C:\Users\Luis\.kre\packages

As you can see, the result is precisely the same and that’s why I prefer to create an alias in order to reduce the required typing (yes, I’m lazy!).

Whenever you want to remove an alias, you should use the unalias option:

PS C:\code\git\home> kvm unalias CoreCLR64
Removing alias CoreCLR64
PS C:\code\git\home> kvm list

Active Version     Runtime Architecture Location                    Alias
—— ——-     ——- ———— ——–                    —–
       1.0.0-beta1 CLR     amd64        C:\Users\Luis\.kre\packages
       1.0.0-beta1 CLR     x86          C:\Users\Luis\.kre\packages
  *    1.0.0-beta1 CoreCLR amd64        C:\Users\Luis\.kre\packages default
       1.0.0-beta1 CoreCLR x86          C:\Users\Luis\.kre\packages

There’s one final option which you can use with the kvm command: install.You can use this option to install a specific runtime. It works in a similar way to the upgrade/use options, so I won’t be giving any examples of its usage here.

Before ending, I’d just like to mention the existence of the –g and –f flags, which can be used with the upgrade, install and use options. The –g flag can be used to persist changes globally across the machine (instead of just saving them on the current user profile).As for the –f flag, you can use it to force the execution of the current request. For instance, if you want to force the download of a previously downloaded runtime, you can use the following command: kvm update –f.

And that’s it for now. Stay tuned for more on the ASP.NET vNext.

Book review: Propose, prepare, present: hot to become a successful, effective and popular speaker at industry conferences

•June 18, 2013 • Leave a Comment

[Disclaimer: I’ve received a copy of this book for reviewing]

In this (really!) short book, Alistair Croll presents you several tips on how to improve your chances of becoming a good professional speaker. Alistair starts by introducing the conference industry world. Having an idea about how it works is important for understanding the risks and obstacles you might face. After this introduction, you’ll see how you can adapt an idea to a specific type of event. As you’ll find out (if you read the book), having a good idea is not enough for making into the conference as a presenter. You’ll probably need to have one or two good topics, write a good CFP about it and, if you get picked, you’ll probably need to adapt it to the available sessions/slots.

Chapter 3 is a great one because it will present several tips that will help you get chosen from the available candidates. It also presents several things which will probably hurt you during the process, so you should really pay attention to this chapter. The last two chapters give you some tips on how to improve your presentations and on how you can improve your chances of making money at these conferences.

Typically, this is not the sort of book I read. However, I was looking for something to give me some tips on this subject (conferences) and this book was really what I needed to get an overall look on the topic. Overall, I’m giving it a 7/10.

Book review: UX for Lean Startups

•June 7, 2013 • Leave a Comment

[Disclaimer: I’ve received a copy of this book for reviewing.]

Nowadays, there are no doubts about the role UX plays in getting a great product. Unfortunately, UX is generally associated with costly processes which involve lots of design. In this book, Laura Klein does an excellent job in showing you how to apply several techniques in  order to reduce the time and money which is typically spent in this area.

Even though the book has UX in its title, the truth is that book concentrates on showing you several techniques that will help you continuously test the user experience. No, I’m not talking about color use or stuff like that. I’m talking about techniques which will help you validate if the problem you’re trying to solve deserves to be solved (ie, should you be wasting your time and money building this product) or that will improve the way you run your qualitative and quantitative research and testing. In other words, Laura introduces several approaches which will help you apply lean principles to UX design.

Looking at its title (UX for Lean Startups) might mislead you into thinking that this book is for someone who wants to create a startup. In my opinion, it’s not. In fact, I’d say that given the importance that UX plays in software, the book’s title should be something like UX for Lean Developers. But hey, that’s just me Smile

Overall, I’m giving it a 8/10.

My ASP.NET 4.5 is out

•April 4, 2013 • Leave a Comment

I’ve been so busy that I’ve forgot to mention that my ASP.NET 4.5 book (written in Portuguese) is out.

Book review: CLR via C#

•February 25, 2013 • Leave a Comment

[Disclaimer: I’ve received a copy of this book for reviewing]

Yesterday I’ve finally finished reading Jeffrey Richter’s last book CLR via C#, 4th edition. I’ve been getting a copy of this book (buying or being lucky enough to get a review copy) since it was called Applied Microsoft .NET Framework Programming. Each new edition ends up adding new cool stuff and this last edition didn’t disappoint. Besides Garbage Collector chapter rewrite, this latest edition introduces the new Reflection API (introduced by .NET 4.5)  and presents several new concepts associated with the new WinRT framework. If you’re a die hard C# programmer, you should be pleased to know that the book has been updated to illustrate the new C# 5.0 async features introduced by the latest .NET framework release.

So, this is really a book I love and fortunately for us developers, Jeffrey has been doing an excellent job of maintaining and updating it during these last years. In my opinion, this is still the .NET reference book every developer should buy and read. My score: 10/10.

Book review: The art of SEO

•February 18, 2013 • Leave a Comment

[Disclaimer: I’ve received a free copy of this book for reviewing]

In these last couple of days, I’ve spent most of my free time reading this book. It’s a really thick book (I must confess that is was way more thicker than I was expecting initially). It does cover a lot of ground and it’s probably the best reference on the subject available on print. It’s a little dense and I wouldn’t recommend it to someone who is just starting doing web development. Even though it covers several topics in depth, I must say that chapter 7 is really a must for anyone interested in understanding how links are used for ranking pages.

Even though the book has lots of examples (I think it would be better to reduce them, specially the ones presented in the first chapters), this isn’t a platform specific book. In other words, don’t expect to get instructions on how to perform a specific task for server A or platform B. Instead, expect to find lots of examples that can be used across all platforms. Overall, I liked the book and that’s why I’m giving it an 8/10.

The–LiteralPath parameter

•February 15, 2013 • Leave a Comment

It’s 2013, we’ve got Powershell for a couple of years now, so it’s only natural to automate things, right? At least, that’s what I try to do. So, one of the things I’ve ended up doing some time ago was writing a simple script for copying files from an USB pen to a specific folder. As you can see, it’s really simple:

ls j:\ | foreach { 
  $itemName = $_.Name.Replace('.', ' ') 
  $destination = ls | where { $itemName -match $_.Name } | select -First 1 
  if( $destination -ne $null){       
   mi $_.PSPath $destination.PSPath -Verbose -WhatIf  
  } 
}

After some time where everything seemed to be running ok, I’ve noticed that some of the files weren’t being copied. After further analysis, I’ve noted that files contained the [ and ] chars weren’t being copied. Fortunately, we have StackOverflow and I’ve ended posting my question over there. One of the answers suggested to use the –LiteralPath parameter for the move-item cmdlet. According to the docs, the –LiteralPath parameter :

Specifies the path to the current location of the items. Unlike Path, the value of LiteralPath is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.

Did you notice the wildcards part? Yep, wildcards…unfortunately form me, I had completely forgotten that [] define wildcards which match a range of characters (note to self: do read the PowerShell docs). For instance, and this is just copied from the docs, here’s a quick example:

[a-l]ook matches book, cook or look, but not took.

Aha! ok, now it makes sense…that’s why those files which contained the [ ] on its name weren’t being copied. PowerShell was translating the values defined within [ ]  into ranges. Another note to self: don’t forget about wildcards when you’re writing PowerShell scripts.

And that’s it for now. Stay tuned for more.

 
Follow

Get every new post delivered to your Inbox.

Join 576 other followers