With MSBuild 3.5 two new known metadata names were introduced for items passed to the MSBuild Task. Those known metadata names are Properties and AdditionalProperties. The idea is that you can now specify properties on the item itself instead of having to pass all the properties using the Properties attribute on the MSBuild Task. For example you could define an item, Projects, to be:
Then you can build the values contained in the Projects item using the MSBuild task:
Like I said previously there are two new ways to pass properties in item metadata, Properties and AdditionalProperties. The difference can be confusing and very problematic if used incorrectly. Admittedly I didn't know the difference until about 6 months ago (but soon enough to include in my book
J ). The difference is that if you specify properties using the Properties metadata then any properties defined using the Properties attribute on the MSBuild Task will be ignored. In contrast to that if you use the AdditionalProperties metadata then both values will be used, with a preference going to the AdditionalProperties values.
Now let's take a look at an example to make this clear. The following MSBuild file is named Properties.proj and is shown below.
Text="Building project with Properties metadata"
Text="Building project with AdditionalProperties metadata"
I've highlighted a few important elements contained in this file. Firstly if you do not specify your ToolsVersion to be 3.5 then none of this functionality will work. Make sure to always provide this value, or you may be baffled by the un-expected behavior.
Inside of both targets you can see that I and providing the value Properties="DebugSymbols=true". Below is the definition of the file that it is building, the Project01.proj file.
This file just prints out the values for a couple of properties that are not defined inside the file itself. Now let's see the behavior when we execute both of these targets. The result is shown in the image below.
As I've highlighted here the result of executing the Build_Properties target results in the attribute Properties="DebugSymbols=true" being completely ignored. The result from the Build_AProperties target takes the Properties attribute into consideration as well as the AdditionalProperties metadata. Don't use both of these together!
I personally prefer using the AdditionalProperties because I think that ignoring the Properties attribute can be confusing and hard to diagnose. This is why I tend to use that approach instead of the Properties metadata unless I have a specific reason.
Sayed Ibrahim Hashimi
If you are you using ASP.NET MVC and the Entity Framework then odds are that you will want to use some of your entity object inside of your views. If you've tried this you may have run into the following exception: "CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)".
So the first guess is to add a reference to System.Data.Entity assembly in the MVC project. I did that then ran my app again, and I encountered the same error. After some poking around I figured out that you need to manually add the assembly to the web.config file. So in your web.config file you need to add the element
assembly="System.Data.Entity, Version=22.214.171.124, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
Under the compiliation\assembiles node, here it is:
Once you've done this you should be able to run your app with no problems.
Sayed Ibrahim Hashimi
After my previous entry a reader requested that I post a table of contents for my book Inside the Microsoft Build Engine. After searching I realized that I didn't have one. So I put one together here it is.
Contents at a Glance
Part I Overview
- MSBuild Quick Start
- MSBuild Deep Dive, Part 1
- MSBuild Deep Dive, Part 2
Part II Customizing MSBuild
- Custom Tasks
- Custom Loggers
Part III Advanced MSBuild Topics
- Batching and Incremental Building
- External Tools
Part IV MSBuild Cookbook
- Practical Applications, Part 1
- Practical Applications, Part 2
Part V Team Foundation Build
- Team Build Quick Start
- Team Build Deep Dive
- Team Build Cookbook
- New Features in MSBuild 3.5
- Common Properties and Items
- New Features in Visual Studio Team System 2010 Team Build
Sayed Ibrahim Hashimi
Saturday, April 11, 2009 4:55:18 PM (GMT Daylight Time, UTC+01:00)
Since the release of Inside the Microsoft Build Engine, the book that I wrote along with William Bartholomew, there has been a continuous stream of positive feedback posted. I would like to thank everyone that has taken the time to post reviews of the book. I think it is important that feedback is provided (positive or negative) so that potential readers can more accurately decide whether or not to purchase a particular book. I would like to highlight some of the reviews that I have found here.
Steve St. Jean, who is himself regarded as an MSBuild expert, posted a very thorough review of the book on his blog. I personally have never seen a book review by an independent party with soo much detail. Thanks Steve! Here is some of his comments.
"Wow! This is the book that I wish I had written. Sayed and William have covered the topic's depth and breadth with enough illustrations and code examples to make any developer productive with MSBuild and Team Build. No Experience Required."
"The "Deep Dive – Part 2" builds on the prior chapter to go deeper into Dynamic Properties and Items. One of the best nuggets of the book can be found here. On pages 60 & 61 they show the "MSBuild Order of Evaluation" which is essential to all but the most trivial MSBuild script. Up until this point I knew the basics of the evaluation order but had never been able to find a definitive order. This was the first time I knew that there was much I didn't know but sadly not the last."
"Batching is a process whereby MSBuild looks at an Item list and groups its elements based on some metadata attribute's values."
[Discussing Team Build Content]: "The "Deep Dive" section is truly "deep". It describes the default build process and then shows how you can customize the defaults to bring in your project's specific steps. Need to customize the Clean process? It's in there. Want to package your website into a Zip file? No problem. All the overridable "hook" Targets that Microsoft left in the process are described along with those Targets that you shouldn't touch."
Wes MacDonald who is a Team Systems MVP has these comments.
"This book was fantastic, full of great examples and guides you through customizing MSBuild and Team Build. I was initially surprised to find so many chapters dedicated to MSBuild but afterwards I realized there is just so much you can do with it, there probably could have been more."
Doug Holland who is a Visual C# MVP who works for Intel wrote on his blog:
"I have got to say this book totally rocks and I'll be looking for a second edition once VS2010 RTM is released."
Peter Blomqvist writes a blog post titled "Finally a proper book about MSBuild and Team Build"
"The book is well structured and is down to earth with a lot of practical examples from real world scenarios. I truely wish that I would have had access to this book back in 2005 when I started out with build automation in Team System."
"The book is a must read for anyone considering working with build automation using Team System (atleast until VSTS 2010 comes out and changes it again)."
Mathias Olausson has these comments on his blog.
"The book covers MSBuild and Team Build first with the basics and then with deep-dives that cover topics that are hard to find in one place."
Currently on Amazon.com we have 5 reviews and all 5 are rated 5 stars, and I didn't solicit any of them! Here are snippets from those reviews:
"This is a well written book on the MSBuild system. I was working on an open source project that will generate the MSBuild scripts and wanted to understand it well enough to take maximum advantage of it.
This book is all that I was waiting for, it is worth the price. The explanations are simply and very clear - easy to understand language."
A "must have" for any budding build master
"Even though I have decent experience in MSBuild I read this book from front to back twice over and was exceptionally impressed with how this book was put together."
"There is some fantastic advice and guidance for customizing MSBuilds, batch building and incremental building and there are 3 chapters dedicated to Team Foundation Build which were highly educational for me in not only a gathering a better understanding of the build process in Team Foundation but also a stronger understanding of how to utilize Build Agents, retention policies, triggers, and unit testing within Team Foundation Build."
The Definitive Companion on MSBuild and Team Build 2008
"This book's focus on making sure that MSBuild is explained to the tiniest details is a big win. The explanation and coverage of MSBuild is something you will not find in any other book (or even MSDN)."
"This is the definitive guide on Team Build 2008. I was particularly impressed with the Team Build Cookbook chapter, especially the load balancing discussion of the tool that William wrote"
Best book on the subject, hands down
"This book is outstanding."
"I highly recommend this book to anyone who is both new or experienced with MSBuild or Team Build. Great work!"
The book that everyone who does builds with Visual Studio needs
"I picked up this book because even though I knew how to use MSBuild and TFS Build I did not know all of the nitty gritty pieces of the underlying engine and all of the available options. I know them now."
"Having said that, if you are new to MSBuild then this is a great book. It very quickly introduces you to the basics of MSBuild (which you all use anyway if you use Visual Studio 2005 or greater) and how to quickly customize MSBuild to suit your needs."
Sayed Ibrahim Hashimi
Thursday, April 9, 2009 4:44:55 AM (GMT Daylight Time, UTC+01:00)
Earlier today I was awarded the status of Microsoft MVP! The area that they have put me in is Visual C#, you can see my profile at https://mvp.support.microsoft.com/profile/Sayed.Ibrahim.Hashimi.
I know that a lot of different people have nominated me for this award, and I am very grateful for that. I would especially like to thank Joe Healy. Joe has been pushing the MVP guys to accept me for quite some time. Now that I have received the award I just have to make sure that I keep it!
Sayed Ibrahim Hashimi
Visual C# MVP!
Wednesday, April 1, 2009 9:38:30 PM (GMT Daylight Time, UTC+01:00)