<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Mehfuz's WebLog : VS2008</title><link>http://weblogs.asp.net/mehfuzh/archive/tags/VS2008/default.aspx</link><description>Tags: VS2008</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Deploy, test and pack your code - Part 2 Using MsBuild</title><link>http://weblogs.asp.net/mehfuzh/archive/2008/09/07/deploy-test-and-pack-your-code-part-2-using-msbuild.aspx</link><pubDate>Sat, 06 Sep 2008 17:41:46 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6605315</guid><dc:creator>mehfuzh</dc:creator><author>mehfuzh</author><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6605315</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6605315</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/09/07/deploy-test-and-pack-your-code-part-2-using-msbuild.aspx#comments</comments><description>&lt;p&gt;In part one of this packing series I have shown, how you can automate your build process, test and optionally mock by using the popular .net deployment tool NAnt. If you don't know what I am talking about and just landed here by help of search engine. Let me put the link below again.&lt;/p&gt;  &lt;p&gt;&lt;a title="http://weblogs.asp.net/mehfuzh/archive/2008/08/30/deploy-test-and-pack-your-code-part-1-using-nant.aspx" href="http://weblogs.asp.net/mehfuzh/archive/2008/08/30/deploy-test-and-pack-your-code-part-1-using-nant.aspx"&gt;http://weblogs.asp.net/mehfuzh/archive/2008/08/30/deploy-test-and-pack-your-code-part-1-using-nant.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In this post, I will do a replay to mostly what I have talked in my last post but with MsBuild. Let's start with building the code. If you have a chance to see the above link you must have seen that I have to do strict maps of source files under the &lt;em&gt;csc&lt;/em&gt; task as well as the references to make things work. Now, searching the NAnt project I have found that it has a cool &lt;em&gt;solution&lt;/em&gt; task, which even let you define your own output path for libraries but unfortunately it does not work with .net 3.5 and Visual studio 2008. &lt;/p&gt;  &lt;p&gt;Typically , the solution task is defined under NAnt.VSNetTasks.dll also depends on the following assemblies&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/PackDeployandtestyourcodePart2UsingMsBui_9CA/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="77" alt="image" src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/PackDeployandtestyourcodePart2UsingMsBui_9CA/image_thumb.png" width="196" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;To use the task inside build script you need to do something like &lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;loadtasks&lt;/span&gt; &lt;span class="attr"&gt;assembly&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;ThirdParty\Nant\NAnt.VSNetTasks.dll&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;solution&lt;/span&gt; &lt;span class="attr"&gt;solutionfile&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;LinqToFlickr.sln&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;release&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;outputdir&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Bin&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;But , it ends up with &amp;quot;Solution format not supported&amp;quot; exception for VS 2008 solution. We can obviously use the &lt;em&gt;csc&lt;/em&gt; task instead and someday it will support the &lt;em&gt;solution&lt;/em&gt; task but you can do things with MsBuild more easily. Let's see the snippet below&lt;/span&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Project&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/developer/msbuild/2003&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Target&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Build&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;MSBuild&lt;/span&gt; &lt;span class="attr"&gt;Projects&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;LinqToFlickr.sln&amp;quot;&lt;/span&gt;
          &lt;span class="attr"&gt;Properties&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Configuration=Release&amp;quot;&lt;/span&gt;  &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Target&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Project&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;I have put the snippet under Linq.flickr.Targets. Now, if your solution has multiple projects and you want the output to go to a specific folder you can easily do that using the project's &amp;quot;property page&amp;quot;.&amp;#160; The advantage here is that, if a developer adds a new file, the build guy don't need to worry about syncing them up and thus if you have a nice set of rules in your team, it can be far more time saving than strict mapping.&lt;/p&gt;

&lt;p&gt;The next step is to test and deploy the library. I have defined another &lt;em&gt;.target&lt;/em&gt; file for holding the named variables , which I will be using later. I named it &lt;em&gt;include.Targets.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For , those who are curious, declaring property in MsBuild looks like&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Project&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/developer/msbuild/2003&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;PropertyGroup&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TaskDirectory&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Tasks&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;TaskDirectory&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;NUnit&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;ThirdParty\NUnit\nunit-console.exe&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;NUnit&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;PropertyGroup&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UsingTask&lt;/span&gt; &lt;span class="attr"&gt;AssemblyFile&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$(TaskDirectory)\MSBuild.Community.Tasks.dll&amp;quot;&lt;/span&gt;
           &lt;span class="attr"&gt;TaskName&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;MSBuild.Community.Tasks.Zip&amp;quot;&lt;/span&gt;
               &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Project&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;style type="text/css"&gt;





