Recover commit from git reset –hard

The problem

I did a

git reset --hard

on my repository and important code was the casualty.

Luckily git does not delete the commit instantly, and this is how to retrieve it:

1. Find the commit (SHA1), by running

git reflog
b7b5dce HEAD@{0}: checkout: moving from master to memcache
1283aa7 HEAD@{1}: pull --no-commit origin master: Fast-forward
b7b5dce HEAD@{2}: checkout: moving from memcache to master
b7b5dce HEAD@{3}: reset: moving to b7b5dcee57dd9029b0faf86fad1a0e1cc9c0a5ab
a45ae75 HEAD@{4}: commit: Test code for using Memcache

The fifth entry was the commit I lost, and it is the SHA1 “a45ae75″ we need.

2. Recover commit by merging

git merge a45ae75

You can read more here:

http://gitready.com/advanced/2009/01/17/restoring-lost-commits.html

Macbook Air sleep mode not working

My Macbook Air 13″ mid-2011 running Bootcamp with Windows 7, had an issues with sleep modes. Whenever I closed the lid or asked Windows to sleep, a reboot was necessary.

After a failed attempt at resetting the SMC, the solution was something else. A selected startup disk was required.

startup-disk-windows

This blogpost pointed me in the right direction:

http://osxdaily.com/2011/04/05/how-i-fixed-my-macbook-air-11-6-wake-from-sleep-problems/

I selected a startup disc in both MacOSX and the Bootcamp configuration and the Mac now supports sleep mode again.

 

 

Windows 8 shortcuts

Just a quick list of the shortcuts I find useful in Windows 8.

  • CTRL + ESC: Bring up start (Immediate typing will search for app/program)
  • Windows Key + Page up/down: Move app from one screen to another, when using multiple screens
  • Windows key + W: Search for setting
  • Windows key + I: open Settings for current app
  • Alt + Tab: Obviously still works
  • Windows key + C: Open start bar
  • Windows key + X: Action menu

Full list: Keyboard shortcuts for Windows 8

Windows 8 activation problem – 0x8007232B DNS name does not exist

Problem

When trying to activate Windows 8 or an earlier version you get the result:

Activation Error: Code 0x8007232b
DNS Name does not exist

If a volume-licensed media was used for the install, a product key needs to be set.

Solution

Open a command-prompt with administrator rights, and fire the following command:

slmgr -ipk xxxxx-xxxxx-xxxxx-xxxxx-xxxxx

Replace the x’es with your product key.

Now you should be able to activate, I was.

Read more here:

http://support.microsoft.com/kb/929826

[DK] Telenor internet/MMS settings on Nokia Lumia 800

I have a Noiai Lumia 800 Windows Phone mobile and my current Danish phone service provider is Telenor.

Internet worked fine, but MMS did not work. I was trying to find the internet/MMS settings on Telenor.dk, but I was only able to find an automatic SMS service, which did not work.

Finally I discovered that Nokia has recognised this problem and now provides an app called Network Setup.

This app lets you select your phone provider, and then everything is setup for you. MMS and internet now works without problems.

My attempts at installing Umbraco via NuGet

I often use Umbraco as a CMS for my web projects, and NuGet for referencing other libraries. This made me wonder whether Umbraco could be deployed via Nuget. The short answer is, it is possible, but it does not work very well. Here is my experience.

I started to read the NuGet docs to figure out what a NuGet package actually is.

NuGet package

