Friday, 20 February 2009

My Tortoise SVN Global Ignore Pattern

*bin* *obj* *_ReSharper* *.resharper *Debug* *.pdb *.suo *.refresh *Bin* *.user

Simple Publish Target for TeamCity Deployment Build

I set up this simple Deployment build on Team City by creating a build configuration that is dependant on my Continious build being successful. This will call a simple msbuild file. This build file will tag the repository and do a AspNetCompiler publish. You can use the Team City variable "$(BuildNumber)" to store the release, in this case in the "_Releases" folder.

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Publish"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import
Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<PropertyGroup>
<NEW_LINE>%0D%0A</NEW_LINE>
<TAB>%09</TAB>
<DOUBLE_QUOTES>%22</DOUBLE_QUOTES>
<SPACE>%20</SPACE>
</PropertyGroup>

<PropertyGroup>
<SolutionPath>C:\Builds\company\$(Project)\trunk</SolutionPath>
<SolutionFile>$(SolutionPath)\$(SlnFile)</SolutionFile>
<OutputFolder>C:\_Releases\company$(Project)</OutputFolder>
<WebsitePath>$(SolutionPath)\website</WebsitePath>
</PropertyGroup>

<PropertyGroup>
<SubversionPath>C:\Program Files\CollabNet Subversion
Server</SubversionPath>

<SubversionCmd>$(SubversionPath)\svn.exe</SubversionCmd>
<SvnUsername>username</SvnUsername>
<SvnPassword>password</SvnPassword>
<SvnLocalPath>$(SolutionPath)</SvnLocalPath>
<SvnServerPath>https://svn.company.com/$(Project)</SvnServerPath>
<SvnTrunkFolder>$(SvnServerPath)/trunk</SvnTrunkFolder>
<SvnTagsFolder>$(SvnServerPath)/tags</SvnTagsFolder>
</PropertyGroup>

<Target
Name="TagRepository">r />
<!-- Commit all build changes -->

<SvnCopy
SourcePath="$(SvnTrunkFolder)"
DestinationPath="$(SvnTagsFolder)/$(Project)_v$(BuildNumber)" Message="Automatic
tag by the buildserver for the successful IterationBuild $(IterationNumber)." />
<Message Text="Tag created at $(SvnTagsFolder)/$(Project)_v$(BuildNumber)"
Importance="high"/>
</Target>

<Target Name="Publish"
DependsOnTargets="TagRepository">
<AspNetCompiler VirtualPath="/Website"
PhysicalPath="$(WebsitePath)"
TargetPath="$(OutputFolder)\$(Project)_v$(BuildNumber)" Force="true"
Updateable="true" />
</Target>

</Project>

Sending an Email when a subversion commit occurs

I assembled a little zip file with some tools I use on my svn_repository:

Download Here

The package consists of sendmail.bat which you can call from your post-commit-hook.bat file like this:

c:\svn_repository\sendmail.bat %1 %2

It sends an email with all the details of the latest commit to specified recipients.

sendmail.bat

SET REPOS=%1
SET REV=%2
SET LPath=C:\svn_repository

ECHO Repo: %REPOS% >> %LPath%\log.txt
ECHO Rev: %REV% >> %LPath%\log.txt

SET LOG_FILE=%LPath%\svnfileR-%REV%.txt
SET LOG_FILE1=%LPath%\svnfileR1-%REV%.txt
SET LOG_FILE2=%LPath%\svnfileR2-%REV%.txt
SET AUT_FILE=%LPath%\svnfileA-%REV%.txt

"C:\Program Files\CollabNet Subversion Server\"svnlook info -r %REV% %REPOS%>%LOG_FILE1%
"C:\Program Files\CollabNet Subversion Server\"svnlook changed -r %REV% %REPOS%>%LOG_FILE2%
copy %LOG_FILE1%+%LPath%\spacer.txt+%LOG_FILE2%+%LPath%\spacer.txt+%LOG_FILE%

"C:\Program Files\CollabNet Subversion Server\"svnlook author -r %REV% %REPOS%>%AUT_FILE%

REM SET THE AUTHOR FROM THE FILE.
FOR /F %%A IN (%AUT_FILE%) DO SET AUTHOR=%%A

SET EMAILFILE=%LPath%\emails.txt
FOR /F %%A IN (%EMAILFILE%) DO SET EMAILS=%%A