.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;As you can see it is possible to reference the properties later on (in this file or other files that includes it) by $(...) format. &lt;em&gt;UsingTask&amp;#160; &lt;/em&gt;is the MsBuild way of &lt;em&gt;loadtasks &lt;/em&gt;in NAnt which also mimics with the namespace directives in C#.&lt;/p&gt;

&lt;p&gt;To wrap up everything, I have created a master.proj file which is the entry point. it includes the targets and does the test and additionally zip things up. You can open up the master.proj in VS 2008. This will&amp;#160; give you the advantage of intellisense, but here to mention that the intellisense wont work nicely for custom made tasks. Inside the project node of master.proj you can specify default target like NAnt and can make other targets depend on it. So, even if the target is in one of files included, it will still fire up everything else before playing the final target.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Project&lt;/span&gt; &lt;span class="attr"&gt;DefaultTargets&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Deploy&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/developer/msbuild/2003&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
....
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Project&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;We have built the project, its time to copy them in a folder to do something on them before doing the final packing. I have created a tiny Task called &lt;em&gt;BatchCopy (I really missed one in the community tasks). &lt;/em&gt;The usage is pretty simple and it works pretty nice in my&amp;#160; project scope&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;BatchCopy&lt;/span&gt; &lt;span class="attr"&gt;source&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$(SourceDir)\Bin\Release&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;DestinationFolder&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$(BinDir)&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;ExtensionToExclude&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;.pdb;&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;BatchCopy&lt;/span&gt; &lt;span class="attr"&gt;source&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$(TestDir)\Bin\Release&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;DestinationFolder&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$(BinDir)&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;ExtensionToExclude&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;.pdb;&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;As you can see, it requires a source and destination path and there is another property where I can specify the extensions which I want to skip separated by commas.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;Till this line, I have built the project , copied assemblies to a folder, next cool thing is to test them out. Testing definitely to be done by NUnit. In Athena(Flickr API), I have used Typemock to fake request, responses, authentication, etc out so that I can test the whole API while I am on a plane to PDC 08 :-).&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;In the previous post, I have mentioned Typemock 5 made auto deploy possible for open source projects. Let's get that going.&amp;#160; &lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;Step one is to include three tasks&lt;/span&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UsingTask&lt;/span&gt; &lt;span class="attr"&gt;TaskName&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;TypeMock.MSBuild.TypeMockRegister&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;AssemblyFile&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$(TypeMockLocation)\TypeMock.MSBuild.dll&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UsingTask&lt;/span&gt; &lt;span class="attr"&gt;TaskName&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;TypeMock.MSBuild.TypeMockStart&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;AssemblyFile&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$(TypeMockLocation)\TypeMock.MSBuild.dll&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UsingTask&lt;/span&gt; &lt;span class="attr"&gt;TaskName&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;TypeMock.MSBuild.TypeMockStop&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;AssemblyFile&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$(TypeMockLocation)\TypeMock.MSBuild.dll&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;TypemockLocation&lt;/em&gt; is not the application folder rather where I have copied necessary dlls to make the auto deploy possible. Basically to run it as a standalone your deployment folder should have the following dlls in place copied from the Typemock installation folder.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/PackDeployandtestyourcodePart2UsingMsBui_9CA/image_4.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="197" alt="image" src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/PackDeployandtestyourcodePart2UsingMsBui_9CA/image_thumb_1.png" width="230" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Once everything is in place, the steps are the same that I have mentioned for NAnt. Only, few syntax that you need to watch out with wide eyes.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TypeMockRegister&lt;/span&gt; &lt;span class="attr"&gt;Company&lt;/span&gt; &lt;span class="kwrd"&gt;=&amp;quot;Open Source&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;License&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Get one for you&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;AutoDeploy&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;True&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;

