nu – Gems for .NET

Package management has been on my mind for months as one of the greatest short comings in .NET. If you spend two hours using Ruby and gems, you realize how much easier it is than finding the appropriate .NET assemblies to use. It also promotes using open source libraries, instead of re-inventing the wheel.

nu aims to provide this for .NET.

I checked it out tonight. Here is my experience.

First step is to install it, and ruby is the only pre-req. The following commands show how to install and use it.

> gem install nu
> mkdir test
> cd test
> nu install nunit
> nu install nhibernate

Wow, that was easy. nu downloaded nhibernate and nunit, and placed them in the lib folder (including all of NHibernate’s dependencies). By the way, it literally took less than 30s for me to do this.

So what do I think?

  • It is an easy and fast delivery tool.
  • Using Ruby isn’t that big of a deal, but I think that is my opinion, not the community opinion.
  • It is new, so it has a ways to go in terms of functionality in discovery. I can’t hate because at least they have released something and I have just dreamed about releasing something.
  • Build integration (and probably Visual Studio) is going to be key. And by build, I don’t just mean NAnt and UppercuT, but MSbuild too.
  • The biggest hurdle is building a “gem” community in .NET. For some reason, creating a .NET gem seems kind of awkward (even though it isn’t that hard).

Data driving Ruby tests with meta-programming

Data driving ruby tests with meta-programming is one of the more elegant examples of meta-programming in my opinion. Understanding that class definitions are active, and you can add methods in a loop is very powerful.

class LocationTest < ActiveSupport::TestCase
 
  def setup
    @location = Location.new
  end
 
  {:empty => '', :nil => nil}.each do |key, value|
    test "address can't be " + key  do
      @location.address = value
 
      assert !@location.valid?
    end
  end
end

NUnit has the ability to do the same thing, but attributes and reflection just aren’t as elegant.

A MSBuild convention proposal – Targets per assembly

MSBuild is a very powerful build tool. Unfortunately, in my experience, I have seen it utilized very little. Instead, developers rely entirely on Visual Studio for the build, which is a mistake. I think there are a couple reasons for this:

  • Modifying the build feels like you are mucking in the internals of Visual Studio
  • There is no convention based approaches for how to handle custom bulid targets

Now, you could go the way of NAnt, and have complete independence from Visual Studio. I think this is a mistake as well. Visual Studio, while being a royal pain much of the time, is still a very very very powerful tool. I believe we should embrace it, while using MSBuild plus conventions to achieve ultimate flexibility.

The proposal

It’s actually quite simple. Each assembly/project already has its own *.csproj file, which is in essence a partial MSBuild file. The problem is editing it is weird and scary at times, because it is auto-generated by Visual Studio.

Just add the following to any or all your csproj files.

<Project>
  ... All the visual studio muck ...
  <Import Project="$(MSBuildProjectName).targets" Condition="Exists('$(MSBuildProjectName).targets')" />
</Project>

Then add a file with that name. If your projects name is Reference.Web, then add a file named Reference.Web.targets and include it in the project. The content could contain something like the following.

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 
  <ItemGroup>
    <Files Include="$(SolutionDir)\configuration\$(Configuration)\$(AssemblyName).*.config" />
    <Files Include="$(SolutionDir)\configuration\$(Configuration)\Common.*"/>
  </ItemGroup>
 
  <Target Name="InstallConfiguration">    
    <Copy SourceFiles="@(Files)" DestinationFolder="$(OutputPath)" />
  </Target>
 
  <!-- Override the AfterBuild target -->
  <Target Name="AfterBuild" DependsOnTargets="InstallConfiguration" />
 
</Project>

Now you have a build file separate from the project that is really easy setup and use, straight for Visual Studio.

The only gotcha is Visual Studio won’t automatically notice the build file changes, so you still have to relad the assembly after you make a build file change.

UPDATE – More robust Import statement

Via @sayedihashimi

Even better would be a conditional import, and you should use the MSBuildProjectName property instead of AssemblyName.

Zero to Synergy+ in 5 minutes

Synergy+ is most easily described as a software KVM. In reality, it is much more than that. It is more like having multiple monitors, except each monitor is actually attached to its own computer. Synergy+ is a fork of the original project, which hasn’t been updated since 2006.

Enough with the chit-chat, lets get it up and running on Windows in no time.

Install

Install – Done.

Configure – Server side

This is the confusing part. I will take you through the GUI, which doesn’t exist for the Mac or Linux as far as I could tell.

Start Synergy and select the Share this computer’s keyboard and mouse (server) option. Then click Configure.

From there, the next step is adding the screens, which represent the different computers you want connected. Click the + to get going.

First, enter your local computer information. Seems weird that it didn’t add it by default, but it doesn’t. Basically, all you need to enter is your computers name (which can be found/changed on the Synergy Info button on the main configuration screen).

Next, enter in the client computer’s names that you will be connecting.

From there you need to create links. Links tell Synergy how one screen should be linked to another (seems obvious huh). In our example we have two screens, so we need two links. One link will connect Screen 1 to Screen 2, while the other does the reverse.

Configuring the link is a mind trip, so much so that I can’t even describe how to do it. I suggest ignoring the size percentages, and create a sentence like left of Screen 1 of Screen 2. Then click +. After this, it becomes more obvious what you did (just trust me please).

Then the reverse.

Now just Start the server and your server config is basically done.

Configure – Client

The client really doesn’t require any configuration. Just select the Use another computer’s keyboard and mouse (client) option, then enter the server name and click Start

And now for my super sweet home-made video.

Next Steps

Read through the Synergy wiki, which will help you on more complicated setups on Mac and Linux.

I also noticed a couple things that didn’t work too well.

  • Mouse is sometimes laggy – I think this may be because my server is actually my oldest computer. The lagginess isn’t bad enough for me to not use it however.
  • Print Screen didn’t work too well, which made the capturing of the above screen shots a little cumbersome
  • If your computer locks automatically after a certain time and it isn’t the server, synergy can’t be used to unlock it.