<?xml version="1.0" encoding="utf-8"?>
<feed xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom">
  <title>Sayed Ibrahim Hashimi</title>
  <link rel="alternate" type="text/html" href="http://www.sedodream.com/" />
  <link rel="self" href="http://www.sedodream.com/SyndicationService.asmx/GetAtom" />
  <icon>favicon.ico</icon>
  <updated>2008-06-26T23:28:35.2227871-07:00</updated>
  <author>
    <name>Sayed Ibrahim Hashimi</name>
  </author>
  <subtitle>MSBuild, C#, Visual Studio, and more</subtitle>
  <id>http://www.sedodream.com/</id>
  <generator uri="http://www.dasblog.net" version="1.8.5223.2">DasBlog</generator>
  <entry>
    <title>MSBuild Conditions on Targets</title>
    <link rel="alternate" type="text/html" href="http://www.sedodream.com/PermaLink,guid,a3e0f4b1-5714-4491-9134-cce95b1d6e19.aspx" />
    <id>http://www.sedodream.com/PermaLink,guid,a3e0f4b1-5714-4491-9134-cce95b1d6e19.aspx</id>
    <published>2008-06-26T23:28:35.2227871-07:00</published>
    <updated>2008-06-26T23:28:35.2227871-07:00</updated>
    <category term="MSBuild" label="MSBuild" scheme="dasBlog" />
    <category term="Team Build" label="Team Build" scheme="dasBlog" />
    <category term="TFS" label="TFS" scheme="dasBlog" />
    <content type="html">&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
   &lt;font face=Calibri color=#000000 size=3&gt;This post is related to my&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;previous
   post &lt;/font&gt;&lt;a href="http://www.sedodream.com/PermaLink,guid,096a2e3f-fcff-4715-8d00-73d8f2491a13.aspx"&gt;&lt;font face=Calibri size=3&gt;MSBuild
   RE: Enforcing the Build Agent in a Team Build&lt;/font&gt;&lt;/a&gt;&lt;font face=Calibri color=#000000 size=3&gt; which
   is a response on the post by Michael Ruminer at &lt;/font&gt;&lt;a href="http://manicprogrammer.com/cs/blogs/michaelruminer/archive/2008/06/19/enforcing-the-build-agent-in-a-team-build.aspx"&gt;&lt;font face=Calibri size=3&gt;http://manicprogrammer.com/cs/blogs/michaelruminer/archive/2008/06/19/enforcing-the-build-agent-in-a-team-build.aspx&lt;/font&gt;&lt;/a&gt;&lt;font face=Calibri color=#000000 size=3&gt;. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
   &lt;font face=Calibri color=#000000 size=3&gt;Basically every MSBuild element can contain
   a Condtions attribute. You can read more at &lt;/font&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/7szfhaft.aspx"&gt;&lt;font face=Calibri size=3&gt;MSBuild
   Conditions&lt;/font&gt;&lt;/a&gt;&lt;font face=Calibri color=#000000 size=3&gt;. So even targets can
   have conditions attached to them! Despite the fact that you can do this, you should
   not. I recommend that you do not use conditions on targets. Conditions on targets
   seem straight forward but after you take a closer look they are more complicated.
   We can take a look at some of the items that come to mind here.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
   &lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;Conditions
   on targets and DependsOnTargets don’t play well&lt;o:p&gt;&lt;/o:p&gt;
   &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
   &lt;font face=Calibri color=#000000 size=3&gt;Take a look at this simple project file&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
   &lt;font face=Calibri size=3&gt;&lt;font color=#006400&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;br&gt;
   &amp;lt;Project ToolsVersion="2.0" 
   &lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xmlns="&lt;/font&gt;&lt;a href="http://schemas.microsoft.com/developer/msbuild/2003"&gt;&lt;font color=#006400&gt;http://schemas.microsoft.com/developer/msbuild/2003&lt;/font&gt;&lt;/a&gt;&lt;font color=#006400&gt;"&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DefaultTargets="Demo"&amp;gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
   &lt;font face=Calibri color=#006400 size=3&gt;&amp;nbsp; &amp;lt;PropertyGroup&amp;gt;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;AllowTarget&amp;gt;true&amp;lt;/AllowTarget&amp;gt;&lt;br&gt;
   &amp;nbsp; &amp;lt;/PropertyGroup&amp;gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
   &lt;font face=Calibri color=#006400 size=3&gt;&amp;nbsp; &amp;lt;Target Name="SupressTarget"&amp;gt;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;CreateProperty Value="false"&amp;gt;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Output PropertyName="AllowTarget" TaskParameter="Value"/&amp;gt;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/CreateProperty&amp;gt;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Message Text=" ==== SupressTarget ==== " Importance="high"/&amp;gt;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Message Text="AllowTarget: $(AllowTarget)"/&amp;gt;&lt;br&gt;
   &amp;nbsp; &amp;lt;/Target&amp;gt;&lt;br&gt;
   &amp;nbsp; 
   &lt;br&gt;
   &amp;nbsp; 
   &lt;br&gt;
   &amp;nbsp; &amp;lt;Target Name="Demo" Condition="'$(AllowTarget)'=='true'" 
   &lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DependsOnTargets="SupressTarget"&amp;gt;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Message Text=" ===== Demo ===== " Importance="high" /&amp;gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
   &lt;font face=Calibri color=#006400 size=3&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Message Text="AllowTarget:
   $(AllowTarget)"/&amp;gt;&lt;br&gt;
   &amp;nbsp; &amp;lt;/Target&amp;gt;&lt;br&gt;
   &amp;nbsp; 
   &lt;br&gt;
   &amp;lt;/Project&amp;gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
   &lt;font face=Calibri color=#000000 size=3&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-fareast-font-family: 'Times New Roman'"&gt;In
   this project the main target is Demo and it depends on a target SupressTarget which
   actually disables the Demo target based on its condition. If you execute the command &lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'"&gt;msbuild
   /t:Demo&lt;/span&gt;&lt;/b&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-fareast-font-family: 'Times New Roman'"&gt; you
   get the results shown below.&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
   &lt;font face=Calibri color=#000000 size=3&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-fareast-font-family: 'Times New Roman'"&gt;
   &lt;o:p&gt;
      &lt;img alt="" hspace=0 src="http://www.sedodream.com/content/binary/20080627-01.png" align=baseline border=0&gt;
   &lt;/o:p&gt;
   &lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;font face=Calibri color=#000000&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-fareast-font-family: 'Times New Roman'"&gt;
&lt;o:p&gt;
   &lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"&gt;
      &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-fareast-font-family: 'Times New Roman'"&gt;Most
      users would expect that the target SupressTarget target would execute which sets the
      AllowTarget value to false, and then the Demo target is skipped. But what is happening
      here is that by the time DependsOnTargets is evaluated the condition has already been
      evaluated and has passed! The even more interesting thing here is if you execute&lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'"&gt; msbuild
      /t:SupressTarget;Demo&lt;/span&gt;&lt;/b&gt;&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-fareast-font-family: 'Times New Roman'"&gt; the
      results are shown below.&lt;/span&gt;
   &lt;/p&gt;
   &lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"&gt;
      &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'; mso-fareast-font-family: 'Times New Roman'"&gt;
      &lt;o:p&gt;&lt;/o:p&gt;
      &lt;/span&gt;&amp;nbsp;&lt;img alt="" hspace=0 src="http://www.sedodream.com/content/binary/20080627-02.png" align=baseline border=0&gt;
   &lt;/p&gt;
   &lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
      &lt;font face=Calibri&gt;So this time it was skipped, because SupressTarget was called before
      the Demo target was invoked so the condition evaluated to false.&lt;/font&gt;
   &lt;/p&gt;
   &lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
      &lt;o:p&gt;
         &lt;font face=Calibri&gt;&amp;nbsp;&lt;/font&gt;
      &lt;/o:p&gt;
   &lt;/p&gt;
   &lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
      &lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font face=Calibri&gt;Conditions and target batching
      doesn’t work well either&lt;o:p&gt;&lt;/o:p&gt;
      &lt;/font&gt;&lt;/b&gt;
   &lt;/p&gt;
   &lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
      &lt;font face=Calibri&gt;If you are batching a target and you want to execute the target
      for some batches but not others, this cannot be achieved with target conditions, for
      a few reasons but the simplest is: Either a target is or is not defined. When the
      target is going to be executed for the first time the condition is evaluated. If the
      condition is true it will exist, otherwise it will not.&lt;/font&gt;
   &lt;/p&gt;
   &lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
      &lt;font face=Calibri&gt;I thought of some other issues but they are not coming to me at
      this time, but I think this is enough to deter you from using target dependencies.
      Instead of target dependencies you should take a look at other way of achieving the
      same results.&lt;/font&gt;
   &lt;/p&gt;
   &lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
      &lt;o:p&gt;
         &lt;font face=Calibri&gt;&amp;nbsp;&lt;/font&gt;
      &lt;/o:p&gt;
   &lt;/p&gt;
   &lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
      &lt;font face=Calibri&gt;Sayed Ibrahim Hashimi&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;&lt;/font&gt;&gt;