&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TypeMockStart&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Exec&lt;/span&gt; &lt;span class="attr"&gt;ContinueOnError&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Command&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$(NUnit) $(BinDir)\Linq.Flickr.Test.dll&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TypeMockStop&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Don't forget to add the ContinueOnError=&amp;quot;false&amp;quot; that halts the script as soon as there is an error. Once, things are right running the build script will register auto deploy and run over your test project giving you the results. &lt;/p&gt;

&lt;p&gt;Lastly, moving to master.proj, I just wanted to zip everything up with the proper content.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;CreateItem&lt;/span&gt; &lt;span class="attr"&gt;Include&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$(BinDir)\**\Linq.Flickr.dll;$(BinDir)\**\LinqExtender.dll;readme.txt;&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Output&lt;/span&gt; &lt;span class="attr"&gt;ItemName&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;FilesToZip&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;TaskParameter&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Include&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;CreateItem&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Zip&lt;/span&gt; &lt;span class="attr"&gt;Files&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;@(FilesToZip)&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Flatten&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; 
                &lt;span class="attr"&gt;ZipFileName&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$(BinDir)\Linq.Flickr.Lib.zip&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;The CreateItem task lets you prepare an item collection based on the parameters you passed in the Include/Exclude attribute and finally outputs the list to a variable that you can use later on (in this case, it is used with the &lt;em&gt;Files&lt;/em&gt; attribute of the Zip task).&lt;/p&gt;

&lt;p&gt;This is just a simple way of getting things around with MsBuild. To spice a bit more, you can wrap the msbuild command in a batch file, which requires the following two lines&lt;/p&gt;

&lt;pre class="csharpcode"&gt;@ECHO ON
C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe Master.proj /m:2 /fileLogge&lt;/pre&gt;

&lt;p&gt;&lt;em&gt;fileLogger &lt;/em&gt;will create an output file (msbuild.log) after the build that contains the detail of execution. &lt;em&gt;/m &lt;/em&gt;defines that msbuild will run in two process in parallel, this option is pretty good for large solution (for ex, Telerik has plenty of projects in a solution and I found building with msbuild much faster than using the VS IDE), of course having quad core processor with /m:4 will give more boost than in two cores . In my other project which is LinqExtender, I created a script that download source code and setup working base with a click of a button. Therefore, those who check in/out things in codeplex or any other source control environment could find this task useful.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TFSGet&lt;/span&gt;
            &lt;span class="attr"&gt;Server&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;tfs05.codeplex.com&amp;quot;&lt;/span&gt;
            &lt;span class="attr"&gt;Port&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;443&amp;quot;&lt;/span&gt;
            &lt;span class="attr"&gt;Secured&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;
            &lt;span class="attr"&gt;Repository&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$/LinqExtender/somthing&amp;quot;&lt;/span&gt;
            &lt;span class="attr"&gt;UseUICredentials&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false/true&amp;quot;&lt;/span&gt;
            &lt;span class="attr"&gt;Username&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$(User)&amp;quot;&lt;/span&gt;
            &lt;span class="attr"&gt;Password&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$(Pass)&amp;quot;&lt;/span&gt;
            &lt;span class="attr"&gt;Domain&lt;/span&gt; &lt;span class="kwrd"&gt;=&amp;quot;snd&amp;quot;&lt;/span&gt;
            &lt;span class="attr"&gt;LocalPath&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;local path to host the source&amp;quot;&lt;/span&gt;
            &lt;span class="attr"&gt;UnBind&lt;/span&gt; = &lt;span class="kwrd"&gt;&amp;quot;true/false&amp;quot;&lt;/span&gt;
            &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;Here, UseUICredential = true, will bring up the TFS login prompt every time, so if you don't want to type in user/pass every time then just leave as it is and populate the username and password parameter with proper values.&amp;#160; &lt;em&gt;Unbind&lt;/em&gt;&amp;#160; will remove the source control binding after downloading , if set to &lt;em&gt;true&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Last but not the least, there is another task that I want to share with you is called &lt;em&gt;XmlFindReplace&lt;/em&gt;, this is useful if you are automating VSI package creation&amp;#160; which I did in my LinqExtender project (I hate doing this manually every time for deployment :-))&amp;#160; or want to create a starter project with predefined template.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;XmlFindReplace&lt;/span&gt;
      &lt;span class="attr"&gt;FilePath&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;.\Template\project.xml&amp;quot;&lt;/span&gt;
      &lt;span class="attr"&gt;Ns&lt;/span&gt; &lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/developer/msbuild/2003&amp;quot;&lt;/span&gt;
      &lt;span class="attr"&gt;Attribute&lt;/span&gt; = &lt;span class="kwrd"&gt;&amp;quot;Include&amp;quot;&lt;/span&gt;
      &lt;span class="attr"&gt;Element&lt;/span&gt; &lt;span class="kwrd"&gt;=&amp;quot;Reference&amp;quot;&lt;/span&gt;
      &lt;span class="attr"&gt;Text&lt;/span&gt; &lt;span class="kwrd"&gt;=&amp;quot;#ASSEMBLY#&amp;quot;&lt;/span&gt;
      &lt;span class="attr"&gt;ReplaceText&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;LinqExtender, Version=1.4.0.0, Culture=neutral, processorArchitecture=MSIL&amp;quot;&lt;/span&gt;
      &lt;span class="attr"&gt;DestinationFile&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$(TempDir)\LINQProvider.csproj&amp;quot;&lt;/span&gt;
