Monthly Archives: May 2012

GIT .ignore for Visual Studio Projects

Like many .NET devs, I have started using GIT for my source control. It is just so much better than Subversion, Mercurial and any of the other free products.

I have been honing my .gitignore file, to try and include every conceivable file that I should not be committing. So far, I have come up with this list:

Assemblies/*
*\build
*\release
*\Release
*\debug
*\Debug
*.suo
*.dep
*.aps
*.vbw
*.obj
*.ncb
*.plg
*.bsc
*.ilk
*.exp
*.sbr
*.opt
*.pdb
*.idb
*.pch
*.res
*.user
*\bin
*\Bin
*\obj
_ReSharper*
*.exe
*.csproj.user
*.resharper.user
*.cache
TestResult.xml
TestResults/*
Thumbs.db

I just drop this in the root directory of the project which GIT is monitoring, and Bob’s your aunty’s live-in lover!

To verify that your ignored file is doing its job, navigate to your repository and run the following command:

$ git ls-files . --ignored --exclude-standard --others

While I’m spouting git commands, run this one to list untracked files (i.e. not ignored and not even tracked):

$ git ls-files . --exclude-standard --others

Unable to Contact IP Driver – Error Code 5

Building a Sharepoint image, I ran into a problem during the insatllation of SQL server, at the stage where you specify the User under which you want to run the SQL Server services. The User which I wanted to use was an Active Directory User, in the same domain as the current server (the Sharepoint Server). However, the domain controller itself for that domain was on a different server VM. I created both server VMs by copying them each from a master VM with a bare-bones OS.

As part of the troubleshooting process, I pinged the DC from the would-be Sharepoint server, and the following error was displayed – Unable to Contact IP Driver – Error Code 5.

As it turns out, VMs don’t play very well when they start life out being created as copies of an existing, master VM. I’m not going to try and pretend that I understand the ins and outs of this, but I did find the solution. There’s a little executable called Sysprep (located c:\Windows\System32\sysprep\sysprep.exe ) which you run. James Kovacs’ post explains it better than I can, if you would like more information.

Copy As Path

When you do a lot of scripting (I am starting to do a bit), you need to work with a lot of file paths. There is a neat little shortcut baked right into the Windows shell which allows you to copy into the Clipboard, the path to a folder/file, as relevant.

When you right-click on a file/folder to bring up the context menu, hold down the shift key. You will see a menu item Copy as path:

This will copy the path of the file/folder to the clipboard and you can drop it into your script as required. Nice!

Find and Replace with Powershell

I recently had to perform a mundane task. Basically, I needed to trawl through about 50 sql text files and duplicate them, but replacing the string dev-server with sit-server. And then I had to do it all over again with prod-server.
I knew I could easily do this using the Linux find and sed commands together. But I’m starting to think Powershell these days and was curious to see what it had to offer for the task at hand.

Some quick Googling brought me to this post on the very topic. I opted for the script version of the command (as distinct from the shell version), which was:

$a = (gci | ? {$_.Attributes -ne "Directory"}); 
$a | % { cp $_ "$($_).bak";
(gc $_) -replace "dev-server","sit-server" | sc -path $_ }

In the first line, the script assigns to the variable $a all of the files in the directory (by excluding directories). gci is an alias to Get-Child-Item.
The 2nd line creates a backup of each sql file, before the operation is performed. Good, organised, cautious approach. Rollback is a buggar – when you can’t.
The third line performs the actual find and replace operation in each of the text files in the directory.

That tiny script bought me about 30 minutes. And a very boring 30 minutes it would have been!