&lt;img width="0" height="0" src="http://www.sedodream.com/aggbug.ashx?id=a3e0f4b1-5714-4491-9134-cce95b1d6e19" /&gt;</content>
  </entry>
  <entry>
    <title>MSBuild RE: Enforcing the Build Agent in a Team Build</title>
    <link rel="alternate" type="text/html" href="http://www.sedodream.com/PermaLink,guid,096a2e3f-fcff-4715-8d00-73d8f2491a13.aspx" />
    <id>http://www.sedodream.com/PermaLink,guid,096a2e3f-fcff-4715-8d00-73d8f2491a13.aspx</id>
    <published>2008-06-19T21:22:57.5290000-07:00</published>
    <updated>2008-06-19T21:33:27.7637500-07:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
      This is a post that responds to a post by Michael Ruminer at <a href="http://manicprogrammer.com/cs/blogs/michaelruminer/archive/2008/06/19/enforcing-the-build-agent-in-a-team-build.aspx">Enforcing
      the Build Agent in a Team Build</a>. I hope I correctly understand his situation.
      Here is my summary of it. 
   </p>
        <ul>
          <li>
         You have a specified value for the property <span style="color:#00b050; font-family:Courier New">BuildAgentName</span></li>
          <li>
         You create various MSBuild scripts that will hook into a TeamBuild 
      </li>
          <li>
         You want to specify in each MSBuild script the names of the build agents that are
         allowed to run the build 
      </li>
          <li>
         If the current value for <span style="color:#00b050; font-family:Courier New">BuildAgentName</span> is
         not in the list above, fail the build otherwise allow it to continue 
      </li>
        </ul>
        <p>
      My solution to this problem is to create a property, <span style="color:#00b050; font-family:Courier New">AllowedBuildAgents</span>,
      which will contain a semi-colon separated list of the allowed build agent names. Then
      this is converted into an item, <span style="color:#00b050; font-family:Courier New">AllowedBuildAgentsItem</span>,
      so batching can be preformed over it. If you are not familiar with MSBuild batching
      you can see my previous postings at: 
   </p>
        <ul>
          <li>
            <a href="http://www.sedodream.com/PermaLink,guid,5f1e0445-ce3d-4052-ba80-42fd19512d42.aspx">MSBuild
         Batching Part 1</a>
          </li>
          <li>
            <a href="http://www.sedodream.com/PermaLink,guid,b721bc22-c375-4e1e-bcc9-512dd64096bb.aspx">MSBuild
         Batching Part 2</a>
          </li>
          <li>
            <a href="http://www.sedodream.com/PermaLink,guid,cab57d7f-9d6e-4358-8491-dc033fb3bacc.aspx">MSBuild
         Batching Part 3</a>
          </li>
        </ul>
        <p>
      The main objective here is to create an item that contains all the allowed names, <span style="color:#00b050; font-family:Courier New">AllowedBuildAgentsItem</span>,
      and batch over them. If the value for <span style="color:#00b050; font-family:Courier New">BuildAgentName</span> is
      equal to any value in that item then we want to allow the build. I create a property <span style="color:#00b050; font-family:Courier New">BuildAgentAllowed</span> which
      defaults to false, and if that condition is true then I set <span style="color:#00b050; font-family:Courier New">BuildAgentAllowed</span> to
      true. So I created a target <span style="color:#00b050; font-family:Courier New">DetermineIfAuthorizedBuildAgent</span> that
      depends will throw an error if <span style="color:#00b050; font-family:Courier New">BuildAgentAllowed</span> is
      false. Also this target depends on the target that will actually populate that value,
      which is the <span style="color:#00b050; font-family:Courier New">GetBuildAgentAllowed</span> target.
      The build script is placed below. I added a few elements that were for demo only.
      Those are; value for BuildAgentName and BeforeEndToEndIteration target. See comments
      in the file (which can be downloaded at the end of this post). 
   </p>
        <p style="background: #d9d9d9">
      &lt;?xml version="1.0" encoding="utf-8"?&gt;<br />
      &lt;Project ToolsVersion="2.0" 
      <br />
      xmlns="http://schemas.microsoft.com/developer/msbuild/2003"<br />
      DefaultTargets="BeforeEndToEndIteration"&gt;<br /><br />
      &lt;!-- 
      <br />
      Assume that this value has been set already. 
      <br />
      I'm declaring it here for this demonstration.<br />
      --&gt;<br />
      &lt;PropertyGroup&gt;<br />
      &lt;BuildAgentName&gt;Sayed_001&lt;/BuildAgentName&gt;<br />
      &lt;/PropertyGroup&gt;<br /><br /><br /><br />
      &lt;PropertyGroup&gt;<br />
      &lt;BeforeEndToEndIterationDependsOn&gt;<br />
      $(BeforeEndToEndIterationDependsOn);<br />
      DetermineIfAuthorizedBuildAgent;<br />
      &lt;/BeforeEndToEndIterationDependsOn&gt;<br />
      &lt;/PropertyGroup&gt;<br /><br />
      &lt;!--<br />
      Define this here as a property so it can be passed 
      <br />
      via Properties from various callers.<br />
      --&gt;<br />
      &lt;PropertyGroup&gt;<br />
      &lt;AllowedBuildAgents&gt;Sayed_001;Sayed_003;Sayed_005&lt;/AllowedBuildAgents&gt;<br />
      &lt;/PropertyGroup&gt;<br /><br />
      &lt;!-- 
      <br />
      Convert the property into an item so we can batch over it.<br />
      --&gt;<br />
      &lt;ItemGroup&gt;<br />
      &lt;AllowedBuildAgentsItem Include="$(AllowedBuildAgents)"/&gt;<br />
      &lt;/ItemGroup&gt;<br />
      &lt;!-- 
      <br />
      Specify this value to false. If allowed it will be set to true.<br />
      --&gt;<br />
      &lt;PropertyGroup&gt;<br />
      &lt;BuildAgentAllowed&gt;false&lt;/BuildAgentAllowed&gt;<br />
      &lt;/PropertyGroup&gt;<br /><br /><br /><br />
      &lt;Target Name="PrintInfo"&gt;<br />
      &lt;Message Text="AllowedBuildAgentsItem: @(AllowedBuildAgentsItem,'%0a%0d')"/&gt;<br />
      &lt;/Target&gt;<br /><br />
      &lt;!-- Executing this target will make the GetBuildAgentAllowed target execute first
      --&gt;<br />
      &lt;Target Name="DetermineIfAuthorizedBuildAgent" 
      <br />
      DependsOnTargets="GetBuildAgentAllowed"&gt;<br />
      &lt;Message Text="BuildAgentAllowed: $(BuildAgentAllowed)"/&gt;<br />
      &lt;Error Text="This build can only be run on one of the following build agents: @(AllowedBuildAgentsItem)" 
      <br />
      Condition="'$(BuildAgentAllowed)'=='false'" /&gt;<br />
      &lt;/Target&gt;<br /><br />
      &lt;!-- 
      <br />
      This target will be executed for each value in the AllowedBuildAgentsItem.<br />
      If the BuildAgentName is equal to any value in AllowedBuildAgentsItem then the<br />
      property BuildAgentAllowed will be set to true.<br />
      --&gt;<br />
      &lt;Target Name="GetBuildAgentAllowed" Outputs="%(AllowedBuildAgentsItem.Identity)"&gt;<br />
      &lt;Message Text="GetBuildAgentAllowed %25(AllowedBuildAgentsItem.Identity): %(AllowedBuildAgentsItem.Identity)"/&gt;<br /><br />
      &lt;CreateProperty Value="true" Condition="'$(BuildAgentName)'=='%(AllowedBuildAgentsItem.Identity)'"&gt;<br />
      &lt;Output PropertyName="BuildAgentAllowed" TaskParameter="Value"/&gt;<br />
      &lt;/CreateProperty&gt;<br /><br />
      &lt;/Target&gt;<br /><br /><br /><br />
      &lt;!-- 
      <br />
      This target is really executed by TeamBuild but I will 
      <br />
      put it here for demonstration. If this target executes then the build<br />
      was allowed otherwise an error will be shown.<br />
      --&gt;<br />
      &lt;Target Name="BeforeEndToEndIteration" DependsOnTargets="$(BeforeEndToEndIterationDependsOn)"&gt;<br />
      &lt;Message Text="EndToEndIteration starting"/&gt;<br />
      &lt;/Target&gt;<br /><br />
      &lt;/Project&gt; 
   </p>
        <p>
      The only reason that I have defined the allowed build agents in a property (<span style="color:#00b050; font-family:Courier New">AllowedBuildAgents</span>)
      is because I want to allow external sources to specify it. You can specify properties
      through the <a href="http://msdn.microsoft.com/en-us/library/ms164311.aspx">command
      line</a> or when using the <a href="http://msdn.microsoft.com/en-us/library/7z253716.aspx">MSBuild
      Task</a>. Then the script converts this to an item. If I execute this project I would
      expect it to succeed because the defined value for BuildAgentName is contained in
      the list of <span style="color:#00b050; font-family:Courier New">AllowedBuildAgents</span>.
      The results of executing this project are shown below. 
   </p>
        <p>
          <img src="http://www.sedodream.com/content/binary/062008_0423_MSBuildREEn1.png" alt="" />
        </p>
        <p>
      Now we can change the value for <span style="color:#00b050; font-family:Courier New">BuildAgentName</span>,
      by using the command <span style="color:#00b050; font-family:Courier New">msbuild.exe
      BuildAgent01.proj /p:BuildAgentName=Sayed_010</span>. We would expect the build to
      fail. The results of this are below. 
   </p>
        <p>
          <img src="http://www.sedodream.com/content/binary/062008_0423_MSBuildREEn2.png" alt="" />
        </p>
        <p>
        </p>
        <p>
      So the build failed as expected so we are good. Any questions? 
   </p>
        <p>
        </p>
        <p>
          <a href="http://www.sedodream.com/content/binary/BuildAgent01.proj.txt">BuildAgent01.proj</a>
        </p>
        <p>
      Sayed Ibrahim Hashimi
   </p>
        <img width="0" height="0" src="http://www.sedodream.com/aggbug.ashx?id=096a2e3f-fcff-4715-8d00-73d8f2491a13" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Changing Build Verbosity in Visual Studio</title>
    <link rel="alternate" type="text/html" href="http://www.sedodream.com/PermaLink,guid,b3b0d07b-3f21-41ab-9e52-4da8ff268a66.aspx" />
    <id>http://www.sedodream.com/PermaLink,guid,b3b0d07b-3f21-41ab-9e52-4da8ff268a66.aspx</id>
    <published>2008-06-15T22:50:26.7370000-07:00</published>
    <updated>2008-06-15T22:50:26.7370000-07:00</updated>
    <category term="MSBuild" label="MSBuild" scheme="dasBlog" />
    <category term="Visual Studio" label="Visual Studio" scheme="dasBlog" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
      If you are customizing your build process you may need to increase the verbosity that
      Visual Studio uses when building your projects. It is pretty easy to change this value,
      you just go to <span style="font-family:Courier New"><em>Tools-&gt;Options</em></span> then
      find the <span style="font-family:Courier New"><em>Project and Solutions-&gt;Build
      and Run</em></span> node. The dialog is shown here 
   </p>
        <p>
          <a href="http://www.sedodream.com/content/binary/BuildOptions.jpg">
            <img src="http://www.sedodream.com/content/binary/061608_0550_ChangingBui1.png" alt="" border="0" />
          </a>
        </p>
        <p>
      The area where the verbosity setting lies is highlighted. I've got mine set to Detailed,
      which produces a lot of output. If you set it to Diagnostic, then you should be ready
      for a lot of output. Most like much more then you need! 
   </p>
        <p>
          <br />
      Sayed Ibrahim Hashimi
   </p>
        <img width="0" height="0" src="http://www.sedodream.com/aggbug.ashx?id=b3b0d07b-3f21-41ab-9e52-4da8ff268a66" />
      </div>
    </content>
  </entry>
  <entry>
    <title>MSBuild Reserved Properties</title>
    <link rel="alternate" type="text/html" href="http://www.sedodream.com/PermaLink,guid,7e11f92e-e778-4e69-9441-9a6be3512e71.aspx" />
    <id>http://www.sedodream.com/PermaLink,guid,7e11f92e-e778-4e69-9441-9a6be3512e71.aspx</id>
    <published>2008-06-08T22:52:31.2500000-07:00</published>
    <updated>2008-06-08T22:59:56.2656250-07:00</updated>
    <category term="MSBuild" label="MSBuild" scheme="dasBlog" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
      If you take a look the MSDN documentation for the reserved <a href="http://msdn.microsoft.com/en-us/library/ms164309.aspx">MSBuild
      Reserved Properties</a> you will see many properties listed. For one reason or another
      there are actually several reserved properties that are missing from that list. Here
      is the list of all the reserved properties, the ones missing from that page are presented
      here in <strong>bold</strong>. For those that are listed on that page the description
      is taken from the MSDN. Also this is the list for MSBuild 3.5. 
   </p>
        <p>
        </p>
        <ul>
          <li>
            <div>
              <strong>MSBuildNodeCount </strong>
            </div>
            <ul>
              <li>
               Contains the number of nodes, processes, which is being used to build the project. 
            </li>
            </ul>
          </li>
          <li>
            <div>
              <strong>MSBuildExtensionsPath32 </strong>
            </div>
            <ul>
              <li>
               Path to MSBuild extensions path specifically for the 32 bit directory. If you are
               using a 32 bit machine then this will be the same value as MSBuildExtensionsPath property. 
            </li>
              <li>
               This property can be overridden. 
            </li>
            </ul>
          </li>
          <li>
            <div>
              <strong>MSBuildProjectDirectoryNoRoot </strong>
            </div>
            <ul>
              <li>
               Same as MSBuildProjectDirectory but without the root listed in front. 
            </li>
            </ul>
          </li>
          <li>
            <div>
              <strong>MSBuildToolsPath </strong>
            </div>
            <ul>
              <li>
               Directory for the framework that is used to build the project. 
            </li>
            </ul>
          </li>
          <li>
            <div>
              <strong>MSBuildToolsVersion </strong>
            </div>
            <ul>
              <li>
               Tools version for the current build. 
            </li>
            </ul>
          </li>
          <li>
            <div>MSBuildBinPath 
         </div>
            <ul>
              <li>
               The absolute path of the directory where the MSBuild binaries that are currently being
               used are located, for example, C:\Windows\Microsoft.Net\Framework\v2.0. This property
               is useful if you need to refer to files in the MSBuild directory. 
            </li>
            </ul>
          </li>
          <li>
            <div>MSBuildExtensionsPath 
         </div>
            <ul>
              <li>
               The MSBuild folder under the Program Files directory. This location is a useful place
               to put custom target files. For example, your targets files could be installed at
               \Program Files\MSBuild\MyFiles\Northwind.targets and then imported in project files
               with the following XML. 
               <br />
               &lt;Import Project="$(MSBuildExtensionsPath)\MyFiles\Northwind.targets"/&gt;<br />
               This property can be overridden. 
            </li>
            </ul>
          </li>
          <li>
            <div>MSBuildProjectDefaultTargets 
         </div>
            <ul>
              <li>
               The complete list of targets specified in the DefaultTargets attribute of the Project
               element. For example, the following Project element would have an MSBuildDefaultTargets
               property value of A;B;C. 
               <br />
               &lt;Project DefaultTargets="A;B;C" &gt; 
            </li>
            </ul>
          </li>
          <li>
            <div>MSBuildProjectDirectory 
         </div>
            <ul>
              <li>
               The absolute path of the directory where the project file is located, for example,
               C:\MyCompany\MyProduct. 
            </li>
            </ul>
          </li>
          <li>
            <div>MSBuildProjectExtension 
         </div>
            <ul>
              <li>
               The file name extension of the project file, including the period, for example, .proj. 
            </li>
            </ul>
          </li>
          <li>
            <div>MSBuildProjectFile 
         </div>
            <ul>
              <li>
               The complete file name of the project file, including the file name extension, for
               example, MyApp.proj. 
            </li>
            </ul>
          </li>
          <li>
            <div>MSBuildProjectFullPath 
         </div>
            <ul>
              <li>
               The absolute path and complete file name of the project file, for example, C:\MyCompany\MyProduct\MyApp.proj. 
            </li>
            </ul>
          </li>
          <li>
            <div>MSBuildProjectName 
         </div>
            <ul>
              <li>
               The file name of the project file without the file name extension, for example, MyApp. 
            </li>
            </ul>
          </li>
          <li>
            <div>MSBuildStartupDirectory 
         </div>
            <ul>
              <li>
               The absolute path of the directory where MSBuild is invoked. 
            </li>
            </ul>
          </li>
        </ul>
        <p>
        </p>
        <p>
      Take a look at this project file that prints out these values. 
   </p>
        <p style="background: #d9d9d9">
      &lt;Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" 
      <br />
      DefaultTargets="PrintProperties" 
      <br />
      ToolsVersion="3.5"&gt; 
   </p>
        <p style="background: #d9d9d9">
      &lt;Target Name="PrintProperties"&gt;<br />
      &lt;Message Text="MSBuildNodeCount: $(MSBuildNodeCount)"/&gt;<br />
      &lt;Message Text="MSBuildExtensionsPath32: $(MSBuildExtensionsPath32)"/&gt;<br />
      &lt;Message Text="MSBuildProjectDirectoryNoRoot: $(MSBuildProjectDirectoryNoRoot)"/&gt;<br />
      &lt;Message Text="MSBuildToolsPath: $(MSBuildToolsPath)"/&gt;<br />
      &lt;Message Text="MSBuildToolsVersion: $(MSBuildToolsVersion)"/&gt;<br />
      &lt;Message Text="MSBuildBinPath: $(MSBuildBinPath)"/&gt;<br />
      &lt;Message Text="MSBuildExtensionsPath: $(MSBuildExtensionsPath)"/&gt;<br />
      &lt;Message Text="MSBuildProjectDefaultTargets: $(MSBuildProjectDefaultTargets)"/&gt;<br />
      &lt;Message Text="MSBuildProjectDirectory: $(MSBuildProjectDirectory)"/&gt; 
      <br />
      &lt;Message Text="MSBuildProjectExtension: $(MSBuildProjectExtension)"/&gt;<br />
      &lt;Message Text="MSBuildProjectFile: $(MSBuildProjectFile)"/&gt;<br />
      &lt;Message Text="MSBuildProjectFullPath: $(MSBuildProjectFullPath)"/&gt;<br />
      &lt;Message Text="MSBuildProjectName: $(MSBuildProjectName)"/&gt;<br />
      &lt;Message Text="MSBuildStartupDirectory: $(MSBuildStartupDirectory)"/&gt; 
   </p>
        <p style="background: #d9d9d9">
      &lt;/Target&gt;<br />
      &lt;/Project&gt; 
   </p>
        <p>
      If you execute this you will get something like what's shown here. 
   </p>
        <p>
          <img src="http://www.sedodream.com/content/binary/060908_0552_MSBuildRese1.png" alt="" />
        </p>
        <p>
        </p>
        <p>
      I'm not sure how important this, but you may need to know one day. 
   </p>
        <p>
          <a href="http://www.sedodream.com/content/binary/ReservedProperties.proj.txt">ReservedProperties.proj</a>
        </p>
        <p>
      Sayed Ibrahim Hashimi
   </p>
        <img width="0" height="0" src="http://www.sedodream.com/aggbug.ashx?id=7e11f92e-e778-4e69-9441-9a6be3512e71" />
      </div>
    </content>
  </entry>
  <entry>
    <title>DataContract XML Helper</title>
    <link rel="alternate" type="text/html" href="http://www.sedodream.com/PermaLink,guid,0a779774-4405-44e4-98a1-af91c1ad8269.aspx" />
    <id>http://www.sedodream.com/PermaLink,guid,0a779774-4405-44e4-98a1-af91c1ad8269.aspx</id>
    <published>2008-06-03T22:54:58.2950000-07:00</published>
    <updated>2008-06-03T23:11:12.9449777-07:00</updated>
    <category term="DataContractSerializer" label="DataContractSerializer" scheme="dasBlog" />
    <category term="WCF" label="WCF" scheme="dasBlog" />
    <content type="html">&lt;p&gt;
   Lately I've been doing some work with WCF and I have had a need to easily convert
   from object-&amp;gt;XML and from XML-&amp;gt;object. These XML strings were created using
   the &lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx"&gt;DataContractSerializer&lt;/a&gt;.
   So I threw together this util class [yeah I know I probably shouldn't have these,
   but you know you do too &lt;span style="FONT-FAMILY: Wingdings"&gt;J&lt;/span&gt; ]. There are
   really 2 methods &lt;em&gt;GetDataContractXml&lt;/em&gt; and &lt;em&gt;BuildFromDataContractXml&lt;/em&gt;.
   The &lt;em&gt;GetDataContractXml&lt;/em&gt; returns the XML for the object provided and the &lt;em&gt;BuildFromDataContractXml&lt;/em&gt; method
   will create the object from the XML string. These methods have both a generic and
   non-generic method. The non-generic versions are particularly useful if you are using
   this with reflection. Anywayz, the class itself is shown below, and you can download
   the file at the bottom of this post. 