&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Here you can do two sets of find and replace. Either replace the attribute value of an element which requires both the Element and its Attribute or just replace the element text in which case you need to provide only the Element name.&lt;/p&gt;

&lt;p&gt;So far, you can see that it is possible to do same things with Msbuild that is possible with NAnt, but MsBuild gives more integration to VS environment which sometimes give more power over how the build goes. Earlier, in a post I have shown that at the end of each project file there is a &amp;quot;AfterBuild&amp;quot;&amp;#160; and &amp;quot;BeforeBuild&amp;quot; target where you can put your own script to do some special tasks. Also, Msbuild comes as part of .net framework so that you don't ever need to bother about the script runtime and distributes.&lt;/p&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;div class="wlWriterSmartContent" id="scid:8eb9d37f-1541-4f29-b6f4-1eea890d4876:c8d0544a-796b-46ca-a02f-ae0ed413df75" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;&lt;p&gt;&lt;div&gt;Download &lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/PackDeployandtestyourcodePart2UsingMsBui_9CA/MsBuildTasks_1.zip" target="_self"&gt;MsBuildTasks.zip&lt;/a&gt;&lt;/div&gt;&lt;/p&gt;&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Hope all these info are useful for you to get going, I have added the tasks with test classes so that you can play, use or extend it as you like.&lt;/p&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f09%2f07%2fdeploy-test-and-pack-your-code-part-2-using-msbuild.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f09%2f07%2fdeploy-test-and-pack-your-code-part-2-using-msbuild.aspx" border="0" /&gt;&lt;/a&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6605315" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/TypeMock/default.aspx">TypeMock</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/MSBuild/default.aspx">MSBuild</category></item><item><title>Bundle SQL script with build process using MSBuild</title><link>http://weblogs.asp.net/mehfuzh/archive/2008/08/15/bundle-sql-script-with-build-process-using-msbuild.aspx</link><pubDate>Thu, 14 Aug 2008 19:29:49 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6518942</guid><dc:creator>mehfuzh</dc:creator><author>mehfuzh</author><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=6518942</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=6518942</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/08/15/bundle-sql-script-with-build-process-using-msbuild.aspx#comments</comments><description>&lt;p&gt;We are making a sample application, demo or startup kit or a toolkit with test project that requires some SQL scripts. We generally ship in a &lt;em&gt;readme.txt&lt;/em&gt; that says it all. But hey, how about having the script under automated process , like if my SQL Server and VS 2008 is in place, with the click of &lt;em&gt;&lt;strong&gt;Ctrl + Shift + B&lt;/strong&gt;&lt;/em&gt; everything gets ready. Here, we will do just right that.&lt;/p&gt;  &lt;p&gt;MSBuild provides a lot of community tasks that includes zip, XmlUpdater to SqlServer. You can get it all from &lt;em&gt;tigris.org&lt;/em&gt;. After having it installed you can either copy it to your local app directory or reference it using $(MSBuildExtensionsPath). In my case I have copied the dll into the &lt;em&gt;Tasks&lt;/em&gt; directory of my application (which is the example app supplied with LinqExtender). Anyway, there is a nice task called ExecuteDDL that will take in one or more sql script files , join with GO separator if required&amp;#160; and run it against your database.&lt;/p&gt;  &lt;p&gt;To start things off I have created a &lt;em&gt;Sql.Scripts.Targets&lt;/em&gt;. About *.Targets file, you can either include them in other targets or *.proj or *.csproj files where you will be using them. Its almost the same with NAnt scripts that terminate with .build extensions.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Project&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/developer/msbuild/2003&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;PropertyGroup&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TaskDirectory&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Tasks&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;TaskDirectory&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;BatchSql&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Sql\script.sql&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;BatchSql&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
       &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ConnectionString&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Server=localhost;Integrated Security=True&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ConnectionString&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;      
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;PropertyGroup&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UsingTask&lt;/span&gt; &lt;span class="attr"&gt;AssemblyFile&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$(TaskDirectory)\MSBuild.Community.Tasks.dll&amp;quot;&lt;/span&gt;
              &lt;span class="attr"&gt;TaskName&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;MSBuild.Community.Tasks.SqlServer.ExecuteDDL&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Project&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;As you can see inside &lt;em&gt;Sql.Scripts.Targets&lt;/em&gt; , I have added a block of PropertyGroup which declares the variables which I can use later in the script. I have referenced the &lt;em&gt;tasks&lt;/em&gt; directory where the task DLL resides. Also, added the batch SQL path (can add multiple separated by &amp;quot;;&amp;quot;) and the default connection string. &lt;em&gt;UsingTask&lt;/em&gt; is just like any other using statements in your c# code that lets you include the reference of the task which you will be using in this or other files that is dependent on this.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kwrd"&gt;Now, the interesting part. If you ever opened the c# project file by a notepad or any text editor, you must have seen this&lt;/span&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;&amp;lt;!-- To modify your build process, add your task inside one of the targets below and uncomment it. &lt;/span&gt;
