Resource

This is a simple task, but it took some time for me to udnerstand, as MSBuild was a new thing to me.
First, Get the latest code from TFS is TFS task, not MSBUild task. So, you can use tf.exe command-line utility.

[sourcecode language="vb"]
"C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\tf.exe" get $/root/MSBUILD/Team/Sapphire /force /recursive
[/sourcecode]

the batch file is like this

[sourcecode language="vb"]
"C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\tf.exe" get $/root/OccupyingSpace/GoYocal /force /recursive
"C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe" "C:\TEMP\Test_GoYocalBuild.proj" /t:Clean;Test
pause
[/sourcecode]

You need SDC taks in order to build .sln file. Please download it from codeplex. I created a simple proj file that builds .sln file

[sourcecode language="xml"]
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\TeamBuild\Microsoft.TeamFoundation.Build.targets" />
<Import Project="C:\vss\root\MSBUILD\bin\Microsoft.Sdc.Common.tasks"/>
<Target Name="Test" >
<Tools.DevEnv
VisualStudio="9.0"
Path="C:\VSS\root\OccupyingSpace\GoYocal\GoYocal.sln"
Config="Release"
OutputFolder="C:\VSS\root\OccupyingSpace\GoYocal\src\app\bin"
Clean="true">
</Tools.DevEnv>
</Target>

<PropertyGroup>
<TFSServerName>http://rbi101:8080</TFSServerName>
<SourceControlMainDirectory>$/root/OccupyingSpace/GoYocal</SourceControlMainDirectory>
<WorkspaceName>myworkspace</WorkspaceName>
<TfCommand>"C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\tf.exe"</TfCommand>
<DevenvCommand>"C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"</DevenvCommand>
<WorkingDirectory>c:\</WorkingDirectory>
</PropertyGroup>
</Project>
[/sourcecode]

After I used the batch file, I realised I could use <Exce Command=''> for any dos command. So, I moved "GetLatest" bit into msbuild proj.
Also, included remote copy to the server. The final codes are like the below

batch file

[sourcecode language="vb"]
"C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe" MSBUld_Build.proj /t:GetLatest;Build;Deploy
pause
[/sourcecode]

and msbuild proj file

[sourcecode language="xml"]
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\TeamBuild\Microsoft.TeamFoundation.Build.targets" />
<Import Project="C:\MSBUILD\bin\Microsoft.Sdc.Common.tasks"/>

<PropertyGroup>
<TF>"C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\tf.exe"</TF>
<TFSourceLocation>$/Occup/GoYocal</TFSourceLocation>
<SolutionRoot>C:\Occu\GoYocal</SolutionRoot>
<RemoteWebRoot>\\TJ103\d$\Occu\WebSites\GoYocal</RemoteWebRoot>
<Copy>xcopy /E /I /R /Y</Copy>
</PropertyGroup>

<Target Name="GetLatest">
<Exec Command="$(TF) get $(TFSourceLocation) /force /recursive /version:T /noprompt" ContinueOnError="true" />
</Target>

<Target Name="Build" >
<Tools.DevEnv VisualStudio="9.0" Path="$(SolutionRoot)\GoYocal.sln" Config="Release" OutputFolder="$(SolutionRoot)\src\app\bin" Clean="true">
</Tools.DevEnv>
</Target>

<Target Name="Deploy">
<Exec Command='net use "x:" "$(RemoteWebRoot)" /u:domain\username pwd' />
<Exec Command='$(Copy) "$(SolutionRoot)\src\app" "x:" '/>
<Exec Command='net use x: /d' />
</Target>

</Project>
[/sourcecode]


Andrew Chaa

another day, another PR