&lt;/p&gt;
&lt;pre&gt;///
/// © Copyright Sayed Ibrahim Hashimi
/// www.sedodream.com
///
using System;
using System.IO;
using System.Xml;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
using System.Xml.Serialization;
namespace Sedodream.Sample.Serialization01.Util
{
    public static class XmlUtils
    {
        /// 
&lt;SUMMARY&gt;
   /// Builds an object of the specified type from the given /// XML representation that
   can be passed to the DataContractSerializer /// 
&lt;/SUMMARY&gt;
public static object BuildFromDataContractXml(string xml, Type type) { if (string.IsNullOrEmpty(xml))
{throw new ArgumentNullException("xml"); } if (type == null) { throw new ArgumentNullException("type");
} object result = null; DataContractSerializer dcs = new DataContractSerializer(type);
using (StringReader reader = new StringReader(xml)) using (XmlReader xmlReader = new
XmlTextReader(reader)) { result = dcs.ReadObject(xmlReader); } return result; } /// 
&lt;SUMMARY&gt;
   /// Builds an object from its XML /// representation that can be passed to the DataContractSerializer.
   /// 
&lt;/SUMMARY&gt;
public static T BuildFromDataContractXml&lt;T&gt;
   (string xml) { if (string.IsNullOrEmpty(xml)) { throw new ArgumentNullException("xml");
   } T result = default(T); object objResult = BuildFromDataContractXml(xml, typeof(T));
   if (objResult != null) { result = (T)objResult; } return result; } /// 
   &lt;SUMMARY&gt;
      /// Gets the XML representation of the given object /// by using the DataContracSerializer.
      /// 
   &lt;/SUMMARY&gt;
   public static string GetDataContractXml&lt;T&gt;
      (T obj) { if (obj == null) { throw new ArgumentNullException("obj"); } return GetDataContractXml(obj.GetType(),
      obj); } /// 
      &lt;SUMMARY&gt;
         /// Gets the XML representation of the given object /// of specfiied 
         &lt;C&gt;
            type
         &lt;/C&gt;
         by using the DataContracSerializer. /// 
      &lt;/SUMMARY&gt;
      public static string GetDataContractXml(Type type, object val) { if (type == null)
      { throw new ArgumentNullException("type"); } if (val == null) { throw new ArgumentNullException("val");
      } MemoryStream ms = new MemoryStream(); string xml = null; try { DataContractSerializer
      dcs = new DataContractSerializer(type); using (XmlTextWriter xmlTextWriter = new XmlTextWriter(ms,
      System.Text.Encoding.Default)) { xmlTextWriter.Formatting = System.Xml.Formatting.Indented;
      dcs.WriteObject(xmlTextWriter, val); xmlTextWriter.Flush(); ms = (MemoryStream)xmlTextWriter.BaseStream;
      ms.Flush(); xml = UTF8ByteArrayToString(ms.ToArray()); } } finally { if (ms != null)
      { ms.Close(); ms = null; } } return xml; } /// 
      &lt;SUMMARY&gt;
         /// Writes the XML representation from the DataContractSerializer /// into the specified
         filename. If a file at 
         &lt;C&gt;
            filename
         &lt;/C&gt;
         /// already exists then an 
         &lt;C&gt;
            Exception
         &lt;/C&gt;
         will be thrown. /// 
      &lt;/SUMMARY&gt;
      public static void WriteDateContractToFile&lt;T&gt;
         (string filename, T obj) { WriteDateContractToFile(filename, obj.GetType(), obj);
         } /// 
         &lt;SUMMARY&gt;
            /// Writes the XML representation from the DataContractSerializer /// into the specified
            filename. If a file at 
            &lt;C&gt;
               filename
            &lt;/C&gt;
            /// already exists then an 
            &lt;C&gt;
               Exception
            &lt;/C&gt;
            will be thrown. /// 
         &lt;/SUMMARY&gt;
         public static void WriteDateContractToFile(string filename, Type type, object val)
         { if (string.IsNullOrEmpty(filename)) { throw new ArgumentNullException("filename");
         } if (val == null) { throw new ArgumentNullException("val"); } if (File.Exists(filename))
         { throw new ArgumentException("filname"); } //TODO: Stream this into the file instead
         of this!!! File.WriteAllText(filename, GetDataContractXml(type, val)); } private static
         String UTF8ByteArrayToString(Byte[] characters) { UTF8Encoding encoding = new UTF8Encoding();
         string constructedString = encoding.GetString(characters); return (constructedString);
         } private static Byte[] StringToUTF8ByteArray(String pXmlString) { UTF8Encoding encoding
         = new UTF8Encoding(); byte[] byteArray = encoding.GetBytes(pXmlString); return byteArray;
         } } } 