&lt;span class="rem"&gt;       Other similar extension points exist, see Microsoft.Common.targets.&lt;/span&gt;
&lt;span class="rem"&gt;  &amp;lt;Target Name=&amp;quot;BeforeBuild&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;  &amp;lt;/Target&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;  &amp;lt;Target Name=&amp;quot;AfterBuild&amp;quot;&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;  &amp;lt;/Target&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;--&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span class="rem"&gt;As it says, you can add your custom tasks under it and before or after build, it will fire up your task to do the things you want it to do. So, our final touch is to include the target file and to add the ExecuteDDL task under &lt;em&gt;AfterBuild target.&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="rem"&gt;With this let's un-comment the above code and add our block there.&lt;/span&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Import&lt;/span&gt; &lt;span class="attr"&gt;Project&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Sql.Scripts.Targets&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Target&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;AfterBuild&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ExecuteDDL&lt;/span&gt; &lt;span class="attr"&gt;ConnectionString&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$(ConnectionString)&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Files&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;$(BatchSql)&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;ContinueOnError&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Target&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;  &lt;/pre&gt;

&lt;p&gt;That's it, next time you build the code, right after it will run the necessary scripts to setup your database.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/BundleSQLscriptwithbuildprocessusingMSBu_9FE6/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="228" alt="image" src="http://weblogs.asp.net/blogs/mehfuzh/WindowsLiveWriter/BundleSQLscriptwithbuildprocessusingMSBu_9FE6/image_thumb.png" width="397" border="0" /&gt;&lt;/a&gt;&amp;#160; &lt;/p&gt;