ECHO Executing: %LPath%\blat svnfileR1-%REV%.txt -to %EMAILS% -s "Repository Commit by %AUTHOR% New Revision: %REV%" >> %LPath%\log.txt
%LPath%\blat svnfileR1-%REV%.txt -to %EMAILS% -s "Repository Commit by %AUTHOR% on %REPOS% @ %REV%" >> %LPath%\log.txt -server L060 -f BuildMaster@someplace.com

del %LOG_FILE%
del %LOG_FILE1%
del %LOG_FILE2%
del %AUT_FILE%


--------------------------------------

Sendmail.bat uses a text file called "emails.txt" in which you can store the comma separated recipients. Im using Blat as the email tool.

Tuesday, 3 February 2009

Quick 5 minute intro to Ado.Net Dataservices

Ado.Net Dataservices is included in the .Net 3.5 Asp Extensions. It provides a complete data driven web service to your consumers and includes security and access rules!

public class NorthwindDataService :
            WebDataService<NorthwindDataContext> {
           
    public static void InitializeService(IWebDataServiceConfiguration config)
    {
        config.SetResourceContainerAccessRule
            ("*", ResourceContainerRights.AllRead);
    } 
}

You can then query your database through calling the Dataservice with REST type URL's:
http://localhost:1453/WebSite5/NorthwindDataService.svc/Products(1)

For the full article provided by David Hayden, click here.

Sunday, 1 February 2009

Lost your Windows 2003/XP/Vista/7 Administrator password? Not too worry ;)

I was recently in a situation where the Administrator password has been lost on a Windows 2003 server machine. After quite an extensive search I found a great little program called “Trinity Rescue Kit” (website).

You can use a program like BartPe to create a bootable USB stick containing the ISO contents, or simply burn the ISO file to a CD or DVD using IsoBurner.

Once you have booted up the computer, you can list all the users of the Windows system, reset password, upgrade users to administrator or even disable users.

Great application if you are in a pickle!

Friday, 14 March 2008

Setting up a Continuous Integration Server with Subversion and TeamCity Part 2

Ok now that you have Subversion up and running, you can grab JetBrains Team City.

Download Team City Free Edition

Install the "Build Agent" and "Core" modules. When you are choosing ports, please make sure these ports are free and not used already by Subversion (Subversion is "8888" if you followed my advice in Part 1).

Take note of the ports where TeamCity Server will be running.
When the installation is finished go to the url: http://SERVERIPORNAME:PORT/

Create an administration account and lets set up a continuous build for "ProjectX"!
Click on "Administration" and "Add Project". Call it "Test Project"

Click on "Add Build Configuration" and call it "ProjectX". Make sure "Clean All Files Before Build" is checked and leave the rest as is and click on "VCS settings".

Click on "Create and Attach VSC root". Call it "ProjectX SVN" and choose type "Subversion".
The url would be in the format "http://SERVERIPORNAME:8888/svn/ProjectX/trunk"

Now in username you should add an account for the buildserver on your domain and add that to the authorization file in the repository root. I will use "Buildmaster" with password "password" and click Save.

Back at the previous screen select a checkout directory, Im using "c:\Builds\ProjectX". Leave everything else as is and click on "BuildRunner".

Now if you have an NANT, ANT or MSBUILD build file and know how to set it up, this is were we go our seperate ways! If you do not have an NANT, ANT or MSBUILD file, then lets create a very simple one!

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

<PropertyGroup>
<NUnitPath>C:\Program Files\NUnit-Net-2.0 2.2.9\bin</NUnitPath>
<NUnitCmd>$(NUnitPath)nunit-console.exe</NUnitCmd>
<NUnitFile>TestResult.xml</NUnitFile>
</PropertyGroup>


<Target Name="Build">

<!-- Clean, then rebuild entire solution -->
<MSBuild Projects="$(Solution)"
Targets="Clean;Rebuild"
Properties="Configuration=$(Configuration);Platform=$(Platform);RunCodeAnalysis=$(RunCodeAnalysis)">

<Output TaskParameter="TargetOutputs" ItemName="CodeAssemblies"/>

</MSBuild>

<!-- Add the compiled code assemblies to master list of all compiled assemblies for the build -->
<CreateItem Include="@(CodeAssemblies)">
<Output TaskParameter="Include" ItemName="CompiledAssemblies"/>
</CreateItem>


<NUnit Assemblies="@(CodeAssemblies)"
ToolPath="$(NUnitPath)"
WorkingDirectory="%(CodeAssemblies.RootDir)%(CodeAssemblies.Directory)"
OutputXmlFile="@(CodeAssemblies->'%(FullPath).$(NUnitFile)')"
ContinueOnError="true">
<Output TaskParameter="ExitCode" ItemName="NUnitExitCodes"/>
</NUnit>