&lt;/pre&gt;
&lt;p&gt;
   To show how this can be used here is a quick sample unit test shown below, this will
   be a part of a later post on a related topic. 
&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 38pt"&gt;
&lt;pre&gt;using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Sedodream.Sample.Serialization01;
using Sedodream.Sample.Serialization01.Util;

namespace unittest.Sedodream.Sample.Serialization01
{
    [TestFixture]
    public class TestXmlUtils
    {
        [Test]
        public void TestCreateXml()
        {
            string name = "Sayed Ibrahim Hashimi";
            string email = "sayed.hashimi@gmail.com";


            Person person = new Person();
            person.Name = name;
            person.Email = email;

            string xml = XmlUtils.GetDataContractXml&lt;PERSON&gt;
   (person); Assert.IsTrue(!string.IsNullOrEmpty(xml)); Assert.IsTrue(xml.Contains(name));
   Assert.IsTrue(xml.Contains(email)); } [Test] public void TestCreateFromXml() { const
   string xml = @"&lt;PERSON xmlns="" http: 04?? 2008 Serialization schemas.sedodream.com XMLSchema-instance?? 2001 www.w3.org xmlns:i=""&gt;
      &lt;EMAIL&gt;
         sayed.hashimi@gmail.com
      &lt;/EMAIL&gt;
      &lt;ID&gt;
         9891668d-8107-4f3e-85a4-79e941453be2
      &lt;/ID&gt;
      &lt;NAME&gt;
         Sayed Ibrahim Hashimi
      &lt;/NAME&gt;
   &lt;/PERSON&gt;
   "; string name = "Sayed Ibrahim Hashimi"; string email = "sayed.hashimi@gmail.com";
   Guid id = new Guid("9891668d-8107-4f3e-85a4-79e941453be2"); Person person = XmlUtils.BuildFromDataContractXml&lt;PERSON&gt;
      (xml); Assert.IsNotNull(person); Assert.AreEqual(name, person.Name); Assert.AreEqual(email,
      person.Email); Assert.AreEqual(id, person.Id); } } } 
