Wednesday, 5 May 2010

Update AssemblyInfo as part of the build process

I use TeamCity to build by code as part of continuous integration. One of the tasks I tend to do is to update the AssemblyInfo file with the current build number.

First you need to ensure you have installed the open source project MSBuild Community Tasks, downloadable from here.

Then the code to do this is:
<Target Name="PreBuildTasks">
<PropertyGroup>
<Version>$(BUILD_NUMBER)</Version>
</PropertyGroup>
<MSBuild.Community.Tasks.AssemblyInfo
CodeLanguage="CS"
AssemblyCompany="CompanyName"
AssemblyCopyright="Copyright (c) CompanyName2009"
AssemblyDescription="Description"
AssemblyFileVersion="$(Version)"
AssemblyVersion="$(Version)"
AssemblyTitle="Titlek"
Guid="1938930d-a5f3-4045-a5f3-f5b930d70ade"
AssemblyProduct="Product name"
OutputFile="$(MSBuildProjectDirectory)\ProjectName\Properties\AssemblyInfo.cs" />
</Target>

Please note this has only be tested to work on TeamCity.

Create build file from solution file

You can create a build file from your solution for use with MSBuild. Useful if you are using any automated build tools like TeamCity.

To do this, open up the "Visual Studio 2008 Command Prompt"
Navigate to the folder containing your solution file
Enter the following:

Set MSBuildEmitSolution = 1
msbuild solutionname.sln


Once complete you should see a file in the folder called solutionname.sln.proj which is now your build file. You can edit this build file as required. I tend to add pre build code to update AssemblyInfo.cs and post build code to fire off unit tests and to package up the final output.

Thursday, 25 February 2010

Changing default editor for batch scripts.

Right clicking on a .bat or .cmd file and select edit will open the file in the default program, Notepad. I prefer to use a different editor. To change the default for these files requires a registry change:
  1. Open the registry editor (regedit.exe)
  2. Browse to HKEY_CLASSES_ROOT\batfile\shell\edit\command
  3. Edit the default value and change to the executable you want to use to edit the batch files,
    e.g. "C:\Program Files\Programmer's Notepad\pn.exe" "%1"
  4. Click OK
  5. Browse to HKEY_CLASSES_ROOT\cmdfile\shell\edit\command
  6. Edit the default value and change to the executable you want to use to edit the command files.
  7. Click OK
No restart required.

Wednesday, 24 February 2010

IIS 7.0 not serving CSS files

After a rebuild of IIS 7, I couldn't get any CSS files to return. If I browsed to the path http://localhost/styles.css, I would a blank page (even when I view source). The problem was that during the reinstall of IIS I forgot to add the Static Content Component.

For Vista and Windows 7:
Control Panel -> Programs -> Turn Windows features on or off

Then navigate to: Internet Information Services -> World Wide Web Services -> Common HTTP Features
Enable the Static Content option

Friday, 19 February 2010

Cannot load macro project error

After moving 'My Documents' folder to a different drive, I started getting an error when loading the macro's explorer window. The error was:

Cannot load macro project '' for the following reason:

'C:\Users\\Documents\Visual Studio 2008\Projects\VSMacros80\Samples\Samples.vsmacros' is an invalid or inaccessible macro project file

The problem is when you move your documents folder, this updates the environment variable %USERPROFILE%, but the macro's path for Visual Studio are stored in the registry.

Searching the registry I found the following two keys which had a 'path' value, referencing the C:\.

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\vsmacros\OtherProjects7\0
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\vsmacros\RecordingProject7


To solve, change the 'path' values in the above keys to your new location and restart Visual Studio.

Attach to multiple w3wp processes

This is an update to a previous post as I am now working on a project that can have up to 3 w3wp processes running.

I've changed the following lines:

Dim proc2 As EnvDTE80.Process2 = dbg2.GetProcesses(trans, compName).Item("w3wp.exe")
proc2.Attach2(dbgeng)


with:
For Each proc2 As EnvDTE80.Process2 In dbg2.GetProcesses(trans, compName)
If proc2.Name.Contains("w3wp.exe") Then
proc2.Attach2(dbgeng)
End If
Next

Wednesday, 3 February 2010

Visual Studio and Spark

There is a great post about setting up file icons, Templates and syntax highlighting in Visual Studio for spark templates here:

3 Useful Visual Studio Tricks for Spark Templates

Thursday, 28 January 2010

IIS7 and basic authentication

I needed to use basic HTTP authentication to secure a site instance as it required pulic access for a demo.

However, in IIS7, the only authentication modes listed are the default Forms, Anonymous and ASP.NET Impersonation.

To solve this, I had to install the basic authentication module for IIS.

For Server 2008:
  • Server Manager -> Roles -> Web Server -> Add Role Services

For Vista and Windows 7:
  • Control Panel -> Programs -> Turn Windows features on or off

Then navigate to: Internet Information Services -> World Wide Web Services -> Security
Enable the Basic Authentication option

Thursday, 7 January 2010

Debug prompt in VS 2008

When trying to debug an application using VS2008 on Windows 7 64 bit, I keep getting the following prompt, which is quite annoying.

debug prompt
To disable the prompt, you need to edit the following registry key. Ensure that Visual Studio is not running whilst you change the registry.

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\Debugger
Set DisableAttachSecurityWarning attribute value to 1.

Monday, 4 January 2010

Open command window here...

Windows XP came with a nice little powertoy “Open Command Prompt Here”, which enabled you to use the navigate around the file system and then were able to open a command prompt at the current location.

In Windows 7, you can now simply hold the Shift key down while right clicking on a folder and you'll see the option to "Open command window here".