&lt;p&gt;As you can see that any error occurs gives you a prompt message with VS task list window that also gives the user a clue what to do next. Finally, I have added a&amp;#160; hollow class library project with the scripts tied up, please download it &lt;a href="http://weblogs.asp.net/blogs/mehfuzh/HollowMan.zip" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Hope that helps&lt;/p&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f08%2f15%2fbundle-sql-script-with-build-process-using-msbuild.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f08%2f15%2fbundle-sql-script-with-build-process-using-msbuild.aspx" border="0" /&gt;&lt;/a&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6518942" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/MSBuild/default.aspx">MSBuild</category></item><item><title>REST with LINQ to XML</title><link>http://weblogs.asp.net/mehfuzh/archive/2008/01/11/rest-with-linq-to-xml.aspx</link><pubDate>Fri, 11 Jan 2008 12:30:32 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5587927</guid><dc:creator>mehfuzh</dc:creator><author>mehfuzh</author><slash:comments>10</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=5587927</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=5587927</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/01/11/rest-with-linq-to-xml.aspx#comments</comments><description>&lt;p&gt;With LINQ to XML, what I have learned so far, it's awesome, it is not only the first class concept of processing XML data, but also let you process a complex XML doc in the most simplest and readable way.&lt;/p&gt; &lt;p&gt;I have a project called, &lt;a href="http://www.codeplex.com/LINQFlickr"&gt;Linq.Flickr&lt;/a&gt; , and I often need to process&amp;nbsp; XML data for REST query.&lt;/p&gt; &lt;p&gt;To show a simple example of LINQ to XML, lets take a REST response from a Flickr method called &lt;em&gt;flickr.people.getUploadStatus &lt;/em&gt;and see how it is processed.&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;user&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="12037949754@N01"&lt;/span&gt; &lt;span class="attr"&gt;ispro&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;  
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;username&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Bees&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;username&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; 
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;bandwidth&lt;/span&gt; &lt;span class="attr"&gt;maxbytes&lt;/span&gt;&lt;span class="kwrd"&gt;="2147483648"&lt;/span&gt; &lt;span class="attr"&gt;maxkb&lt;/span&gt;&lt;span class="kwrd"&gt;="2097152"&lt;/span&gt; 
&lt;span class="attr"&gt;usedbytes&lt;/span&gt;&lt;span class="kwrd"&gt;="383724"&lt;/span&gt; &lt;span class="attr"&gt;usedkb&lt;/span&gt;&lt;span class="kwrd"&gt;="374"&lt;/span&gt; &lt;span class="attr"&gt;remainingbytes&lt;/span&gt;&lt;span class="kwrd"&gt;="2147099924"&lt;/span&gt; &lt;span class="attr"&gt;remainingkb&lt;/span&gt;&lt;span class="kwrd"&gt;="2096777"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;filesize&lt;/span&gt; &lt;span class="attr"&gt;maxbytes&lt;/span&gt;&lt;span class="kwrd"&gt;="10485760"&lt;/span&gt; &lt;span class="attr"&gt;maxkb&lt;/span&gt;&lt;span class="kwrd"&gt;="10240"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;sets&lt;/span&gt; &lt;span class="attr"&gt;created&lt;/span&gt;&lt;span class="kwrd"&gt;="27"&lt;/span&gt; &lt;span class="attr"&gt;remaining&lt;/span&gt;&lt;span class="kwrd"&gt;="lots"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;user&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Before .net 3.5. it could have been done by GetElementyByTagName("users") - &amp;gt; inside the while loop getting the element, reading value, storing it in private variables , going to next sibling and repeat, if nested , then take the first child and so forth. But , in .net 3.5 using LINQ , the translation is not only just like XML itself, moreover , in XElement.Load , we can directly pass the REST query string.&lt;/p&gt;
&lt;p&gt;So, Two, steps to do a REST with LINQ&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Build the URL and pass it to XElement.Load 
&lt;li&gt;Parse the response and take necessary actions.&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;For example, for the above XML, I wrote something like below, in PhotoRepository.cs, that does a selective parsing.&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;try&lt;/span&gt;
{  &lt;/pre&gt;&lt;pre class="csharpcode"&gt;    XElement element = GetElement(##REQUEST URL##);

    People people = (from p &lt;span class="kwrd"&gt;in&lt;/span&gt; element.Descendants(&lt;span class="str"&gt;"user"&lt;/span&gt;)
      select &lt;span class="kwrd"&gt;new&lt;/span&gt; People
      {
            Id = p.Attribute(&lt;span class="str"&gt;"id"&lt;/span&gt;).Value ?? &lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty,
            IsPro =
            Convert.ToInt32(p.Attribute(&lt;span class="str"&gt;"ispro"&lt;/span&gt;).Value) == 0 ? &lt;span class="kwrd"&gt;false&lt;/span&gt; : &lt;span class="kwrd"&gt;true&lt;/span&gt;,
            BandWidth =
            (from b &lt;span class="kwrd"&gt;in&lt;/span&gt; element.Descendants(&lt;span class="str"&gt;"bandwidth"&lt;/span&gt;)
               select &lt;span class="kwrd"&gt;new&lt;/span&gt; BandWidth
                {
                      RemainingKB = 
                      Convert.ToInt32(b.Attribute(&lt;span class="str"&gt;"remainingkb"&lt;/span&gt;).Value),
                      UsedKB = Convert.ToInt32(b.Attribute(&lt;span class="str"&gt;"usedkb"&lt;/span&gt;).Value)
                 }).Single&amp;lt;BandWidth&amp;gt;()
               }).Single&amp;lt;People&amp;gt;();

    &lt;span class="kwrd"&gt;return&lt;/span&gt; people;
}
&lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
{
    &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ApplicationException("Could not process response", ex);
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Note :GetElement is a local method that does a XElement.Load, with some validation check.&lt;/p&gt;
&lt;p&gt;Here my Client-Side object looks like &lt;/p&gt;
&lt;p&gt;People&lt;br&gt;Id&lt;br&gt;IsPro&lt;br&gt;BandWidth&lt;br&gt;&amp;nbsp;&amp;nbsp; RemainingKB&lt;br&gt;&amp;nbsp;&amp;nbsp; UsedKB 
&lt;p&gt;The most interesting thing is, everything is done on the fly , no loop, no intermediate result tracking, no headache of sibling and first child.Overall, the code has a high point in terms of readability.&lt;/p&gt;
&lt;p&gt;Take that !!&lt;/p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f01%2f11%2frest-with-linq-to-xml.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f01%2f11%2frest-with-linq-to-xml.aspx" border="0"&gt;&lt;/a&gt; 
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5587927" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Linq.Flickr/default.aspx">Linq.Flickr</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LINQ+To+Xml/default.aspx">LINQ To Xml</category></item><item><title>[New Article] Creating custom LINQ provider using LinqExtender</title><link>http://weblogs.asp.net/mehfuzh/archive/2008/01/08/new-article-creating-custom-linq-provider-using-linqextender.aspx</link><pubDate>Mon, 07 Jan 2008 23:32:39 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5565950</guid><dc:creator>mehfuzh</dc:creator><author>mehfuzh</author><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=5565950</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=5565950</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2008/01/08/new-article-creating-custom-linq-provider-using-linqextender.aspx#comments</comments><description>&lt;p&gt;First of all happy new year, secondly my new article is just published at Dotnetslackers. This explains the detail of creating custom LINQ providers using Linqextender. &lt;/p&gt; &lt;p&gt;You can check that out at &lt;a title="http://dotnetslackers.com/articles/csharp/CreatingCustomLINQProviderUsingLinqExtender.aspx" href="http://dotnetslackers.com/articles/csharp/CreatingCustomLINQProviderUsingLinqExtender.aspx"&gt;http://dotnetslackers.com/articles/csharp/CreatingCustomLINQProviderUsingLinqExtender.aspx&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Moreover, I would like to add some tiny enhancements to the extender.&lt;/p&gt; &lt;p&gt;1. All the extender descendant can now do something like.&lt;/p&gt;&lt;pre class="csharpcode"&gt;var query = (from q &lt;span class="kwrd"&gt;in&lt;/span&gt; _queryContext
             orderby q.LastUpdated descending
             select &lt;span class="kwrd"&gt;new&lt;/span&gt; { q.Id, q.Title, q.LastUpdated }).Take(1);
 
&lt;span class="kwrd"&gt;int&lt;/span&gt; count = query.Count(); &lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;&lt;font face="Tahoma"&gt;2. OpenLinqToSql, which is a part of &lt;a href="http://www.codeplex.com/LINQExtender"&gt;Linqextender&lt;/a&gt;, now, supports SQLCE database.&lt;/font&gt;&lt;/pre&gt;&lt;pre class="csharpcode"&gt;&lt;font face="Tahoma"&gt;3. Easy OnError event for exception trapping.&lt;/font&gt;&lt;/pre&gt;
&lt;p&gt;In the end, there are plenty of things that needs to done and to be told, but the article explains exactly how to get started and create a provider in no time. Please take a look , and if possible give some votes.&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f01%2f08%2fnew-article-creating-custom-linq-provider-using-linqextender.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2008%2f01%2f08%2fnew-article-creating-custom-linq-provider-using-linqextender.aspx" border="0"&gt;&lt;/a&gt; &lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;&lt;/pre&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5565950" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LinqExtender/default.aspx">LinqExtender</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/OpenLinqToSql/default.aspx">OpenLinqToSql</category></item><item><title>IOrderedQueryable VS IQueryable</title><link>http://weblogs.asp.net/mehfuzh/archive/2007/12/06/iorderedqueryable-vs-iqueryable.aspx</link><pubDate>Wed, 05 Dec 2007 18:27:51 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5406889</guid><dc:creator>mehfuzh</dc:creator><author>mehfuzh</author><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=5406889</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=5406889</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2007/12/06/iorderedqueryable-vs-iqueryable.aspx#comments</comments><description>&lt;p&gt;We have seen that , while making general LINQ query provider , we have to implement IQueryable along with IQueryProvider. &lt;/p&gt; &lt;p&gt;But what about the following query.&lt;/p&gt;&lt;pre class="csharpcode"&gt;var query = (from ph &lt;span class="kwrd"&gt;in&lt;/span&gt; context.Photos
             &lt;span class="kwrd"&gt;where&lt;/span&gt; ph.User == User &amp;amp;&amp;amp; ph.PhotoSize == PhotoSize.Medium
 &amp;amp;&amp;amp; ph.SearchText == &lt;span class="str"&gt;"pocketpc, windows mobile"&lt;/span&gt; &amp;amp;&amp;amp; 
ph.SearchMode == SearchMode.TagsOnly orderby PhotoOrder.Date_Posted descending
             select ph ).Take(10).Skip(0);