&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
   Where the simple Person class is shown here 
&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 38pt"&gt;
&lt;pre&gt;[DataContract(Namespace="http://schemas.sedodream.com/Serialization/2008/04")]
public class Person
{
    #region Constructors
    public Person()
    {
        Id = Guid.NewGuid();
    }
    #endregion

    [DataMember]
    public string Name
    {
        get;
        set;
    }
    [DataMember]
    public string Email
    {
        get;
        set;
    }
    [DataMember]
    public Guid Id
    {
        get;
        set;
    }
}
&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
   From the two simply test you can see how to create the object from the XML string
   and vice versa. As far as I know these work pretty good, if you find any issues please
   let me know and I can update them. At some point I will post some more information
   that is related to this keep an eye for it. 
&lt;/p&gt;
&lt;p&gt;
   &amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
   &lt;a href="http://www.sedodream.com/content/binary/XmlUtils.cs.txt"&gt;XmlUtils.cs&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
   Sayed Ibrahim Hashimi
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.sedodream.com/aggbug.ashx?id=0a779774-4405-44e4-98a1-af91c1ad8269" /&gt;</content>
  </entry>
  <entry>
    <title>MSBuild Output Inferral and CreateProperty.ValueSetByTask</title>
    <link rel="alternate" type="text/html" href="http://www.sedodream.com/PermaLink,guid,2e12b6f3-5aaa-47bc-958e-2cea5c6ff902.aspx" />
    <id>http://www.sedodream.com/PermaLink,guid,2e12b6f3-5aaa-47bc-958e-2cea5c6ff902.aspx</id>
    <published>2008-05-21T22:09:41.4643748-07:00</published>
    <updated>2008-05-21T22:09:41.4643748-07:00</updated>
    <category term="MSBuild" label="MSBuild" scheme="dasBlog" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
      Ok there is this hidden feature of MSBuild its called output inferral. This is used
      when a target is skipped due its Inputs &amp; Outputs (incremental building) but the
      target creates properties and items. Eventhough the inputs and outputs are up to date
      the side effects (properties &amp; items) may change the rest of the build process.
      Because of this output inferral is required. When a target is skipped MSBuild will
      inspect the target for properties &amp; items that were created and create those.
      This will ensure that other targets down the chain will not be affected by the target
      being skipped. In MSBuild 3.5 there is a new property on the <a href="http://msdn.microsoft.com/en-us/library/63ckb9s9.aspx">CreateProperty</a> task,
      this property is ValueSetByTask. The whole purpose of this is to only be used when
      you do not want its value to be inferred. By using this property instead of Value
      you would be guaranteed that the target was actually executed. Let's clear this up
      with an example take a look at the project file shown below. 
   </p>
        <p style="margin-left: 38pt">
          <span style="color:black; font-family:Lucida Sans Typewriter; font-size:7pt">&lt;Project
      xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;<br /><br />
      &lt;!-- 
      <br />
      This target will always be skipped .<br />
      Neither property One or Two exists but One will be inferred<br />
      by MSBuild.<br />
      --&gt;<br />
      &lt;Target Name="SetupValues" 
      <br />
      Inputs="$(MSBuildProjectFullPath)" 
      <br />
      Outputs="$(MSBuildProjectFullPath)"&gt;<br /><br />
      &lt;Message Text="SetuptValues Executed!" Importance="high"/&gt; 
      <br /><br />
      &lt;CreateProperty Value="1111"&gt;<br />
      &lt;Output PropertyName="One" TaskParameter="Value"/&gt;<br />
      &lt;!-- Property One is actually inferred by this statement. --&gt;<br />
      &lt;/CreateProperty&gt;<br />
      &lt;CreateProperty Value="2222"&gt;<br />
      &lt;Output PropertyName="Two" TaskParameter="<span style="background-color:yellow"><strong>ValueSetByTask</strong></span>"/&gt;<br />
      &lt;!-- Using ValueSetByTask we can ensure bypassing any inferring here --&gt;<br />
      &lt;/CreateProperty&gt;<br /><br />
      &lt;PropertyGroup&gt;<br />
      &lt;!-- 3.5 syntax: Property Three is also inferred --&gt;<br />
      &lt;Three&gt;3333&lt;/Three&gt;<br />
      &lt;/PropertyGroup&gt;<br /><br />
      &lt;!-- Items are inferred too! --&gt;<br />
      &lt;ItemGroup&gt;<br />
      &lt;File Include="app.config"/&gt;<br />
      &lt;/ItemGroup&gt;<br />
      &lt;/Target&gt;<br /><br />
      &lt;Target Name="PrintValues" DependsOnTargets="SetupValues"&gt;<br />
      &lt;Message Text="One: $(One)" /&gt;<br />
      &lt;Message Text="Two: $(Two)" /&gt;<br />
      &lt;Message Text="Three: $(Three)"/&gt;<br />
      &lt;Message Text="File: @(File)"/&gt;<br />
      &lt;/Target&gt;<br /><br />
      &lt;/Project&gt; </span>
        </p>
        <p>
      In this file <em>(you can download from link at end)</em> there are two targets, SetupValues
      and PrintValues. PrintValues depends on SetupValues. Because the Inputs and Outputs
      on SetupValues point to the same file the target will <strong>always</strong> be skipped.
      But we declare properties and items so they have to be inferred by the MSBuidl engine
      so that the remainder of the build will not be hosed because of it. If you execute
      the PrintValues target the result would be what you see in the image below. 
   </p>
        <p>
          <img src="http://www.sedodream.com/content/binary/052208_0509_MSBuildOutp1.png" alt="" />
        </p>
        <p>
      As you can see the values for the properties <em>One</em> &amp; <em>Three</em> were
      provided by inference but the value for <em>Two</em> was passed over because it uses
      the <em>ValueSetByTask</em> instead of <em>Value</em>. I would suggest that you continue
      to use the <em>Value</em> property and not the <em>ValueSetByTask</em> unless you
      are trying to detect this exact scenario, which most of the time shouldn't matter
      anywayz. 
   </p>
        <p>
          <a href="http://www.sedodream.com/content/binary/OutputInferral.proj.txt">OutputInferral.proj</a>
        </p>
        <p>
          <br />
      Sayed Ibrahim Hashimi
   </p>
        <img width="0" height="0" src="http://www.sedodream.com/aggbug.ashx?id=2e12b6f3-5aaa-47bc-958e-2cea5c6ff902" />
      </div>
    </content>
  </entry>
  <entry>
    <title>MSBuild: Building the same project multiple times</title>
    <link rel="alternate" type="text/html" href="http://www.sedodream.com/PermaLink,guid,9b1d23aa-6cb2-48cb-a47a-9cef29622676.aspx" />
    <id>http://www.sedodream.com/PermaLink,guid,9b1d23aa-6cb2-48cb-a47a-9cef29622676.aspx</id>
    <published>2008-05-07T16:52:14.1503744-07:00</published>
    <updated>2008-05-07T16:52:14.1347494-07:00</updated>
    <category term="MSBuild" label="MSBuild" scheme="dasBlog" />
    <category term="Visual Studio" label="Visual Studio" scheme="dasBlog" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
      After some discussion at the <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3303182&amp;SiteID=1">MSBuild
      MSDN Forum</a> I started investigating building the same project with different Compiler
      constants defined. I was actually pretty surprised by what I found. I created a simple
      Windows Form Application with a lone button one it. The image below show the simple
      app. 
   </p>
        <p>
          <img src="http://www.sedodream.com/content/binary/050708_2358_MSBuildBuil1.png" alt="" />
        </p>
        <p>
      Here is the entire code behind file. 
   </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt">using System; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt">using System.Collections.Generic; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt">using System.ComponentModel; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt">using System.Data; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt">using System.Drawing; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt">using System.Linq; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt">using System.Text; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt">using System.Windows.Forms; </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt">namespace WindowsFormsApplication1 </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt">{ </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> public partial class Form1 : Form </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> { </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> public Form1() </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> { </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> InitializeComponent(); </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> } </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> private void buttonExample_Click(object
      sender, EventArgs e) </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> { </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> string message = "default message"; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt">
            <span style="background-color:yellow">#if
      CONSTANT_ONE</span>
          </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> message = "CONSTANT_ONE"; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt">#endif </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt">
            <span style="background-color:yellow">#if
      CONSTANT_TWO</span>
          </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> message = "CONSTANT_TWO"; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt">#endif </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> MessageBox.Show(message); </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> } </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> } </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt">} </span>
        </p>
        <p>
      Ddd 
   </p>
        <p>
      The parts to take note are the regions highlighted in <span style="background-color:yellow">yellow</span>.
      So if the constant <em>CONSTANT_ONE</em> is defined the message results to CONSTANT_ONE
      and if CONSTANT_TWO is defined it will show the message <em>CONSTANT_TWO</em>. 
   </p>
        <p>
      I then created the simple build file. 
   </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt">&lt;?xml version="1.0" encoding="utf-8"?&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt">&lt;Project DefaultTargets="BuildAll"
      ToolsVersion="3.5" </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt; </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;PropertyGroup&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;ConstOne&gt;CONSTANT_ONE&lt;/ConstOne&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;ConstTwo&gt;CONSTANT_TWO&lt;/ConstTwo&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;/PropertyGroup&gt; </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;ItemGroup&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;Projects Include="$(MSBuildProjectDirectory)\..\WindowsFormsApplication1\WindowsFormsApplication1.csproj"&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;/Projects&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;/ItemGroup&gt; </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;!-- </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> Cleans the project before we start
      the build process. </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> The only reason I am calling this
      is to remove artifacts of </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> previous builds, to clearly demonstrate
      what's going on. </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> --&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;Target Name="CleanAll"&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;MSBuild Projects="@(Projects)"
      Targets="Clean" /&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;/Target&gt; </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;Target Name="BuildAll" DependsOnTargets="CleanAll;BuildConstOne;BuildConstTwo"
      /&gt; </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;Target Name="BuildConstOne"&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;MSBuild Projects="@(Projects)" </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> Properties="DefineConstants=$(ConstOne);OutputPath=binOne\;"/&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;/Target&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;Target Name="BuildConstTwo"&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;MSBuild Projects="@(Projects)" </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> Properties="DefineConstants=$(ConstTwo);OutputPath=binTwo\;" </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> /&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;/Target&gt; </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;!-- =========================================================================== </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> This region rebuilds the projects,
      so after it is built once it is then cleaned </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> before building it again. </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> This produces the assemblies with
      the desired behavior </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> ================================================================================--&gt; </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;Target Name="ReBuildAll" DependsOnTargets="CleanAll;ReBuildConstOne;ReBuildConstTwo"
      /&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;Target Name="ReBuildConstOne"&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;MSBuild Projects="@(Projects)"
      Targets="Rebuild" </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> Properties="DefineConstants=$(ConstOne);OutputPath=binOne\;"/&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;/Target&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;Target Name="ReBuildConstTwo"&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;MSBuild Projects="@(Projects)"
      Targets="Rebuild" </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> Properties="DefineConstants=$(ConstTwo);OutputPath=binTwo\;"/&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;/Target&gt; </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;!--========================================================================== </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> This region calls the default
      target (Build) but also specifies the </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> BaseIntermediateOutputPath so
      it works as well because the projects </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> are building to different locations
      on disk. </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> ==============================================================================--&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;Target Name="BuildAllBetter"
      DependsOnTargets="CleanAll;BuildConstOneBetter;BuildConstTwoBetter" /&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;Target Name="BuildConstOneBetter"&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;MSBuild Projects="@(Projects)" </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> Properties="DefineConstants=$(ConstOne);OutputPath=binOne\BaseIntermediateOutputPath=objOne\"/&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;/Target&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;Target Name="BuildConstTwoBetter"&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;MSBuild Projects="@(Projects)" </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> Properties="DefineConstants=$(ConstTwo);OutputPath=binTwo\;BaseIntermediateOutputPath=objTwo\;" </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> /&gt; </span>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt"> &lt;/Target&gt; </span>
        </p>
        <p>
        </p>
        <p>
          <span style="font-family:Consolas; font-size:10pt">&lt;/Project&gt; </span>
        </p>
        <p>
      Ddddd 
   </p>
        <p>
      Let's take a look at what's going on here. The <em>BuildConstOne</em> target passes
      the <em>CONSTANT_ONE</em> value as a property when invoking the <a href="http://msdn.microsoft.com/en-us/library/7z253716.aspx">MSBuild</a> task,
      and builds to the <em>binOne</em> folder. The <em>BuildConstTwo</em> target passes
      the <em>CONSTANT_TWO</em> value and builds to <em>binTwo</em>. If you execute the
      target <em>BuildAll</em>, you would expect that the exe in <em>binOne</em> would show
      the message <em>CONSTANT_ONE</em> and the exe in the <em>binTwo</em> folder has CONSTANT_TWO
      message showing. What you actually get is that both actually show <em>CONSTANT_ONE</em>.
      This is because MSBuild doesn't entirely rebuild the project when building it for
      the second time in BuildConstTwo. The real reason behind this would be because both
      projects are building to the same <em>BaseIntermediateOutputPath</em>, obj\. There
      are two ways to of getting around this, one is to call Rebuild instead of <em>Build</em>,
      and the other is to specify the <em>BaseIntermediateOutputPath</em> as well. In the
      above I have demonstrated both approaches. The ReBuildAll calls Rebuild, and the BuildAllBetter
      specifies the <em>BaseIntermediateOutputPath</em> as well as OutputPath. 
   </p>
        <p>
      Questions?! 
   </p>
        <p>
      You can download all the files at: 
   </p>
        <p>
          <a href="http://www.sedodream.com/content/binary/DefineConst.zip">DefineConst.zip</a>
        </p>
        <p>
      Sayed Ibrahim Hashimi 
   </p>
        <img width="0" height="0" src="http://www.sedodream.com/aggbug.ashx?id=9b1d23aa-6cb2-48cb-a47a-9cef29622676" />
      </div>
    </content>
  </entry>
  <entry>
    <title>How to debug MSBuild tasks</title>
    <link rel="alternate" type="text/html" href="http://www.sedodream.com/PermaLink,guid,29c564ee-05ed-47e3-b2bb-fe6b05b623c6.aspx" />
    <id>http://www.sedodream.com/PermaLink,guid,29c564ee-05ed-47e3-b2bb-fe6b05b623c6.aspx</id>
    <published>2008-04-28T22:10:03.6350000-07:00</published>
    <updated>2008-04-28T22:13:08.4476250-07:00</updated>
    <category term="MSBuild" label="MSBuild" scheme="dasBlog" />
    <category term="Visual Studio" label="Visual Studio" scheme="dasBlog" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
      A question that comes up pretty frequently is <em>"How can I debug an MSBuild task"</em>?
      It's actually pretty simple. In this post I will describe how to easily an effectively
      debug MSBuild tasks that you are creating. In this example I will be demonstrating
      a task from my open source tasks at <a href="http://www.codeplex.com/Sedodream">www.codeplex.com/Sedodream</a>.
      The task is one that was contributed by <a href="http://ozgrant.com/2008/04/04/createguid-msbuild-task/">Grant
      Holliday</a>. 
   </p>
        <p>
      First in the project where your tasks are contained create a folder that will be used
      to contain sample MSBuid files that can be used to debug the tasks. This is also a
      good idea, because it will show people how to use your tasks. If you are don't want
      to mix samples &amp; code in the same project then just make sure in your build you
      copy the files to the correct locations. In the sample project, which you can download
      at the bottom, the folder is named <strong>Samples</strong>. When you add MSBuild
      files to the folder make sure you set the file to be copied to the output folder as
      well. See the image below. 
   </p>
        <p>
          <img src="http://www.sedodream.com/content/binary/042908_0515_HowtodebugM1.png" alt="" />
        </p>
        <p>
      By setting this, the file will be copied to the output folder when the project is
      built. Since it will be in the output folder we can use a relative path to get to
      the assembly that contains the task. Take a look at the sample MSBuild file for this
      task. 
   </p>
        <p>
          <span style="color: rgb(0, 176, 80);">&lt;?xml version="1.0" encoding="utf-8"?&gt; </span>
        </p>
        <p>
          <span style="color: rgb(0, 176, 80);">&lt;Project ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt; </span>
        </p>
        <p>
          <span style="color: rgb(0, 176, 80);">   &lt;PropertyGroup&gt; </span>
        </p>
        <p>
          <span style="color: rgb(0, 176, 80);">    <span style="background-color: yellow;">&lt;TaskLocation
      Condition="$(TaskLocation)==''"&gt;$(MSBuildProjectDirectory)\..\DebugTask.dll&lt;/TaskLocation&gt;</span></span>
        </p>
        <p>
          <span style="color: rgb(0, 176, 80);">  &lt;/PropertyGroup&gt; </span>
        </p>
        <p>
          <span style="color: rgb(0, 176, 80);">   &lt;UsingTask TaskName="CreateGuid"
      AssemblyFile="$(TaskLocation)"/&gt; </span>
        </p>
        <p>
       
   </p>
        <p>
          <span style="color: rgb(0, 176, 80);">  &lt;Target Name="Example"&gt; </span>
        </p>
        <p>
          <span style="color: rgb(0, 176, 80);">    &lt;Message Text="Starting example"
      /&gt; </span>
        </p>
        <p>
          <span style="color: rgb(0, 176, 80);">    &lt;CreateGuid&gt; </span>
        </p>
        <p>
          <span style="color: rgb(0, 176, 80);">        &lt;Output
      PropertyName="Guid" TaskParameter="Output"/&gt; </span>
        </p>
        <p>
          <span style="color: rgb(0, 176, 80);">      &lt;/CreateGuid&gt; </span>
        </p>
        <p>
          <span style="color: rgb(0, 176, 80);">    &lt;Message Text="Guid: $(Guid)"
      /&gt; </span>
        </p>
        <p>
          <span style="color: rgb(0, 176, 80);">   &lt;/Target&gt; </span>
        </p>
        <p>
          <span style="color: rgb(0, 176, 80);">&lt;/Project&gt; </span>
        </p>
        <p>
       
   </p>
        <p>
      The line highlighted contains the path to the assembly that contains the task. This
      path is relative to the location in the output folder, not the source folder. Also
      another thing to take note, is that we only write to the <span style="color: rgb(0, 176, 80);"><em>TaskLocation</em></span> property
      if it is empty. This is useful because you can overwrite the location through command
      line parameters if necessary. But this shouldn't be needed for what we are trying
      to accomplish here. 
   </p>
        <p>
      After you create the sample, build the solution. And open a command prompt to verify
      that it works. Here is a sample of the result of this project file. 
   </p>
        <p>
          <img src="http://www.sedodream.com/content/binary/042908_0515_HowtodebugM2.png" alt="" />
        </p>
        <p>
      Once you've verified that that MSBuild file works then you can right click on the
      project that contains your task, and select properties. From there go to the debug
      tab. What we want to do is start the msbuild.exe executable on that sample project
      file. To do this fill in the full path to it in the Start External program text box,
      i.e. '<em>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe</em>'. In the command
      line arguments you should pass the name of the project file followed by any msbuild
      parameters. Typically I will attach a file logger to the process. Finally you should
      set the working directory to the folder containing the sample. The result should look
      something like the image shown below. 
   </p>
        <p>
          <img src="http://www.sedodream.com/content/binary/042908_0515_HowtodebugM3.png" alt="" />
        </p>
        <p>
      Following this set a break point in your task, set the project as the startup project
      and hit F5! Another thing to take note of is that these properties are stored in the <em>.user</em> file
      so it shouldn't affect any other developers on your team. 
   </p>
        <p>
      Below is the link containing a simple solution that was used here. 
   </p>
        <p>
       
   </p>
        <p>
          <a href="http://www.sedodream.com/content/binary/DebugTask.zip">DebugTask.zip</a>
        </p>
        <p>
      Sayed Ibrahim Hashimi
   </p>
        <img width="0" height="0" src="http://www.sedodream.com/aggbug.ashx?id=29c564ee-05ed-47e3-b2bb-fe6b05b623c6" />
      </div>
    </content>
  </entry>
  <entry>
    <title>MSBuild + JSLint = Good Javascript</title>
    <link rel="alternate" type="text/html" href="http://www.sedodream.com/PermaLink,guid,8e4c1e41-393b-402b-8251-10f3f59a54e2.aspx" />
    <id>http://www.sedodream.com/PermaLink,guid,8e4c1e41-393b-402b-8251-10f3f59a54e2.aspx</id>
    <published>2008-04-14T22:25:01.7500000-07:00</published>
    <updated>2008-04-17T10:23:47.7656250-07:00</updated>
    <category term="MSBuild" label="MSBuild" scheme="dasBlog" />
    <category term="Visual Studio" label="Visual Studio" scheme="dasBlog" />
    <category term="Javascript" label="Javascript" scheme="dasBlog" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
      Recently I was introduced to a tool that was to a tool that would analyze Javascript
      for syntactical errors as well as usage of bad practices. This tool is <a href="http://www.jslint.com">JSLint</a>. <a href="http://www.crockford.com/">Douglas
      Crockford</a> from <a href="http://www.yahoo.com">Yahoo!</a> created, and maintains, <a href="http://www.jslint.com">JSLint</a>.
      If you haven't heard of him, he is a well known Javascript expert. 
   </p>
        <p>
      Now how can we verify our Javascript with JSLint &amp; MSBuild? In my open source
      project <a href="http://www.codeplex.com/sedodream">Sedodream MSBuild</a> I have created
      a new JSLint task. You can get the installer by going to <a href="http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=Sedodream&amp;ReleaseId=12530">http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=Sedodream&amp;ReleaseId=12530</a>.
      After you install the msi you can follow these steps to invoke the JSLint on your
      projects. 
   </p>
        <p>
      Edit your web project file and include the following snippet before the &lt;/Project&gt;
      tag. 
   </p>
        <p>
          <span style="font-family: Courier New; font-size: 10pt;">
            <span style="color: blue;"> &lt;</span>
            <span style="color: rgb(163, 21, 21);">Import</span>
            <span style="color: blue;">
            </span>
            <span style="color: red;">Project</span>
            <span style="color: blue;">=</span>"<span style="color: blue;">$(MSBuildExtensionsPath)\Sedodream\Sedodream.tasks</span>"<span style="color: blue;">/&gt; </span></span>
        </p>
        <p>
          <span style="font-family: Courier New; font-size: 10pt;">
            <span style="color: blue;"> &lt;</span>
            <span style="color: rgb(163, 21, 21);">Import</span>
            <span style="color: blue;">
            </span>
            <span style="color: red;">Project</span>
            <span style="color: blue;">=</span>"<span style="color: blue;">$(MSBuildExtensionsPath)\Sedodream\JSLint.targets</span>"<span style="color: blue;">/&gt; </span></span>
        </p>
        <p>
       
   </p>
        <p>
          <span style="font-family: Courier New; font-size: 10pt;">
            <span style="color: blue;"> &lt;</span>
            <span style="color: rgb(163, 21, 21);">PropertyGroup</span>
            <span style="color: blue;">&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family: Courier New; font-size: 10pt;">
            <span style="color: blue;"> &lt;</span>
            <span style="color: rgb(163, 21, 21);">BuildDependsOn</span>
            <span style="color: blue;">&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family: Courier New; font-size: 10pt;"> $(BuildDependsOn); </span>
        </p>
        <p>
          <span style="font-family: Courier New; font-size: 10pt;"> RunJSLint; </span>
        </p>
        <p>
          <span style="font-family: Courier New; font-size: 10pt;">
            <span style="color: blue;"> &lt;/</span>
            <span style="color: rgb(163, 21, 21);">BuildDependsOn</span>
            <span style="color: blue;">&gt; </span>
          </span>
        </p>
        <p>
          <span style="font-family: Courier New; font-size: 10pt;">
            <span style="color: blue;"> &lt;/</span>
            <span style="color: rgb(163, 21, 21);">PropertyGroup</span>
            <span style="color: blue;">&gt; </span>
          </span>
        </p>
        <p>
       
   </p>
        <p>
      The first line includes makes the tasks from my project available, and the second
      line includes the file that knows how to execute the JSLint tool. Following that I
      extend the build process to execute the <em>RunJSLint</em> target. If you are not
      familiar with this take a look at my article <a href="http://msdn2.microsoft.com/en-us/magazine/cc163589.aspx">Inside
      MSBuild</a>. 
   </p>
        <p>
      After you do this you may be prompted with a security warning from Visual Studio,
      you should pick 'Load Project Normally'. You can read more about how to disable it
      at <a href="http://msdn2.microsoft.com/en-us/library/ms228217.aspx">http://msdn2.microsoft.com/en-us/library/ms228217.aspx</a>.
      I chose to not have my installer set that registry flag. For the time being I think
      that users should make that decision themselves, although I would like to think I'm
      trustworthy <span style="font-family: Wingdings;">J</span></p>
        <p>
      After you do this and allow Visual Studio to load the project normally, if your create
      Javascript files that have errors, or JSLint doesn't like you will be warned in the
      error list as shown below. 
   </p>
        <p>
          <img src="http://www.sedodream.com/content/binary/041508_0531_MSBuildJSLi1.png" alt="" />
        </p>
        <p>
       
   </p>
        <p>
      With that being said keep in mind this is a<strong> V1</strong> deal, so this may
      not work perfect. I am working to make sure that it works well, but it was kinda tricky
      to get this to work period! 
   </p>
        <p>
      As always I welcome your feedback and I will post more info about this later. Oh yeah
      by default from <a href="http://www.jslint.com">JSLint</a> the GoodParts are enforced
      keep an eye on this blog, or send me a message, to see how to change that. 
   </p>
        <p>
      Sayed Ibrahim Hashimi
   </p>
        <img width="0" height="0" src="http://www.sedodream.com/aggbug.ashx?id=8e4c1e41-393b-402b-8251-10f3f59a54e2" />
      </div>
    </content>
  </entry>
  <entry>
    <title>MSBuild Batching Part 3</title>
    <link rel="alternate" type="text/html" href="http://www.sedodream.com/PermaLink,guid,cab57d7f-9d6e-4358-8491-dc033fb3bacc.aspx" />
    <id>http://www.sedodream.com/PermaLink,guid,cab57d7f-9d6e-4358-8491-dc033fb3bacc.aspx</id>
    <published>2008-03-28T13:04:53.8750000-07:00</published>
    <updated>2008-03-28T13:04:53.8593750-07:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
      This post is to supplement the two previous posts that I have focused on batching
      those are located at: 
   </p>
        <ul>
          <li>
            <a href="http://www.sedodream.com/PermaLink,guid,5f1e0445-ce3d-4052-ba80-42fd19512d42.aspx">MSBuild
         Batching Part 1</a>
          </li>
          <li>
            <a href="http://www.sedodream.com/PermaLink,guid,b721bc22-c375-4e1e-bcc9-512dd64096bb.aspx">MSBuild
         Batching Part 2</a>
          </li>
        </ul>
        <p>
      Batching continues to be confusing and I hope that that post will help to further
      clarify it a little bit. In the two previous posts I think that I was <em>"hiding"</em> what
      was really happening by using built in metadata. This time I will expose what's happening
      by a simple example that only uses custom metadata. The first thing to know about
      batching, it <strong>always</strong> occurs over metadata, either <a href="http://msdn2.microsoft.com/en-us/library/ms164313.aspx">Well
      Known</a> or custom. Take a look at the project file shown below, Batching03.proj. 
   </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt">&lt;!— </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> © Copyright 2008,
      Sayed Ibrahim Hashimi (sayed.hashimi@gmail.com) </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt">--&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt">&lt;Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;ItemGroup&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Server Include="Server1"&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Type&gt;2008&lt;/Type&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Name&gt;SVR01&lt;/Name&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;/Server&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Server Include="Server2"&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Type&gt;2003&lt;/Type&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Name&gt;SVR02&lt;/Name&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;/Server&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Server Include="Server3"&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Type&gt;2008&lt;/Type&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Name&gt;SVR03&lt;/Name&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;/Server&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Server Include="Server4"&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Type&gt;2003&lt;/Type&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Name&gt;SVR04&lt;/Name&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;/Server&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;/ItemGroup&gt; </span>
        </p>
        <p>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Target Name="TaskBatching"&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Message Text="%40(Server-&gt;'%(Name)'):
      @(Server-&gt;'%(Name)')" /&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Message Text="==========================================="
      /&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;!-- </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> Task Batching
      Here over the Name metadata. </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> Notice that Message
      task is invoked once per unique batch </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> --&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Message Text="%25(Server.Name):
      %(Server.Name)" /&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Message Text="==========================================="
      /&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Message Text="%25(Server.Type):
      %(Server.Type)" /&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Message Text="==========================================="
      /&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;/Target&gt; </span>
        </p>
        <p>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Target Name="TargetBatching01"
      Outputs="%(Server.Name)"&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Message Text="=====
      TargetBatching01 ============" /&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Message Text="%25(Server.Name):
      %(Server.Name)" /&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Message Text="%25(Server.Type):
      %(Server.Type)" /&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Message Text="Server:
      @(Server)" /&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Message Text="==================================="/&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;/Target&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Target Name="TargetBatching02"
      Outputs="%(Server.Type)"&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Message Text="=====
      TargetBatching01 ============" /&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Message Text="%25(Server.Name):
      %(Server.Name)" /&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Message Text="%25(Server.Type):
      %(Server.Type)" /&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Message Text="Server:
      @(Server)" /&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Message Text="==================================="/&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;/Target&gt; </span>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt"> &lt;Target Name="All"
      DependsOnTargets="TaskBatching;TargetBatching01;TargetBatching02"/&gt; </span>
        </p>
        <p>
          <span style="color:#339933; font-family:Courier New; font-size:9pt">&lt;/Project&gt; </span>
        </p>
        <p>
      There are three targets that are important <span style="color:#339933">TaskBatching</span>,
      which demonstrates how you can invoke individual tasks once per batch and then two
      targets; <span style="color:#339933">TargetBatching01</span> &amp; <span style="color:#339933">TargetBatching02</span>,
      which demonstrate batching an entire target once per batch. When you want to proform
      batching you will <strong>always</strong> use the %(…) notation somewhere. In Task
      batching this will be notated only inside of the tasks' parameters. In target batching
      this notation will be declared in the targets <em>Outputs</em> attribute. 
   </p>
        <p>
      Zooming in on <span style="color:#339933">TaskBatching</span> target here are the
      results and we will discuss 
   </p>
        <p>
          <img src="http://www.sedodream.com/content/binary/032808_2005_MSBuildBatc1.png" alt="" />
        </p>
        <p>
      The comments on the image pretty much describe what's happening. In the first execution
      there we are <strong>not</strong> batching. So the item is transformed into a string
      and passed into the Message task. The transformation is described by what is contained
      in the <strong>-&gt;()</strong>. So the Metadata <span style="color:#339933"><em>Name</em></span> for
      each element in Server is evaluated and a string is created from that by concatenating
      each of these values. If there were duplicate values then the duplicates would show
      up in the resulting string. 
   </p>
        <p>
      Moving on to the next one, we batch on the Name Metadata. Since there were 4 Name
      metadata values the Message task is invoked 4 distinct times. The same applies for
      the Next invocation of the Message task. 
   </p>
        <p>
      Now let's take a look at the Target Batching. I simply invoked these targets, nothing
      special. The <span style="color:#339933"><em>TargetBatching01</em></span> target is
      batching on the <span style="color:#339933"><em>Name</em></span> Metadata, and the <span style="color:#339933"><em>TargetBatching02</em></span> on
      the <span style="color:#339933"><em>Type</em></span> Metadata. The output is shown
      below. 
   </p>
        <p>
          <img src="http://www.sedodream.com/content/binary/032808_2005_MSBuildBatc2.png" alt="" />
        </p>
        <p>
      Because there are 4 distinct Name values TargetBatching is invoked 4 times, and similarily
      TargetBatching twice because of the distinct Type values. So if you just need to perform
      a single task over a set of parameters, the use Task batching. But If you need to
      perform a set of actions on a set of parameters then use Target Batching. More to
      come later on this topic I'm sure. 
   </p>
        <p>
      As a note I have decided to resume work on the MSBuild book I referenced in earlier
      posts. You'll be happy to know that I will cover batching in great detail there. 
   </p>
        <p>
        </p>
        <p>
      Sayed Ibrahim Hashimi 
   </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
      ddd 
   </p>
        <img width="0" height="0" src="http://www.sedodream.com/aggbug.ashx?id=cab57d7f-9d6e-4358-8491-dc033fb3bacc" />
      </div>
    </content>
  </entry>
</feed>