Programming on the bus

Software, reading, and surfing on the big bus

Monday, February 27, 2012

Setting up NuGet for a new project

When setting up a solution to fetch from NuGet automatically:
1) Install-Package NuGetPowerTools
2) Enable-PackageRestore
4) Ignore packages folder from version control
3) Include .nuget folder in version control

More tips here:
http://blog.davidebbo.com/2011/08/easy-way-to-set-up-nuget-to-restore.html

Saturday, July 2, 2011

CA1024: Use properties where appropriate

For a long time I had no understanding of the code analysis rule CA1024: "Use properties where appropriate."

I have often violated this rules with methods named Get*, without parameters, that returns a list of items, like

public interface IBlogRepository
{
IEnumerable GetBlogPosts();
}


I have now realized that this is probably an error, since there should always be some kind of paging (see also Ayendes comments on this).

So the correct solution is something like

public interface IBlogRepository
{
IEnumerable GetBlogPosts(int pageSize, int pageNumber);
}

Simian

I started using Simian to find duplicated code - very nice!

I created a simple cmd file to output the analysis to a text file.

[PathToSimian]\simian-2.3.32.exe
-includes=**/*.cs
-excludes=**\obj\**\*.cs
-excludes=**\Reference.cs
-excludes=**\*.feature.cs
-excludes=**\*.Designer.cs > simian.txt

Saturday, October 23, 2010

Code contracts

Interesting article by Jon Skeet about code contracts.

Saturday, October 2, 2010

Export changes from Subversion with SharpSvn

private static void ExportRevisionRange(
Uri repositoryUrl,
long fromRevision,
long toRevision,
string exportFolder)
{
var client = new SvnClient();
var from =
new SvnUriTarget(repositoryUrl, fromRevision);
var to =
new SvnUriTarget(repositoryUrl, toRevision);
Collection<SvnDiffSummaryEventArgs> list;
client.GetDiffSummary(from, to, out list);

foreach (SvnDiffSummaryEventArgs item in list)
{
if (item.DiffKind == SvnDiffKind.Deleted ||
item.NodeKind != SvnNodeKind.File)
continue;
var target = new SvnUriTarget(item.ToUri);
string exportPath =
Path.Combine(
exportFolder,
item.Path.Replace("/", "\\"));
var fi = new FileInfo(exportPath);
if (!fi.Directory.Exists)
fi.Directory.Create();
client.Export(
target,
exportPath,
new SvnExportArgs { Revision = toRevision });
}}

Friday, September 17, 2010

Windows XP-programmer i Windows 7

Denne artikel er en dansk version af denne artikel: Running Windows XP-only apps on Windows 7

Hvordan man i Windows 7 kan køre programmer der ellers kun kan køre på Windows XP (trin som er specifikke for Windows 7 Home er beskrevet her).

Scott Hanselman beskriver her hvordan man kan køre Windows XP-programmer i Windows 7:
Windows 7 - Seamless Apps in Windows Virtual PC (Virtual XP) and Application Compatibility

Men Hanselman beskriver ikke hvad man skal gøre hvis man ikke har adgang til at downloade Windows XP Mode, som fx når man har Windows 7 Home.

Denne artikel beskriver hvordan man kan installere Windows Virtual PC, installere en ny virtuel maskine med Windows XP, installe et program der ellers kun kører på Windows XP, og køre dette program fra Windows 7:

1) Download og installér Windows Virtual PC:
Windows Virtual PC

2) Hvis du kører en maskine uden "hardware virtualization", Windows Virtual PC vil ikke køre, så installér dette fix fra Microsoft, enten:
a) på 32 bit systemer: 32 bit fix
b) på 64 bit systemer: 64 bit fix

3) Kør Windows Virtual PC og opret en ny virtuel maskine.

4) Installér og start Windows XP på den virtuelle maskine.

5) Installér "Integration Functions" via den indbyggede disk.

6) På den virtuelle maskine: installér Windows XP-programmet.

7) Luk den virtuelle maskine ved at klikke på krydset (X), hvilket vil sætte maskinen i dvale.

8) I Windows 7 Start menuen kan du finde navnet for programmet og klikke på det. Den virtuelle Windows XP maskine vil starte i baggrunden og starte dit program op som om det kørte i Windows 7.

For flere detaljer bag nogle af trinnene, se Hanselmans artikel:
Windows 7 - Seamless Apps in Windows Virtual PC (Virtual XP) and Application Compatibility

Running Windows XP-only apps on Windows 7

How to run Windows XP-only applications on Windows 7 (particular steps necessary for Windows 7 Home are described here):

Scott Hanselman describes how to run Windows XP apps nicely in Windows 7:
Windows 7 - Seamless Apps in Windows Virtual PC (Virtual XP) and Application Compatibility

However, Hanselman does not cover when you have no access to the Windows XP Mode download.

This article describes how to install Windows Virtual PC, install a new virtual machine with Windows XP, install your Windows XP-only application, and run it from Windows 7:

1) Download and install Windows Virtual PC:
Windows Virtual PC

2) If you are running a machine without hardware virtualization, Windows Virtual PC will not run, so install this fix from Microsoft, either:
a) on 32 bit systems: 32 bit fix
b) on 64 bit systems: 64 bit fix

3) Run Windows Virtual PC and create a new virtual machine.

4) Install and start Windows XP on the virtual machine.

5) Install Integration Functions via the built-in disk.

6) Install the Windows XP application that you want to run on Windows 7.

7) Close the virtual machine by clicking the X, which will make the machine hibernate.

8) In Windows 7 Start menu you can find the name of your application and click it. The Windows XP virtual machine will start in the background and bring your application up as if it was running on Windows 7.

For more details behind some of the steps, see Hanselman's article:
Windows 7 - Seamless Apps in Windows Virtual PC (Virtual XP) and Application Compatibility