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.

Posted in Development, Software | Tagged , , , , , , | Leave a comment

MacBook Pro BootCamp/Windows keyboard schema

Visual Studio 2010 + Resharper

Key Description
FN+ALT+[Right arrow] Go to sub types
FN+ALT+[Left arrow] Go to super types
ALT+SHIFT+F12 Find usages of variable
CTRL+SHIFT+F11 Go to type of variable
CTRL+SHIFT+R Refactor this
CTRL+SHIFT+T Go to file
CTRL+T Go to type
FN+ALT+[ENTER] Generate
Posted in Development, Mac, Software | Tagged , , , , , | 1 Comment

NHibernate query optimising with HQL expression IN

A note for me to remember.

I have been doing some optimisation of queries done by NHibernate HQL. To optimise I have rewritten some of them to use the HQL IN expression.

Point: important to check the collection parameter, if NULL or Empty, NHibernate criteria will fail.

Posted in Development, Personal | Tagged | Leave a comment

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 -->
    <TestAssemblies>..\Tests\Core.Tests\bin\Debug\Core.Tests.dll ..\Tests\Model.Tests\bin\Debug\Model.Tests.dll</TestAssemblies>

  </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.

Posted in Development | Tagged , , , , | Leave a comment

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
Posted in Development, Software | Tagged , , | 1 Comment

Cuda v3.2 template project using C++

Important

The tutorial is missing some compilation, linker, library settings steps. However you can download the template project, it works and has everything setup.

Introduction

I am a developer who has been developing software using .NET and C# for several years. I have never used C or C++, and it has never been required.

I like to investigate new technologies, mainly because I am curious, but also because it could make my daily development work easier or smarter.

Recently my focus has been directed towards GPGPU on the Nvidia Cuda platform.

The programming language for Cuda is called “Cuda C”. The name implies that knowledge of C indeed is required for using GPGPU on the Cuda platform.

I discovered that there exist .NET bindings to the Cuda platform and drivers. However, I find their usage complicated and insufficient, and further more kernel development will still have to done in Cuda C.

These fact made me realise that I would have to learn a bit of C and C++ to use Cuda as it was actually intended by Nvidia. Nvidia provides many samples and suggest that a Cuda development environment on Windows could use Visual Studio and Nvidia Parallel NSight for debugging, profiling etc.

As my knowledge of C and C++ development was severely limited, so was the setting up and configuration of Visual Studio 2008 for Cuda C development.