A NuGet package is a file that makes it easy to add, remove, and update libraries and tools in Visual Studio projects that use the .NET Framework. A NuGet package is comprised by these three things:

  • tools – The tools folder of a package is for powershell scripts and programs accessible from the Package Manager Console. After the folder is copied to the target project, it is added to the `$env:Path (PATH) environment variable.
  • lib – Assemblies (.dll files) in the lib folder are added as assembly references when the package is installed.
  • content – Files in the content folder are copied to the root of your application when the package is installed.
The above is from the NuGet docs.

The documentation also indicate that NuGet was not designed for a project like Umbraco with so many files and such a complex web.config file. But I wanted to try and see how and if it was actually possible.

The strategy

The Umbraco project consists of libraries/assemblies and content, so it should be rather easy to create the NuGet package.

The first step was to download Umbraco 4.7.1 and go through the required assemblies and web.config. Initially I located assemblies that could already be found on NuGet and added these dependencies to the NuGet package. It later showed, that there would be versioning problems which I was not able to fix.

So instead of using dependencies to other NuGet packages as NuGet was actually intended, I  just added all the assemblies released with Umbraco 4.7.1.

Assemblies

The assemblies that gave me the most trouble was ClientDependency and ICharpCode.SharpZipLib.

ClientDependency was actually already in the NuGet feed, but the configuration transformation made from that NuGet package combined with the web.config transformation from the Umbraco package, yilded an invalid web.config file.  ClientDependency was therefor provided as an assembly directly from the Umbraco package and not as an external dependency.

The assembly ICSharpCode.SharpZipLib was also found in the NuGet feed, but Umbraco 4.7.1 required a specific version (0.85.5.452) that NuGet could not provide, and this assembly was as such also added as a part of the Umbraco package.

Web.config

The web.config configuration file for Umbraco is long and rather complex, and that makes merging of multiple web.config files difficult. The configuration transformation features in NuGet are limited, so you should expect problems when adding the Umbraco package to an existing website. The best results I achieved was when the package was added to an empty website or web application.

But even though a web.config file is almost empty, you should still prepare for some clean up.

Content

The Umbraco 4.7.1 binary release containes more than 1500 files. NuGet was not designed for this number of files and does not handle it very well. A complete package installation can take up to 5-10 min. depending on you machine and SSD/HDD configuration.

Example

The following describes the steps I used to run the Umbraco NuGet package against a web application project and the problems that arose.

1. Open Visual Studio 2010 and create an empty C# web application project

2. Open the NuGet Package Manager Console

3. Write:

Install-Package "Umbraco" -Source "c:\[NuGetPackageFolder]"

NuGetPackageFolder: Replace with the path to the folder containing the Umbraco.4.7.1.nupkg file. Important do not give the full path to the file, just the folder

4. Hit [ENTER] and wait for NuGet to do its work

5. Wait for the following two messages:

Successfully installed 'Umbraco 4.7.1'.
Successfully added 'Umbraco 4.7.1' to WebApplication1.

6. Compile and receive an error from web.config. (Multiple System.Web -> Compilation sections are present)

7. Remove the first and compile and run again

<compilation debug="true" targetFramework="4.0" />

8. At this point everything worked and I was able to follow the usual Umbraco installation steps :)

Conclusion

Umbraco is a fantastic CMS and NuGet is very cool, but together is not a good idea.

My goal was to find a way for installing Umbraco to a web project via NuGet, and that is not impossible, but I would not recommend it. I find it a lot easier to simply download the Umbraco released ZIP, and then extract and drag all files to my web application project. So that is what I will do :)

But if you still wants the Umbraco NuGet file, you can download it here.

Using OpenCover and NUnit with MSBuild

I am working on a project that has a large code base with a lot of logic. For this project I am trying to adopt a more TDD oriented development approach. This includes unit- and integration testing, as well as code coverage, and yes I do know that a high coverage percentage is not the same as good tests, but on the other hand, a low coverage indicates that more tests need to be written.

We are currently using NUnit.2.5.10.11092 and the code coverage tools I was able to find was NCover, PartCover and OpenCover. NCover is no longer free, and from what I can read it seems like OpenCover is the better choice compared to PartCover.

This blog post describes well some of the differences and features of PartCover vs. OpenCover.

MSBuild

This is the MSBuild configuration file that we are currently using to run unit test and code coverage.

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">

  <!-- Application Configurations -->
  <PropertyGroup>
    <NUnit-ToolPath>..\packages\NUnit.2.5.10.11092\tools\</NUnit-ToolPath>
    <OpenCover-ToolPath>..\packages\OpenCover.1.0.719\</OpenCover-ToolPath>
    <ReportGenerator-ToolPath>..\packages\ReportGenerator.1.2.1.0\</ReportGenerator-ToolPath>
    <MSBuildCommunityTasksPath>$(MSBuildProjectDirectory)\..\Libs\msbuild\</MSBuildCommunityTasksPath>

    <!-- Add paths to assemblies to test -->
    <TestAssembliesPath>..\Tests\Core.Tests\bin\Debug\Core.Tests.dll ..\Tests\Model.Tests\bin\Debug\Model.Tests.dll</TestAssembliesPath>

  </PropertyGroup>

  <ItemGroup>
    <AllProjects Include="..\Tests\**\*.csproj" />
  </ItemGroup>

  <Target Name="Clean">
    <MSBuild Projects="@(AllProjects)" Targets="Clean" />
  </Target>

  <Target Name="Compile">
    <MSBuild Projects="@(AllProjects)" Targets="Build" Properties="WarningLevel=1" />
  </Target>

  <Target Name="Test" DependsOnTargets="Clean;Compile">
    <!-- /domain=single is not support by the NUnit msbuild task, and it is required for OpenCover coverage test -->
    <Exec Command="$(NUnit-ToolPath)nunit-console-x86.exe $(TestAssembliesPath) /nologo /noshadow /domain=single /output=test-results.xml" />
  </Target>

  <Target Name="Coverage" DependsOnTargets="Clean;Compile">

    <!-- /domain=single is not support by the NUnit msbuild task, and it is required for OpenCover coverage test -->
    <Exec Command="$(OpenCover-ToolPath)OpenCover.Console.exe -register:user -target:"$(NUnit-ToolPath)nunit-console-x86.exe" -targetargs:"/noshadow $(TestAssembliesPath) /domain:single" -filter:"+[Model]* +[Core]* +[Datalayer]*" -output:coverage.xml" />
    <Delete Files=".\coveragereport" />
    <Exec Command="$(ReportGenerator-ToolPath)ReportGenerator.exe coverage.xml "coveragereport" html" />
    <Exec Command="$(ReportGenerator-ToolPath)ReportGenerator.exe coverage.xml "coveragereport" xmlsummary" />
    <Delete Files="coverage.xml" />
  </Target>

  <Target Name="Build" DependsOnTargets="Clean;Compile;Test;" />

</Project>

Running the different targets from command prompt is easy, just type “msbuild [MSBUILD CONFIG FILE].xml /t:[TARGET]”

[MSBUILD CONFIG FILE] should be the name of the file above, [TARGET] can be any of the following Clean, Compile, Test and Coverage.

The Coverage target generates a fine HTML report as well as a XML summary.

Please note that I have not used the NUnit task from MSBuild community as the /domain=single is important, and as it is currently not supported by that task.

Visual Studio 2010 Package load errors

My Windows 7 installation on my laptop broke down, and I then had to completely reinstall Windows 7, Visual Studio etc.

Besides it being a long and tedious process it seemed to go fine. But I started to get the following error messages when Visual Studio 2010 was launched:

The ‘RadLangSvc.Package, RadLangSvc.VS, Version = 10.0.0.0, Culture = neutral, PublicKeyToken = 89845dcd8080cc91′ failed to load

VSTS for Database Professionals Sql Server Data-tier Application did not load

and some other VSTS packages that was unable to load.

I followed the steps described here, and it worked :). The steps are also described below:

  1. Close all running instances of Visual Studio 2010
  2. Install the following MSI packages from the installation CD of VS2010, in the folder  \WCU\DAC
  3. DACProjectSystemSetup_enu.msi
  4. TSqlLanguageService_enu.msi
  5. DACFramework_enu.msi

My thoughts, stuff I need to remember or things I just want to share with the world