&lt;/pre&gt;
&lt;p&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/p&gt;
&lt;p&gt;As, this query has orderby clause, this will require IOrderedQueryable instead of IQueryable, or less it will end up with build error. &lt;/p&gt;
&lt;p&gt;Now, digging deeper, what is the methodcall for orderby "item" descending/ascending&amp;nbsp; &lt;/p&gt;
&lt;p&gt;Simple order by , like orderby ph.id / orderby ph.id ascending, the internal method call is OrderBy(ph=&amp;gt;ph.id)&lt;/p&gt;
&lt;p&gt;Query &lt;/p&gt;&lt;pre class="csharpcode"&gt;var query = from ph &lt;span class="kwrd"&gt;in&lt;/span&gt; context.Photos &lt;span class="kwrd"&gt;where&lt;/span&gt; ph.user = &lt;span class="str"&gt;"jcl"&lt;/span&gt;
 order by ph.Date_Taken select ph;&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;&lt;/pre&gt;
&lt;p&gt;but if we use, orderby p.id descending , the internal&amp;nbsp; method call will be made as&amp;nbsp; OrderByDescending(ph =&amp;gt; ph.id).Therefore, in CreateQuery&amp;lt;T&amp;gt;, we have to check for OrderByDescending and OrderBy method separately to process data accordingly.&lt;/p&gt;
&lt;p&gt;Which could be&lt;/p&gt;
&lt;p&gt;MethodCallExpression curentMethodcall = _expression &lt;span class="kwrd"&gt;as&lt;/span&gt; MethodCallExpression;&lt;br&gt;&lt;br&gt;_asc = curentMethodcall.Method.Name == CallType.ORDERBYDESC ? &lt;span class="kwrd"&gt;false&lt;/span&gt; : &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;br&gt;&lt;br&gt;ProcessExpression(curentMethodcall.Arguments[1], _dummyPhotoObject);&lt;/p&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;And during ProcessExpression , the expression breakdown will be&lt;/p&gt;
&lt;p&gt;UnaryExpression&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; LamdaExpression&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Memberexpresion ( for p = &amp;gt; p.id) or direct ConstantExpression (for p=&amp;gt; "Dake_take")&lt;/p&gt;
&lt;p&gt;Source : &lt;a href="http://www.codeplex.com/LINQExtender"&gt;LinqExtender&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Hope this is useful&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2007%2f12%2f06%2fiorderedqueryable-vs-iqueryable.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fmehfuzh%2farchive%2f2007%2f12%2f06%2fiorderedqueryable-vs-iqueryable.aspx" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5406889" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LINQ/default.aspx">LINQ</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/VS2008/default.aspx">VS2008</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LinqExtender/default.aspx">LinqExtender</category></item></channel></rss>