I have read “Cuda by example…” (http://developer.nvidia.com/object/cuda-by-example.html), “Programming Massively Parallel Processors…” (http://www.nvidia.com/object/io_1264656303008.html) and “C Programming Language, 2. edition” (http://www.pearsonhighered.com/educator/product/C-Programming-Language/9780131103627.page). These books have given me the foundation to start developing using Cuda C and GPGPU.

Setting up Visual Studio 2008 and making the compiler work required some work, but here is what I did.

1. Download and install driver and toolkit

Download Cuda toolkit and the developer driver and install. A restart is probably required. (http://developer.nvidia.com/object/gpucomputing.html)

2. Start Visual Studio 2008, and create a new project of type Win32 Console Application

Give the project and solution a name (here called Cuda_Template).

3. Click Next

4. Select Console application and check the empty project, then click Finish

5. Add new item called main.cpp of type C++ File

6. Add the following code the file

#include <stdio.h> 

int main() {

    printf("Hello world...\n);
    return 0;

}

7. Build and try to run the exe file. The output should be

8. Select Project -> Custom Build Rules…

9. Select Cuda Runtime API build rule (v3.2)

10. Add a new file called kernel.cu

11. Add the following to the file kernel.cu

/* power: raise base to n-th power; n >= 0 */
__device__ int devicePower(int base, int n) {

    int p = 1;

    for (int i = 1; i <= n; ++i) {
        p = p * base;
    }

    return p;
}

__global__ void power( int *base, int *n, int *output, int threadMax ) {

    int tid = threadIdx.x + blockIdx.x * blockDim.x;

    if (tid < threadMax) {
        output[tid] = devicePower(base[tid], n[tid]);
    }

}

12. Right click the newly created file and select properties

13. Set the “Exclude From Build” and make sure that the project still builds

14. Create a new file called call_kernel.cu

15. Add the following to the file call_kernel.cu

#include <cuda_runtime_api.h>
#include "main.h"

// includes, kernels
#include <kernel.cu>

void call_kernel_power(int *base, int *n, int *output, int elementCount) {

    int *dev_base, *dev_n, *dev_output;
    int gridX = (elementCount+ThreadsPerBlock-1)/ThreadsPerBlock;

    cudaMalloc( (void**)&dev_base, elementCount * sizeof(int) );
    cudaMalloc( (void**)&dev_n, elementCount * sizeof(int) );
    cudaMalloc( (void**)&dev_output, elementCount * sizeof(int) );

    cudaMemcpy( dev_base, base, elementCount * sizeof(int), cudaMemcpyHostToDevice);
    cudaMemcpy( dev_n, n, elementCount * sizeof(int), cudaMemcpyHostToDevice);

    power<<<gridX,ThreadsPerBlock>>>(dev_base, dev_n, dev_output, elementCount);

    cudaMemcpy( output, dev_output, elementCount * sizeof(int), cudaMemcpyDeviceToHost);

    cudaFree( dev_base );
    cudaFree( dev_n );
    cudaFree( dev_output );
}

16. Create a new header file called main.h

17. Add the following content to the file

#define ThreadsPerBlock 128

#include <stdio.h>

void call_kernel_power(int *base, int *n, int *output, int elementCount);

18. Update the main.cpp file with the following:

#include "main.h"

#define N   80000

int main() {

    printf("Power Cuda kernel test from C++\n");
    printf("Testing %d elements\n", N);

    int base[N], n[N], output[N];

    for(int i = 0; i < N; i++) {
          base[i] = 2;
          n[i] = i+1;
          output[i] = 0;
      }

    call_kernel_power(base, n, output, N);

    for(int i = 0; i < N && i < 15; i++) {

          printf("%d^%d = %d\n", base[i], n[i], output[i]);

      }

      printf("Done\n");

    return 0;
}

19. That should be it…

You now have a template that you can work from. When you build the file and run it, I get this output:

Posted in Development, Software | Tagged , , , , , | Leave a comment

Mercurial graph

This is a screenshot of the Mercurial graph, of a project that I am currently is working on.

It kind of looks like a string instrument you want to play :)

Posted in Development, Fun, Software | Tagged , , | Leave a comment

NHibernate dirty problem, weird updates in NHprof

Upgrading to NH3 from NH2.1.2

We have recently update to NHibernate 3 in one of our projects. While testing I was suddenly seeing some weird UPDATE statements in NHprof.

It seemed like the NHibernate IsDirty detection had changed.

After some digging it turned out that our mapping files (made in FluentNhibernate) actually contained some minor errors when compared to the DB schema. Minor errors like value typed properties not being nullable when the ClassMap said it should be.

Debugging of NHibernate projects

I found that inserting the following into the classmaps made debugging a lot easier:

DynamicUpdate();

Now only the properties that are Dirty (according to NHibernate) are used in the SQL UPDATE statement. Here are the description from NHibernate docs:

  • dynamic-update (optional, defaults to false): Specifies that UPDATE SQL should be generated at runtime and contain only those columns whose values have changed.
  • dynamic-insert: (optional, defaults to false): Specifies that INSERT SQL should be generated at runtime and contain only the columns whose values are not null.

That led me directly to the property in the mapping files that had errors in it, and I could easily fix it.

Conclusion

So, in our case, it wasn’t really the NHibernate dirty detection that changed, NHibernate 3 is just not as fault tolerant, than that of NH2. So the upgrade made us discover some errors that should be corrected.

As such, this is a good thing, but it would have been nicer if NH2 had made us aware of these errors in the first place.

But hey, better late than never ;)

Posted in Development | Tagged , , , , | 2 Comments

Mercurial repository locked on network share and is never released

I have experienced this when the connection is dropped in the middle of a HG command being executed.

The solution is to run the following command on the machine hosting the repository. Fire the command in the directory hosting the problematic/locked .hg folder. (It is not really a requirement to execute the command on the hosting machine, but it will make it a lot quicker than over the network)

hg recover

That is it.

Posted in Development, Software | Tagged , | Leave a comment

NHibernate CompositeId and GetHashCode SELECT N+1 problem

I was looking in my NHProf log and got a lot of SELECT request. To many and I thought I was having a SELECT N+1 problem.

Using the “Stack Trace” in NHprof I identified a call being made to GetHashCode() of the class (MyClass) holding the composite id. MyClass looked like this:

public class MyClass
{
    public virtual Key1Class Key1 { get; set; }
    public virtual Key2Class Key2 { get; set; }

    /*
     * Other virtual properties
     * ...
     */

    public override int GetHashCode()
    {
        unchecked
        {
            return ((Key1 != null ? Key1.GetHashCode() : 0) * 397) ^ (Key2 != null ? Key2.GetHashCode() : 0);
        }
    }
}

Note that Key1 and Key2 are both references, and please take a closer look at the GetHashCode method.

The problem

The problem I was facing… NHibernate called the GetHashCode() of MyClass when doing the query. And the call to MyClass‘s GetHashCode method subsequentily called GetHashCode() of both the Key1 and Key2 classes.

Key1 and Key2 were loaded as proxies and hence a call to something else than theirs Id resulted in a select being fired.

The solution

The solution was to rewrite the GetHashCode method to this:

public override int GetHashCode()
{
    unchecked
    {
        return ((Key1 != null ? Key1.Id : 0) * 397) ^ (Key2 != null ? Key2.Id : 0);
    }
}

Note that both Id’s of KeyClass1 and KeyClass2 are integers.

Now a call to MyClass GetHashCode does not result in individual SELECT statements being fired, even though the Keys area lazy loaded.

Posted in Development | Tagged , , , , , | Leave a comment