</Target>
</Project>


Notice that the build file will use NUnit and run all unit tests that it found in the assemblies. Therefore please install NUnit and remember to change the location of NUnit-console.exe in the properties of the build file.

Save this file as "teamcity.common.build" and place it in the "C:\Builds\" folder (Note that it should be the root of where you will checkout projects).

Back at the BuildRunner screen in TeamCity select MSBUILD enter "..\teamcity.common.build" into the "Build file path" (Note that it is a relative path to the current project)

Set your MSBuild Version (the .Net version you have installed on the machine).

In "Targets" type "Build" and in "Command Line Parameters" type in the following:

/v:normal /p:Solution=C:\Builds\ProjectX\projectx.sln;Configuration=Debug;Platform="Any CPU";RunCodeAnalysis=false

offcourse replacing projectx.sln with the correct path to your solution file.

Make sure Validate Build file is unchecked, and click Save.

On the Build Triggering you can now set up when this build should run. By enabling "Enable triggering when files are checked into VCS" the build will run everytime it picks up new changes committed to subversion.

Thats it! As you can see this is a very basic configuration and only uses a fraction of Team City's power.

Last but not least, click on "My Settings And Tools" and install the Windows tray notifier. This will enable you to configure your watched builds and be notified if a build fails etc.

There you go! A brilliant platform independant solution and its Free!

Setting up a Continuous Integration Server with Subversion and TeamCity Part 1

In this part we will set up Subversion on the server, create a repository and use SSPI(Integrated Windows Authentication) for access control to repository.

Step 1: Install Open Collabnet Subversion

Download Open Collabnet (you may need to register for free)
Choose SVNSERVE and APACHE, use the default settings but use port 8888 for Apache if you are running IIS aswell.

Step 2: Install TortoiseSVN

Download Tortoise
Restart the computer...

Step 3: Create a repository

Go to the repository location you chose when setting up Subversion (should be something like C:\svn_repository).
First create a folder for the new repository. Lets assume we call it "ProjectX" for now. Right click on "ProjectX" and you will see some new Tortoise options in the context menu. Go to the TortoiseSVN item and expand to show "Create Repository Here" and click that.

You should now see some new items in that folder which means the folder is now a valid Repository. That was easy wasn it! Now we just need to set up Apache and SSPI and we are set.

Step 4: Set up Apache and SSPI

First you need to download the SSPI Module here. Copy the file mod_auth_sspi.so into the Apache modules folder (should be something like C:\Program Files\CollabNet Subversion Server\httpd\modules).

Edit the http.conf file (should be at C:\Program Files\CollabNet Subversion Server\httpd\conf) and add the line

LoadModule sspi_auth_module modules/mod_auth_sspi.so

to the LoadModule's section. Make sure you insert this line before the line

LoadModule auth_module modules/mod_auth.so

Change the line

AuthType Basic

TO

AuthType SSPI

also replace everything inside "Location /svn" block with this:

DAV svn
SVNParentPath "[REPOPATH]"

# authentication
AuthName "Subversion Authentication"
AuthType SSPI
SSPIAuth On
SSPIAuthoritative On
SSPIDomain [DOMAINNAME]
SSPIOfferBasic On
Require valid-user

# authorization
AuthzSVNAccessFile "[REPOPATH]\authorization.conf"


Replace [REPOPATH] with your root repository location (eg. c:\svn_repository) and replace [DOMAINNAME] with your domain controller. If you have no domain name use "domaincontroller".

Almost done!

The last thing we need to do is add a file authorization.conf in the root of the repository and add these lines...

[groups]
admin = DOMAIN\username, username, DOMAIN\username2, username2
[/]
@admin= rw


You will notice we add an entry with the domain prefix and an entry without. This is because apache authenticates differently and we need both. You can make new groups etc. If you need security for specific repositories you can read further here

Last but not least, lets configure your client to use the repository.

Install TortoiseSVN on your client computer.
Create a folder on your computer to store your working copies. Lets call it "_Subversion".
Previously we created a repository called "ProjectX" so lets check out that repository.

Right Click on "_Subversion" folder and select "SVN Checkout". A window will popup. The URL of the repository will be in the format "http://SERVERIPWHERESUBVERSIONIS:8888/svn/ProjectX/".

Remember you can also use the Repository Browser to locate the projects, its also a good idea to add 3 folders to each project root called "trunk" (latest and greatest version), "branches" (Seperate dev streams of trunk version), "tags" (Tag trunk at specific revision for releases etc). Please read the Open Collabnet Subversion documents for any further help on usuage.