<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;DUUMSHs6eip7ImA9WhBUFUg.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999</id><updated>2013-05-02T22:01:29.512-07:00</updated><category term="Orchard" /><category term="Visual Studio" /><category term="TechThoughts" /><category term="MVC" /><category term="NuGet" /><category term="WebActivator" /><category term="git" /><category term="kudu" /><category term="OData" /><category term="Razor" /><category term="azure" /><category term="EntityFramework" /><category term="DynamicData" /><category term="Mono" /><category term="RazorGenerator" /><category term="ASP.NET" /><category term="T4MVC" /><title>David Ebbo</title><subtitle type="html">ASP.NET, NuGet, and random other things</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://blog.davidebbo.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>34</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/DavidEbbo" /><feedburner:info uri="davidebbo" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;DEQGQX84fSp7ImA9WhBUEU8.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-7830469152458924843</id><published>2013-04-27T22:15:00.001-07:00</published><updated>2013-04-27T22:18:40.135-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-04-27T22:18:40.135-07:00</app:edited><title>Publishing to Azure Web Sites from any git/hg repo</title><content type="html">&lt;p&gt;Windows Azure Web Sites provide a nice selection of ways to deploy a site from source code. You can deploy from:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;a local git repository&lt;/li&gt; &lt;li&gt;a TFS project&lt;/li&gt; &lt;li&gt;a git project on GitHub&lt;/li&gt; &lt;li&gt;a git or Mercurial project on Bitbucket&lt;/li&gt; &lt;li&gt;a git or Mercurial project on CodePlex&lt;/li&gt; &lt;li&gt;code in a Dropbox folder&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;One thing that all these approaches have in common is that you own the code. e.g. in the GitHub case, you must be an admin on the project. The reason is that Azure needs to set up a hook in the project to enable continuous deployment, and only project owners can do that.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;h3&gt;Deploying ‘external’ repositories you don’t own&lt;/h3&gt; &lt;p&gt;In some scenarios, it can be interesting to deploy a site based on sources that you don’t own. For example, you might want to deploy your own instance of the NuGet gallery, but you have no intention to modify the source. You’re happy with it as is, and you just want to deploy it.&lt;/p&gt; &lt;p&gt;To cater to this scenario, we added a new ‘External repository’ entry in the Azure portal:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-gbap_Ku2EMM/UXywfc5g0rI/AAAAAAAAD2I/t_h7zMXC6Ig/s1600-h/image%25255B4%25255D.png"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://lh6.ggpht.com/-dGs0OZM0cQI/UXywfwpKscI/AAAAAAAAD2Q/KVgW9FptfPg/image_thumb%25255B2%25255D.png?imgmax=800" width="637" height="441"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: the ‘External repository’ entry is using the git icon, which is technically incorrect since it supports both git and Mercurial. We just didn’t have time to come up with a better icon for it for this initial release! We’ll probably change that later.&lt;/p&gt; &lt;p&gt;Once you pick that, the next page in the wizard is pretty simple: you just paste any http(s) git or Mercurial URL and you’re good to go!&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-PQVbIqJau1M/UXywgaLKemI/AAAAAAAAD2Y/nhFA7I8Uo64/s1600-h/image%25255B9%25255D.png"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://lh4.ggpht.com/-G8ml__1f2KQ/UXywgqZZj8I/AAAAAAAAD2g/JNAFpX17lVM/image_thumb%25255B5%25255D.png?imgmax=800" width="679" height="449"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;And as soon as you Ok the dialog, a deployment from that repository gets triggered.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;h3&gt;What about updates?&lt;/h3&gt; &lt;p&gt;One important point about this mode is that it doesn’t support continuous deployment. This is because Azure cannot possibly register for change notifications on an arbitrary repo that you don’t own.&lt;/p&gt; &lt;p&gt;Concretely, that means that your site will not be automatically deployed when the repo is updated. Instead, you need to tell it when you want to pick up changes, by clicking the Sync button in the Deployments page:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-dvhggcotHRE/UXywg3PmWQI/AAAAAAAAD2k/j52HXWbdV5I/s1600-h/image%25255B16%25255D.png"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://lh4.ggpht.com/-b7HwYPZQtcs/UXywhZwen3I/AAAAAAAAD2s/wlzQbwI6EKc/image_thumb%25255B8%25255D.png?imgmax=800" width="157" height="58"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;While this feature may not see the same kind of usage as the full continuous deployment workflows, it has its uses and nicely completes the overall source deployment story in Azure Web Sites.&lt;/p&gt;  &lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/cdiPeylc0Sw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/7830469152458924843/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2013/04/publishing-to-azure-web-sites-from-any.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/7830469152458924843?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/7830469152458924843?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/cdiPeylc0Sw/publishing-to-azure-web-sites-from-any.html" title="Publishing to Azure Web Sites from any git/hg repo" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh6.ggpht.com/-dGs0OZM0cQI/UXywfwpKscI/AAAAAAAAD2Q/KVgW9FptfPg/s72-c/image_thumb%25255B2%25255D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://blog.davidebbo.com/2013/04/publishing-to-azure-web-sites-from-any.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEMNQ308cSp7ImA9WhJUFE0.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-2997817182856276191</id><published>2012-09-11T15:17:00.001-07:00</published><updated>2012-09-11T15:28:12.379-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-09-11T15:28:12.379-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="git" /><category scheme="http://www.blogger.com/atom/ns#" term="azure" /><category scheme="http://www.blogger.com/atom/ns#" term="kudu" /><title>Managing database connections in Azure Web Sites</title><content type="html">&lt;p&gt;&lt;em&gt;This topic is not specific to git publishing, but it’s particularly useful in that scenario&lt;/em&gt;&lt;/p&gt; &lt;p&gt;In its first release, the Azure portal had a couple of limitations relating to database connections:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;The database name had to match the connection string, which was quirky&lt;/li&gt; &lt;li&gt;You could not add external connection strings&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;The good news is that both limitations have now been removed, as you’ll see here.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;h3&gt;Using a SQL Azure database associated with the site&lt;/h3&gt; &lt;p&gt;Let’s say you’d like to publish the awesome &lt;a href="https://github.com/NuGet/NuGetGallery"&gt;NuGet Gallery&lt;/a&gt; to an Azure Web Site. When you create the site in Azure, choose the ‘Create with database’ option:&lt;/p&gt; &lt;p&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="image" src="http://lh6.ggpht.com/-XT3zcbwAv1M/UE-4W5vjrFI/AAAAAAAADpM/p3HeYukyzxo/image%25255B37%25255D.png?imgmax=800" width="443" height="198"&gt; &lt;/p&gt; &lt;p&gt;You will see a dialog that looks like this:&lt;/p&gt; &lt;p&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="image" src="http://lh6.ggpht.com/-qiiPv_Zl8ds/UE-4XqaAOZI/AAAAAAAADpQ/lBDDRp-3MH8/image%25255B38%25255D.png?imgmax=800" width="525" height="350"&gt; &lt;/p&gt; &lt;p&gt;Let’s assume that you don’t have a database yet, and you’d like one to be created for you. All you have to do here is give Azure your connection string name (highlighted above).&lt;/p&gt; &lt;p&gt;So where does this ‘NuGetGallery’ string come from? It’s simply the name of the connection string from the app’s &lt;a href="https://github.com/NuGet/NuGetGallery/blob/master/Website/Web.config"&gt;web.config&lt;/a&gt;:&lt;/p&gt; &lt;p&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="image" src="http://lh5.ggpht.com/-0RHPX8Q8dhc/UE-4YsBn35I/AAAAAAAADpU/cCPW1e2EHd0/image%25255B39%25255D.png?imgmax=800" width="708" height="47"&gt; &lt;/p&gt; &lt;p&gt;This way, you don’t need to change your sources to point to the SQL Azure database. You instead rely on Azure to use the right connection string at runtime.&lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;After the following step, you can complete the wizard by either creating a new DB Server or use an existing one. Note that the database itself can be named anything you like (or keep the random name), since it is now decoupled from the connection string name.&lt;/p&gt; &lt;p&gt;At this point, you can just ‘git push azure master’ the NuGet Gallery sources, and your site is up and running with no further configuration!&lt;/p&gt; &lt;p&gt;Now if you go into the Configure tab for your site, you’ll see your associated connection string:&lt;/p&gt; &lt;p&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="image" src="http://lh3.ggpht.com/--d1mgOEUlhE/UE-4ZTMi7nI/AAAAAAAADpY/9n8emYSj_8g/image%25255B40%25255D.png?imgmax=800" width="695" height="185"&gt; &lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;Note that it’s hidden by default, but you can choose to display it if you need it (e.g. if you want to connect via SQL management studio). You can even edit it if you want to tweak it!&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;h3&gt;Working with external connection strings&lt;/h3&gt; &lt;p&gt;In the scenario above, we were using a database that Azure created for us along with the site. In some cases, you will instead need to work with an existing database, which may or may not be hosted on Azure.&lt;/p&gt; &lt;p&gt;In that scenario, you’d create your site without any databases. Instead, you can manually add the connection string in the Configure tab, e.g.&lt;/p&gt; &lt;p&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="image" src="http://lh4.ggpht.com/-1B4_tQYkNh0/UE-4amdKCYI/AAAAAAAADpc/AgxQ7DwmsmI/image%25255B41%25255D.png?imgmax=800" width="676" height="152"&gt; &lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: don’t forget to click the Save button at the bottom of the page when you’re done!&lt;/p&gt; &lt;p&gt;Note that as before, we’re naming the connection string after the one in web.config. The only difference is that the value now comes from you instead of coming from Azure.&lt;/p&gt;  &lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/rHgteqacDtM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/2997817182856276191/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2012/09/managing-database-connections-in-azure.html#comment-form" title="12 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/2997817182856276191?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/2997817182856276191?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/rHgteqacDtM/managing-database-connections-in-azure.html" title="Managing database connections in Azure Web Sites" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh6.ggpht.com/-XT3zcbwAv1M/UE-4W5vjrFI/AAAAAAAADpM/p3HeYukyzxo/s72-c/image%25255B37%25255D.png?imgmax=800" height="72" width="72" /><thr:total>12</thr:total><feedburner:origLink>http://blog.davidebbo.com/2012/09/managing-database-connections-in-azure.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEUERHc-fyp7ImA9WhJUGU0.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-8661052133942997215</id><published>2012-07-31T21:39:00.001-07:00</published><updated>2012-09-17T10:16:45.957-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-09-17T10:16:45.957-07:00</app:edited><title>Using a naked domain with a Windows Azure Web Site</title><content type="html">&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;font color="#ff0000"&gt;Update (9/17/2012): as of today, Azure Web Sites have direct support for A record, so the hack below is no longer necessary!&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;em&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/em&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;em&gt;&lt;strong&gt;Warning&lt;/strong&gt;: the following is just something that worked for me, and that others asked me about. It is not a Microsoft approved technique, and it could cause your cat to self-combust with no warning. I’m just a guy trying random things here.&lt;/em&gt;&lt;/p&gt; &lt;p&gt;&lt;em&gt;&lt;/em&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Windows Azure Web Sites (WAWS) support custom domain names, as documented on &lt;a href="https://www.windowsazure.com/en-us/develop/net/common-tasks/custom-dns-web-site/" target="_blank"&gt;this page&lt;/a&gt;. This makes it easy to use a name like &lt;a href="http://www.davidebbo.com"&gt;www.davidebbo.com&lt;/a&gt;, by setting up a CNAME record in your DNS.&lt;/p&gt; &lt;p&gt;But a lot of people are asking how to make the name just &lt;a href="http://davidebbo.com" target="_blank"&gt;davidebbo.com&lt;/a&gt;, which is known as a naked domain (aka a bare or root domain). Normally, this is done by setting up an A record, but this requires a stable IP address, which is not currently available in WAWS.&lt;/p&gt; &lt;p&gt;But it turns out that you can use use a CNAME for the naked domain, even though many people say it’s a bad idea (more on this below).&lt;/p&gt; &lt;p&gt;I’m not sure if this works with all registrars, but I use NameCheap, and it works with them. Here is what it looks like in the NameCheap DNS records:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-eJelZwrbJy0/UBizUHWYzsI/AAAAAAAADnY/KCoXegEe7KM/s1600-h/image%25255B18%25255D.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://lh4.ggpht.com/-wAVY5LJ2UTM/UBizU4Xgh4I/AAAAAAAADnc/PUmLE1_kCK8/image_thumb%25255B10%25255D.png?imgmax=800" width="564" height="85"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;So I’m doing two things here:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;First I’m making &lt;a href="http://davidebbo.com"&gt;http://davidebbo.com&lt;/a&gt; go to my WAWS  &lt;li&gt;Then I’m making &lt;a href="http://www.davidebbo.com"&gt;http://www.davidebbo.com&lt;/a&gt; redirect to &lt;a href="http://davidebbo.com/"&gt;http://davidebbo.com/&lt;/a&gt;. This is optional.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Then I have the following in the Configure tab of my WAWS:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-FzU1xosAb_4/UBiy_3hlYHI/AAAAAAAADm4/3CAXHommo6s/s1600-h/image%25255B13%25255D.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://lh6.ggpht.com/-326gitmN5Po/UBizAcswG4I/AAAAAAAADnA/jd2qpC-CPRM/image_thumb%25255B7%25255D.png?imgmax=800" width="537" height="195"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Though really, I only need the last entry since I’m redirecting www to the naked domain. I just left the www entry in there because it doesn’t hurt. The first one could go too.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;h3&gt;So what’s wrong with doing this?&lt;/h3&gt; &lt;p&gt;If you search around, you’ll find a number of pages telling you that it’s unsupported, and breaks RFC1034 (e.g. see &lt;a href="http://superuser.com/questions/264913/cant-set-example-com-as-a-cname-record" target="_blank"&gt;this page&lt;/a&gt;). And I’m sure that the experts will crucify me and call me an idiot for blogging this, but heck, I can live with that!&lt;/p&gt; &lt;p&gt;Personally, I don’t care so much about breaking an RFC, as much as I care about breaking my award winning &lt;a href="http://davidebbo.com/"&gt;http://davidebbo.com/&lt;/a&gt; web site, which brings me most of my income.&lt;/p&gt; &lt;p&gt;So what might break? From what I’m told, doing this breaks MX records, which matters if you’re running an email server under your host name. So if I wanted to be me@davidebbo.com, I probably couldn’t. But I don’t, so I don’t care. It might also affect other types of records that I’m not using.&lt;/p&gt; &lt;p&gt;All I can say is that so far, I’m yet to find something broken about it, and I’ve heard from several others that they’ve been using this successfully for a while (not with WAWS, but that shouldn’t matter).&lt;/p&gt; &lt;p&gt;Anyway, I think you get my point: try at your own risk! And sorry about your cat.&lt;/p&gt;  &lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/VQwhI3_uEu8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/8661052133942997215/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2012/07/using-naked-domain-with-windows-azure.html#comment-form" title="5 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/8661052133942997215?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/8661052133942997215?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/VQwhI3_uEu8/using-naked-domain-with-windows-azure.html" title="Using a naked domain with a Windows Azure Web Site" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/-wAVY5LJ2UTM/UBizU4Xgh4I/AAAAAAAADnc/PUmLE1_kCK8/s72-c/image_thumb%25255B10%25255D.png?imgmax=800" height="72" width="72" /><thr:total>5</thr:total><feedburner:origLink>http://blog.davidebbo.com/2012/07/using-naked-domain-with-windows-azure.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkYNR3w8cSp7ImA9WhVaFEs.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-5151819931325305003</id><published>2012-06-11T18:23:00.001-07:00</published><updated>2012-06-11T18:23:16.279-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-06-11T18:23:16.279-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="git" /><category scheme="http://www.blogger.com/atom/ns#" term="azure" /><category scheme="http://www.blogger.com/atom/ns#" term="kudu" /><title>Developing Kudu locally and on Azure</title><content type="html">&lt;p&gt;A few days ago, I &lt;a href="http://blog.davidebbo.com/2012/06/introducing-open-source-engine-behind.html"&gt;discussed&lt;/a&gt; how the git support in Azure Web Sites was written as an Open Source project called &lt;a href="https://github.com/projectkudu/kudu"&gt;Kudu&lt;/a&gt;. This time, I’ll give a few more details on how to run it, both locally and on Azure.&lt;/p&gt; &lt;p&gt;To be clear, you don’t have to care about any of this if you just want to use git deployment to Azure. Just use it as is and it should work great!&lt;/p&gt; &lt;p&gt;This is for folks who are interested in modifying the git deployment engine itself, either to contribute some changes to the project, or just to play around with things.&lt;/p&gt; &lt;h3&gt;Running Kudu locally&lt;/h3&gt; &lt;p&gt;First, you can see it all in action in this &lt;a href="http://www.youtube.com/watch?v=FmufYOz0KXI&amp;amp;feature=plcp&amp;amp;hd=1"&gt;3 minute screencast&lt;/a&gt;!&lt;/p&gt; &lt;p&gt;Here are the basic steps to run Kudu locally. Note that this requires using IIS7, and will not work with IIS Express.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Clone it from &lt;a title="https://github.com/projectkudu/kudu.git" href="https://github.com/projectkudu/kudu.git"&gt;https://github.com/projectkudu/kudu.git&lt;/a&gt;&lt;/li&gt; &lt;li&gt;In Visual Studio, open Kudu.sln. Important: VS needs to run as administrator!&lt;/li&gt; &lt;li&gt;Set Kudu.Web as the Startup solution&lt;/li&gt; &lt;li&gt;Ctrl-F5 to run&lt;/li&gt; &lt;li&gt;You’ll get an admin page that lets you create sites, and gives you the git URL for them&lt;/li&gt; &lt;li&gt;Try git pushing a test project, and see it run!&lt;/li&gt;&lt;/ul&gt; &lt;p align="left"&gt;&lt;strong&gt;Important note&lt;/strong&gt;: the primary purpose of running Kudu locally is to make it easier to develop outside of Azure. Conceivably, you can take this non-Azure Kudu and host it on a VM, to have your own mini deployment server. However, it’s missing a few features that would make it really usable there. e.g. it doesn’t set up host names, and doesn’t set up authentication. We would love to add these features, and welcome contributions!&lt;/p&gt; &lt;h3&gt;Running a private Kudu build on Azure&lt;/h3&gt; &lt;p&gt;First, see it in action in this &lt;a href="http://www.youtube.com/watch?v=rcYXN6ACGi4&amp;amp;feature=youtu.be&amp;amp;hd=1"&gt;5 minute screencast&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;This is the more crazy one. Suppose you want to make changes to the Kudu service, and make it even more awesome. :) You can make these changes locally and test them outside of Azure, per the previous section.&lt;/p&gt; &lt;p&gt;But wouldn’t it be great if you could actually use your latest Kudu bits in Azure itself? Turns out you can, using a special hook that we put in for the exact purpose.&lt;/p&gt; &lt;p&gt;Here are the basic steps:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;As above, clone Kudu from &lt;a title="https://github.com/projectkudu/kudu.git" href="https://github.com/projectkudu/kudu.git"&gt;https://github.com/projectkudu/kudu.git&lt;/a&gt;&lt;/li&gt; &lt;li&gt;Make whatever changes you want to the sources&lt;/li&gt; &lt;li&gt;Run build.cmd at the root of the repo. This creates an artifacts\debug\KuduService folder than contains the built Kudu bits.&lt;/li&gt; &lt;li&gt;Go to the &lt;a href="https://manage.windowsazure.com/"&gt;Azure portal&lt;/a&gt; and create a new app, then enable git.&lt;/li&gt; &lt;li&gt;&lt;a href="https://github.com/projectkudu/kudu/wiki/Accessing-files-via-ftp"&gt;Use FTP to connect to your files&lt;/a&gt;, and copy the KuduService folder at the root. Here is &lt;a href="https://github.com/projectkudu/kudu/wiki/File-structure-on-azure"&gt;what the file structure looks like&lt;/a&gt; in there.&lt;/li&gt; &lt;li&gt;In the Portal, go to the Configure tab, and add an ‘app setting’ with name/value USE_PRIVATE_KUDU=1 (and &lt;strong&gt;don’t forget to hit Save at the bottom!&lt;/strong&gt;).&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;And you’re done! If you now do a git push to your Azure site, you are now using your very own git engine instead of the one that comes with Azure. How cool is that? :)&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Important notes:&lt;/strong&gt;&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Doing this only affects this one site. If you have multiple sites where you want to use your private Kudu bits, you’ll need to set up each of them the same way.&lt;/li&gt; &lt;li&gt;It probably goes without saying, but once you are running your own git deployment engine, you’re in unsupported territory, so don’t call product support if something doesn’t work! However, the Kudu team will always be happy to talk to you on &lt;a href="http://jabbr.net/#/rooms/kudu"&gt;JabbR&lt;/a&gt;, or our &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/azuregit/threads"&gt;MSDN forum&lt;/a&gt;, or on &lt;a href="https://github.com/projectkudu/kudu"&gt;github&lt;/a&gt;. :)&lt;/li&gt;&lt;/ul&gt;  &lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/g7VWp0Ks6RY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/5151819931325305003/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2012/06/developing-kudu-locally-and-on-azure.html#comment-form" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/5151819931325305003?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/5151819931325305003?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/g7VWp0Ks6RY/developing-kudu-locally-and-on-azure.html" title="Developing Kudu locally and on Azure" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><thr:total>4</thr:total><feedburner:origLink>http://blog.davidebbo.com/2012/06/developing-kudu-locally-and-on-azure.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEEFSHw9eyp7ImA9WhVaEk0.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-4524858226870531114</id><published>2012-06-08T17:40:00.001-07:00</published><updated>2012-06-08T17:43:39.263-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-06-08T17:43:39.263-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="git" /><category scheme="http://www.blogger.com/atom/ns#" term="azure" /><category scheme="http://www.blogger.com/atom/ns#" term="kudu" /><title>Introducing Kudu: the Open Source engine behind ‘git push azure master’</title><content type="html">&lt;p&gt;Yesterday, ScottGu unveiled &lt;a href="http://weblogs.asp.net/scottgu/archive/2012/06/07/meet-the-new-windows-azure.aspx"&gt;the new Azure&lt;/a&gt;, which brings a whole list of exciting changes to the platform.&lt;/p&gt; &lt;p&gt;One of the most exciting new features is the ability to deploy Web Sites to Azure using git. Scott’s post covers that, and I also did a &lt;a href="http://www.youtube.com/watch?v=72SAHWUHnzA&amp;amp;hd=1"&gt;screencast&lt;/a&gt; on that topic.&lt;/p&gt; &lt;p&gt;One part that has not yet been discussed is that the engine that powers this feature was developed as an Open Source project from the first line. The project is code named Kudu and can be found at &lt;a href="https://github.com/projectkudu/kudu"&gt;https://github.com/projectkudu/kudu&lt;/a&gt;. Kudu is a member of the the &lt;a href="http://www.outercurve.org/"&gt;Outercurve Foundation&lt;/a&gt;, and is released under the Apache License 2.0 (the same as &lt;a href="http://nuget.codeplex.com"&gt;NuGet&lt;/a&gt;).&lt;/p&gt; &lt;p&gt;This project is actually not tied to Azure, and can run standalone on any machine. In that mode, you can push project and have them run in your local IIS.&lt;/p&gt; &lt;h3&gt;So why is this project interesting to you?&lt;/h3&gt; &lt;p&gt;There are a few reasons that you may be interested in this project.&lt;/p&gt; &lt;p&gt;The first is that it’s a good place to file bugs that you run into when you git push your project to Azure. You can also use our &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/azuregit"&gt;forum&lt;/a&gt; to discuss things.&lt;/p&gt; &lt;p&gt;The second reason is that the associated &lt;a href="https://github.com/projectkudu/kudu/wiki"&gt;wiki&lt;/a&gt; contains lots of useful info about it. Well, at this time there isn’t all that much there, but the idea is that we’ll grow it as we go forward. And of course, wiki contributions are welcome!&lt;/p&gt; &lt;p&gt;And finally, you may be interested in contributing to the project, as we do accept contributions!&lt;/p&gt;  &lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/HjpnZeDiriM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/4524858226870531114/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2012/06/introducing-open-source-engine-behind.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/4524858226870531114?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/4524858226870531114?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/HjpnZeDiriM/introducing-open-source-engine-behind.html" title="Introducing Kudu: the Open Source engine behind ‘git push azure master’" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><thr:total>1</thr:total><feedburner:origLink>http://blog.davidebbo.com/2012/06/introducing-open-source-engine-behind.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkMGQX8-eip7ImA9WhVXEks.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-5598763811011192078</id><published>2012-04-12T15:06:00.001-07:00</published><updated>2012-04-12T15:07:00.152-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-04-12T15:07:00.152-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="T4MVC" /><title>T4MVC has its own home, with some git love</title><content type="html">&lt;p&gt;I have just moved T4MVC to a new CodePlex project, instead of it being part of the MvcContrib project. Its new home is &lt;a href="https://t4mvc.codeplex.com/"&gt;https://t4mvc.codeplex.com/&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;If you’re a T4MVC user, that should not make much difference except that there is now a new place to discuss it and file bugs. NuGet is still the place to go to get T4MVC!&lt;/p&gt; &lt;p&gt;Note that T4MVC is still part of the MvcContrib effort, even if it doesn’t share the same source tree. Here are the reasons for the move.&lt;/p&gt; &lt;h3&gt;Reduce confusion&lt;/h3&gt; &lt;p&gt;T4MVC is quite separate from the rest of MvcContrib, because it’s just a T4 template, and not some code that’s part of an assembly. Having the T4MVC files be in their own little island in the middle of a repo with many unrelated thing has been a bit of a barrier of entry for people wanting to make a quite contribution.&lt;/p&gt; &lt;p&gt;Also, since all MvcContrib bugs are files in the same place, there was always additional pain for me to filter T4MVC issues from unrelated ones.&lt;/p&gt; &lt;p&gt;Likewise, we’ll now have our own &lt;a href="https://t4mvc.codeplex.com/discussions"&gt;discussion forum&lt;/a&gt; that only focuses on T4MVC. Most users have been using StackOverflow for T4MVC support, and you can continue to do that if you prefer.&lt;/p&gt; &lt;h3&gt;Switch to git!&lt;/h3&gt; &lt;p&gt;I’ve been increasingly using git over Mercurial (like everyone else it seems!), to the point where having to use Mercurial is becoming an annoyance. Since CodePlex now supports git, it was the perfect opportunity to switch to that!&lt;/p&gt;  &lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/R_-UIscm7NI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/5598763811011192078/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2012/04/t4mvc-has-its-own-home-with-some-git.html#comment-form" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/5598763811011192078?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/5598763811011192078?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/R_-UIscm7NI/t4mvc-has-its-own-home-with-some-git.html" title="T4MVC has its own home, with some git love" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><thr:total>3</thr:total><feedburner:origLink>http://blog.davidebbo.com/2012/04/t4mvc-has-its-own-home-with-some-git.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkIASXk_fyp7ImA9WhRaEUU.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-8655461955474149038</id><published>2012-02-13T17:54:00.001-08:00</published><updated>2012-02-13T17:55:48.747-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-02-13T17:55:48.747-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Mono" /><title>Quick fun with Mono’s CSharp compiler as a service</title><content type="html">&lt;p&gt;Mono comes with a really cool &lt;a href="http://www.mono-project.com/CSharp_Compiler"&gt;CSharp compiler as a service&lt;/a&gt;. The only problem is that no one seems to know about it!&lt;/p&gt; &lt;p&gt;I think the main reason for this is that anything related to Mono causes a fair bit of confusion to all the people who are not familiar with it. And that certainly includes myself, as I know very little about it besides what I’m discussing in this post!&lt;/p&gt; &lt;p&gt;Talking to various people, the general misconceptions are:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Mono only runs on Linux  &lt;li&gt;Even if it runs on Windows, it doesn’t use the CLR, so I can’t use it  &lt;li&gt;Mono is for strange people :)&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;And while that may be true for some aspects of Mono, it certainly isn’t for Mono.CSharp.dll. In fact, it’s a totally ‘normal’ library that you can use in your very ‘normal’ C# projects in Visual Studio.&lt;/p&gt; &lt;p&gt;The next hurdle is that it’s not all that easy to just get Mono.CSharp.dll. You have to either install an 80MB setup from &lt;a href="http://www.go-mono.com/mono-downloads/download.html"&gt;here&lt;/a&gt;, or get a big .tar.gz file with lots of other things from &lt;a href="http://mono.ximian.com/daily/monocharge-latest.tar.gz"&gt;here&lt;/a&gt;. And a lot of people on Windows don’t like dealing with tar.gz files (hint: use &lt;a href="http://www.7-zip.org/"&gt;7zip&lt;/a&gt;).&lt;/p&gt; &lt;p&gt;Now the good news: after chatting with &lt;a href="https://twitter.com/#!/migueldeicaza"&gt;Miguel de Icaza&lt;/a&gt; on Twitter, I put Mono.CSharp.dll &lt;a href="https://nuget.org/packages/Mono.CSharp"&gt;on NuGet&lt;/a&gt;, making it totally trivial to use from VS. There goes that hurdle. (note: I’m the package owner for now, until some Miguel-blessed dev claims it).&lt;/p&gt; &lt;h3&gt;Try Mono.CSharp in under 5 minutes&lt;/h3&gt; &lt;p&gt;Just open VS and create a Console app, and add a NuGet package reference to Mono.CSharp. That takes a whole 30 seconds. And I’ll re-emphasize that there is nothing ‘Mono’ about this Console app. It’s just plain vanilla.&lt;/p&gt; &lt;p&gt;Now write some basic code to use the compiler. It all revolves around the Evaluator class. Here is the sample code I used (&lt;a href="https://github.com/davidebbo/MonoCompilerDemo"&gt;GitHub&lt;/a&gt;). It’s quick and dirty with poor error handling, as the focus is to just demonstrate the basic calls that make things work:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;using System;
using System.IO;
using Mono.CSharp;

namespace MonoCompilerDemo
{
    public interface IFoo { string Bar(string s); }

    class Program
    {
        static void Main(string[] args)
        {
            var evaluator = new Evaluator(
                new CompilerSettings(),
                new Report(new ConsoleReportPrinter()));

            // Make it reference our own assembly so it can use IFoo
            evaluator.ReferenceAssembly(typeof(IFoo).Assembly);

            // Feed it some code
            evaluator.Compile(
                @"
    public class Foo : MonoCompilerDemo.IFoo
    {
        public string Bar(string s) { return s.ToUpper(); }
    }");

            for (; ; )
            {
                string line = Console.ReadLine();
                if (line == null) break;

                object result;
                bool result_set;
                evaluator.Evaluate(line, out result, out result_set);
                if (result_set) Console.WriteLine(result);
            }
        }
    }
}

&lt;/pre&gt;
&lt;p&gt;It feeds it some starter code and start a REPL look to evaluate expressions. e.g. run it and try this. You type the first two, and the 3rd is output:&lt;/p&gt;&lt;pre class="brush: plain;"&gt;MonoCompilerDemo.IFoo foo = new Foo();
foo.Bar("Hello Mono.CSharp");
HELLO MONO.CSHARP
&lt;/pre&gt;
&lt;p&gt;You get the idea!&lt;/p&gt;
&lt;h3&gt;What about Roslyn?&lt;/h3&gt;
&lt;p&gt;I &lt;a href="http://blog.davidebbo.com/2011/10/using-roslyn-to-implement-mvc-razor.html"&gt;blogged&lt;/a&gt; a few months back about using Roslyn to implement an MVC Razor view engine. I’m far from a Roslyn expert, and frankly haven’t done much with it since that post. From what I read, Roslyn has the potential to enable some very compelling scenarios in the future.&lt;/p&gt;
&lt;p&gt;But there is one major argument right now in favor of using the Mono compiler: it’s pretty much feature complete &lt;strong&gt;today&lt;/strong&gt;, while Roslyn is &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/roslyn/thread/f5adeaf0-49d0-42dc-861b-0f6ffd731825"&gt;not even close&lt;/a&gt;. Totally understandable given that it’s a CTP, and is only meant to give an early taste of the feature.&lt;/p&gt;
&lt;p&gt;So anyway, I still know close to nothing about Mono, but if I need to dynamically compile some pieces of C# in a ‘normal’ non-Mono project, I know that Mono.CSharp is not far away!&lt;/p&gt;  &lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/COMN7GST4Qc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/8655461955474149038/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2012/02/quick-fun-with-monos-csharp-compiler-as.html#comment-form" title="5 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/8655461955474149038?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/8655461955474149038?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/COMN7GST4Qc/quick-fun-with-monos-csharp-compiler-as.html" title="Quick fun with Mono’s CSharp compiler as a service" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><thr:total>5</thr:total><feedburner:origLink>http://blog.davidebbo.com/2012/02/quick-fun-with-monos-csharp-compiler-as.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkQGQX8zcSp7ImA9WhRWEk8.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-1145794917879283085</id><published>2011-10-19T18:25:00.001-07:00</published><updated>2011-12-29T21:52:00.189-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-29T21:52:00.189-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Razor" /><title>Using Roslyn to implement an MVC Razor view engine</title><content type="html">&lt;p&gt;&lt;strong&gt;Update 12/29/2011: the Roslyn CTP is now available on NuGet, so it's no longer necessary to install it before running this sample!&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;
&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: the code for this view engine sample is &lt;a href="https://github.com/davidebbo/RoslynRazorViewEngine" target="_blank"&gt;on Github&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;The C# team has just announced the public availability of the first Roslyn CTP. See their post &lt;a href="http://blogs.msdn.com/b/visualstudio/archive/2011/10/19/introducing-the-microsoft-roslyn-ctp.aspx"&gt;here&lt;/a&gt;, and download it from &lt;a href="http://www.microsoft.com/download/en/details.aspx?id=27746&amp;amp;utm_source=feedburner&amp;amp;utm_medium=twitter&amp;amp;utm_campaign=Feed%3A+MicrosoftDownloadCenter+%28Microsoft+Download+Center%29#tm"&gt;here&lt;/a&gt;. I really hope they can make it available on NuGet soon, but right now it’s not there, so you’ll have to run their setup. Sorry!&lt;/p&gt; &lt;p&gt;As you’ve probably heard from various conferences earlier this year, Roslyn offers a compiler as a service for C# and VB. Since we do a lot of compilation in ASP.NET land, I figured I’d play around with trying write an MVC view engine that uses it instead of the standard compilation path.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Word of warning&lt;/strong&gt;: the Roslyn CTP is still very rough and is missing a lot of key features, like dynamic, anonymous types, indexers and using statements (get the full list &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/roslyn/thread/f5adeaf0-49d0-42dc-861b-0f6ffd731825"&gt;here&lt;/a&gt;). So while I did get something working, the language limitations prevent it from being useful in any real scenario. This is just an exercise to see how far we can get. Lower your expectations! :)&lt;/p&gt; &lt;h3&gt;Why would we want to do this&lt;/h3&gt; &lt;p&gt;When you have a standard MVC project, compilation happens at two different levels:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Your Controllers, Models, and most of your C# code get compiled by msbuild (or Visual Studio) into a single assembly which ends up in the ‘bin’ folder  &lt;/li&gt;&lt;li&gt;All the Views (whether .aspx or .cshtml) get compiled dynamically at runtime by ASP.NET.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;One drawback of compiling views at runtime is that it’s pretty slow. And since it’s slow, ASP.NET tries really hard to save assemblies to disk so it can reuse them across AppDomain cycles. Those assemblies all go under the infamous ‘Temporary ASP.NET Files’ folder. There is a huge amount of complexity to make this work, with settings like batching which can either help or hurt depending on the situation.&lt;/p&gt; &lt;p&gt;One thing I’ve been working on to avoid this dynamic compilation is &lt;a href="http://razorgenerator.codeplex.com/"&gt;RazorGenerator&lt;/a&gt;, which lets you precompile your views into the same assembly as your controllers. This works quite nicely, but it does have one big drawback: you can’t just update a view and have it get picked up at runtime. Instead, you need to rebuild using msbuild (or VS), just like you would when you change a controller file.&lt;/p&gt; &lt;p&gt;What would be nice is to be able to support dynamic compilation of the views, but with a much lighter system then what the standard ASP.NET Build Manager provides. Enter Roslyn!&lt;/p&gt; &lt;h3&gt;Compile views using Roslyn: fast and lightweight&lt;/h3&gt; &lt;p&gt;The main reason that the standard build manager is pretty slow is that it goes through CodeDom, which launching csc.exe for every compilation. csc.exe is actually very fast at compiling C# code, but the fact that we have to pay for the csc process startup time each time we compile anything ends up making things slow.&lt;/p&gt; &lt;p&gt;By contrast, Roslyn gives us an API to compile code in memory, without ever having to launch another process, making things much faster. In fact, it is so fast that the incentive that we had to preserve compiled assembly in ‘Temporary ASP.NET Files’ mostly disappears.&lt;/p&gt; &lt;p&gt;Instead, we can take a much simpler approach: whenever we need to compile a view, we just compile it on the fly in memory using Roslyn, and then cache it for the lifetime of the AppDomain. But we never need to cache it to disk, and generally don’t use the disk at all.&lt;/p&gt; &lt;p&gt;In preliminary tests, I have measured the perf of compiling pages using Roslyn to be more than 50 times faster than doing it via CodeDom. So it’s looking quite promising!&lt;/p&gt; &lt;p&gt;So to summarize, the benefits of using Roslyn to implement a view engine are:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Fast dynamic compilation  &lt;/li&gt;&lt;li&gt;No need to cache assemblies to disk, leading to a much simpler and lighter weight system. &lt;/li&gt;&lt;li&gt;New shiny thing! :)&lt;/li&gt;&lt;/ul&gt; &lt;p&gt; &lt;/p&gt; &lt;h3&gt;More detail about the code&lt;/h3&gt; &lt;p&gt;The code for my sample view engine is on Github (&lt;a href="https://github.com/davidebbo/RoslynRazorViewEngine"&gt;https://github.com/davidebbo/RoslynRazorViewEngine&lt;/a&gt;), so I’ll mostly let you check it out there. All the interesting code is in RoslynRazorViewEngine.cs.&lt;/p&gt; &lt;p&gt;Here are the main steps that it goes through to turn a Razor file into an Assembly:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;First it uses the Razor Engine to generate a CodeCompileUnit from the Razor file.&lt;/li&gt; &lt;li&gt;It then uses CodeDom to turn the CodeCompileUnit into C# source code. Note that we only use CodeDom as a code generator here, and not to actually compile anything.&lt;/li&gt; &lt;li&gt;We then use Roslyn to compile the course code into a byte[]. That byte array is basically an in memory copy of what would normally be a .dll file.&lt;/li&gt; &lt;li&gt;Finally, we call Assembly.Load to load that byte[] into a runtime Assembly.&lt;/li&gt;&lt;/ol&gt; &lt;h3&gt;How restrictive are the limitations in the Roslyn CTP?&lt;/h3&gt; &lt;p&gt;As I mentioned above, there are lots of limitations, which make this little more than a proof of concept.&lt;/p&gt; &lt;p&gt;To begin with, it doesn’t support dynamic, which MVC uses pretty heavily. By default, MVC views extend WebViewPage&amp;lt;dynamic&amp;gt;, so I had to add ‘&lt;em&gt;@model object&lt;/em&gt;’ at the top of my test view to get around that.&lt;/p&gt; &lt;p&gt;Then there is ViewBag, which is also dynamic, and allows writing things like ‘&lt;em&gt;@ViewBag.Message&lt;/em&gt;’. I tried replacing that by ‘&lt;em&gt;@ViewData["Message"]&lt;/em&gt;’, only to find out that indexers were not supported either. Duh!&lt;/p&gt; &lt;p&gt;And then it doesn’t support anonymous objects, which MVC uses quite a bit...&lt;/p&gt; &lt;p&gt;So don’t even think of trying to use this for anything real at this time. Still, the approach feels pretty sound, and whenever Roslyn becomes more feature complete, I have good hope that it can help us improve the ASP.NET compilation system.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/qY8DYYCjFqQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/1145794917879283085/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2011/10/using-roslyn-to-implement-mvc-razor.html#comment-form" title="15 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/1145794917879283085?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/1145794917879283085?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/qY8DYYCjFqQ/using-roslyn-to-implement-mvc-razor.html" title="Using Roslyn to implement an MVC Razor view engine" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><thr:total>15</thr:total><feedburner:origLink>http://blog.davidebbo.com/2011/10/using-roslyn-to-implement-mvc-razor.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEUCQ3o_fip7ImA9WhRXFk8.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-7063252744458381238</id><published>2011-08-16T23:53:00.001-07:00</published><updated>2011-12-22T23:44:22.446-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-22T23:44:22.446-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="NuGet" /><title>The easy way to set up NuGet to restore packages</title><content type="html">&lt;p&gt;&lt;span&gt;&lt;b&gt;Note (12/22/2011): in NuGet 1.6 or later, this feature is built in, so you no longer need to use the NuGetPowerTools. Just right click on the Solution and choose 'Enable NuGet Package Restore'.&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;A few months ago, I described a workflow that lets you &lt;a href="http://blog.davidebbo.com/2011/03/using-nuget-without-committing-packages.html" target="_blank"&gt;use NuGet without committing the packages to source control&lt;/a&gt;. This has been a very popular workflow, and generally works quite well.&lt;/p&gt; &lt;p&gt;The down side is that it’s a bit painful to set up: you have to get NuGet.exe and add it to your tree, then you have to add a pre-build event for every project that uses NuGet.&lt;/p&gt; &lt;p&gt;The good news is that the ever-resourceful &lt;a href="http://twitter.com/#!/davidfowl" target="_blank"&gt;David Fowler&lt;/a&gt; has come up with a much easier way to set that up, using his &lt;a href="https://github.com/davidfowl/NuGetPowerTools" target="_blank"&gt;NuGetPowerTools&lt;/a&gt; package. Here is the way to do it:&lt;/p&gt; &lt;p&gt;Let’s assume that you have a solution that is either already using NuGet, or planning to use it, and that you want to set up the no-commit workflow.&lt;/p&gt; &lt;p&gt;Now, you just need to go to the Package Manager Console and run a couple commands:&lt;/p&gt;&lt;pre class="brush: plain; gutter: false;"&gt;PM&amp;gt; Install-Package NuGetPowerTools
Successfully installed 'NuGetPowerTools 0.28'.

**********************************************************************************
INSTRUCTIONS
**********************************************************************************
- To enable building a package from a project use the Enable-PackageBuild command
- To enable restoring packages on build use the Enable-PackageRestore command.
- When using one of the above commands, a .nuget folder will been added to your
solution root. Make sure you check it in!
- For for information, see https://github.com/davidfowl/NuGetPowerTools
**********************************************************************************


PM&amp;gt; Enable-PackageRestore
Attempting to resolve dependency 'NuGet.CommandLine (≥ 1.4)'.
Successfully installed 'NuGet.CommandLine 1.4.20615.182'.
Successfully installed 'NuGet.Build 0.16'.

Copying nuget.exe and msbuild scripts to D:\Code\StarterApps\Mvc3Application\.nuget
Successfully uninstalled 'NuGet.Build 0.16'.
Successfully uninstalled 'NuGet.CommandLine 1.4.20615.182'.

Don't forget to commit the .nuget folder
Updated 'Mvc3Application' to use 'NuGet.targets'
Enabled package restore for Mvc3Application
&lt;/pre&gt;
&lt;p&gt;And you’re done! So basically, the first command installs a NuGet package which brings in some helpful commands, and the second one runs one of those commands.&lt;/p&gt;
&lt;p&gt;After doing this, you’ll notice a new .nuget folder under your solution, containing nuget.exe plus a couple msbuild target files. &lt;strong&gt;Make sure you commit that folder to source control!&lt;/strong&gt; You’ll also find a few changes in your csproj files to trigger the restore functionality when you build.&lt;/p&gt;
&lt;p&gt;I have now become a strong supporter of the &lt;em&gt;don’t commit packages&lt;/em&gt; workflow, and if you’re going to use it, this is the way to do it!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/A0DaNVX26Y8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/7063252744458381238/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2011/08/easy-way-to-set-up-nuget-to-restore.html#comment-form" title="29 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/7063252744458381238?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/7063252744458381238?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/A0DaNVX26Y8/easy-way-to-set-up-nuget-to-restore.html" title="The easy way to set up NuGet to restore packages" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><thr:total>29</thr:total><feedburner:origLink>http://blog.davidebbo.com/2011/08/easy-way-to-set-up-nuget-to-restore.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkQFSXc6fSp7ImA9WhdRGUQ.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-7897159399027856780</id><published>2011-08-09T00:45:00.001-07:00</published><updated>2011-08-10T09:38:38.915-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-10T09:38:38.915-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="NuGet" /><category scheme="http://www.blogger.com/atom/ns#" term="OData" /><title>How an OData quirk slowed down NuGet, and how we fixed it</title><content type="html">&lt;p&gt;&lt;em&gt;Update: my terminology in this post is not quite correct. Whenever I refer to the server part of OData, I really mean to say ‘WCF Data Services’. OData is the protocol, and WCF Data Services is the specific implementation. So the ‘quirk’ we ran into is a WCF Data Services thing and not an OData thing.&lt;/em&gt;&lt;/p&gt; &lt;p&gt;As you may know, NuGet uses an OData feed for its packages. Whenever you install packages, or search for packages from Visual Studio, it goes through this feed, which you can find at &lt;a href="http://packages.nuget.org/v1/FeedService.svc/Packages"&gt;http://packages.nuget.org/v1/FeedService.svc/Packages&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;If you’re a NuGet user, you may also have noticed that the perf of NuGet searches from Visual Studio had been quite bad in recent months. You’d go to the NuGet package dialog and type a search string, and it would take 10 or more seconds to give you results. Ouch! :(&lt;/p&gt; &lt;p&gt;It turns out that the perf issue was due to a nasty OData quirk that we’ve since worked around, and I thought it might be interesting to share this with others. I’m partly doing this as you might run into this yourself if you use OData, partly to poke a little fun at OData, and also to poke a little fun at ourselves, since we really should have caught that from day one.&lt;/p&gt; &lt;h3&gt;A whole stack of query abstractions&lt;/h3&gt; &lt;p&gt;When you make an OData query from a .NET client, you go through a whole bunch of abstraction layers before a SQL query is made. Let’s say for example that you’re looking for packages that have the string ‘T4MVC’ in their description. It would roughly go though these stages:&lt;/p&gt; &lt;p&gt;First, in your .NET client, the OData client library would let you write something like:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;var packages = context.Packages.Where(p =&amp;gt; p.Description.Contain("T4MVC"));&lt;/pre&gt;
&lt;p&gt;Second, this code gets translated by the OData client LINQ provider into a URL with a query string that looks like this:&lt;/p&gt;&lt;pre class="brush: plain;"&gt;?$filter=substringof('t4mvc',Description)
&lt;/pre&gt;
&lt;p&gt;Third, this is processed by the OData server, which turns it back into a LINQ expressing, which &lt;em&gt;in theory&lt;/em&gt; will look similar to what you had on the client, which was:&lt;/p&gt;&lt;pre class="brush: plain;"&gt;var packages = context.Packages.Where(
    p =&amp;gt; p.Description.Contain("T4MVC"));&lt;/pre&gt;
&lt;p&gt;Of course, the ‘context’ here is a very different beast from what it was in step 1, but from a LINQ expression tree point of view, there shouldn’t be much difference.&lt;/p&gt;
&lt;p&gt;And finally, the Entity Framework LINQ provider turns this into a SQL query, with a WHERE clause that looks something like:&lt;/p&gt;&lt;pre class="brush: plain;"&gt;WHERE Description LIKE N'%T4MVC%'&lt;/pre&gt;
&lt;p&gt;And then it executes nice and fast (assuming a proper index), and all is well.&lt;/p&gt;
&lt;h3&gt;When the abstractions break down&lt;/h3&gt;
&lt;p&gt;Unfortunately, that clean sequence was not going as planned, resulting is much less efficient queries, which started to get really slow as our package count started to get large (and we’re already at over 7000 as of writing this post!).&lt;/p&gt;
&lt;p&gt;So which of these steps went wrong? For us, it turned out to be the third one, where the OData server code was creating a very complex LINQ expression.&lt;/p&gt;
&lt;p&gt;To understand why, let’s first briefly discuss OData providers. When you write an OData DataService&amp;lt;T&amp;gt;, you actually have the choice between three types of providers:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;An &lt;strong&gt;Entity Framework provider&lt;/strong&gt; which works directly over an EF ObjectContext 
&lt;li&gt;A &lt;strong&gt;reflection provider&lt;/strong&gt; which works on an arbitrary context that exposes entity sets that are not tied to a specific database technology 
&lt;li&gt;A &lt;strong&gt;custom provider&lt;/strong&gt;, which is something so hard to write that almost no one has ever done it (maybe a slight exaggeration, but not by much!)&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Give that we’re using EF, #1 seems like the obvious choice. Unfortunately, the EF provider is very inflexible, as it doesn’t let you use any calculated properties on your entities. In other words, it only works if the only thing you want on your OData feed are fields that come straight from the database. So for most non-trivial apps, it’s not a very usable option, and it wasn’t for us (we have some calculated fields like ReportAbuseUrl).&lt;/p&gt;
&lt;p&gt;So we ended up using the reflection provider, and wrapping the EF objects with our own objects which exposed whatever we wanted.&lt;/p&gt;
&lt;p&gt;Functionally, this worked great, but what we didn’t realize is that the use of the reflection provider causes OData to switch to a different LINQ expression tree generator which does ‘crazy’ things. Specifically, it makes the bad assumption that when you use the reflection provider, you must be using LINQ to object.&lt;/p&gt;
&lt;p&gt;So it &lt;em&gt;protects&lt;/em&gt; you by using some ‘null propagation’ logic which makes sure that when you write p.Description.Contain("T4MVC"), it won’t blow up if the Description is ever null. It does this by inserting some conditional checks in the LINQ expression. This is very useful if you are in fact using LINQ to object, but it’s a perf disaster if you are using LINQ to EF!&lt;/p&gt;
&lt;p&gt;Now, when translated into SQL, what should have been the simple WHERE clause above was in fact becoming something like this:&lt;/p&gt;&lt;pre class="brush: plain;"&gt;WHERE  1 = ( CASE 
               WHEN ( Description LIKE N'%T4MVC%' ) THEN 
               CAST(1 AS BIT) 
               WHEN ( NOT ( Description LIKE N'%T4MVC%' ) ) THEN 
               CAST(0 AS BIT) 
             END ) 

&lt;/pre&gt;&lt;font face="Arial"&gt;which was running significantly slower. Note that in reality, we’re querying for multiple fields at once, so the final SQL statement ended up being much scarier than this. I’m just using this simple case for illustration.&lt;/font&gt;&lt;font face="Arial"&gt;And to make things worse, we learned that there was no way of turning off this behavior. What to do?&lt;/font&gt; 
&lt;h3&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;nbsp;&lt;/h3&gt;
&lt;h3&gt;&lt;font face="Arial"&gt;The solution: use some LINQ ninja skills to restore order&lt;/font&gt;&lt;/h3&gt;
&lt;p&gt;&lt;font face="Arial"&gt;LINQ ninja &lt;a href="http://twitter.com/#!/davidfowl" target="_blank"&gt;David Fowler&lt;/a&gt; found this an irresistible challenge, and came up with a fix is both crazy and brilliant: he wrote a custom LINQ provider that analyses the expression tree generated by the OData LINQ provider, searches for the unwanted conditional null-check pattern, and eliminates it before the expression gets handed out to the EF LINQ provider.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;If you want to see the details of his fix, it’s all on github, split into two projects:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;QueryInterceptor (&lt;a href="https://github.com/davidfowl/QueryInterceptor"&gt;https://github.com/davidfowl/QueryInterceptor&lt;/a&gt;) is a helper library that makes it easier to write this type of query modification code.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;ODataNullPropagationVisitor (&lt;a href="https://github.com/davidfowl/ODataNullPropagationVisitor"&gt;https://github.com/davidfowl/ODataNullPropagationVisitor&lt;/a&gt;) builds on QueryInterceptor and specifically targets the removal of the unwanted null check.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Naturally, these are available via NuGet (with the second depending on the first). After importing those packages, all that’s left to do is add one small call to your IQueryable&amp;lt;T&amp;gt;, e.g.&lt;/font&gt;&lt;/p&gt;&lt;pre class="brush: plain;"&gt;query = query.WithoutNullPropagation();&lt;/pre&gt;
&lt;p&gt;and your expression trees will be given a gardener’s special pruning :)&lt;/p&gt;
&lt;h3&gt;Lesson learned: always check your SQL queries&lt;/h3&gt;
&lt;p&gt;Some might conclude that all those query abstractions are just too dangerous, and we should just be writing raw SQL instead, where this never would have happened. But I think that would be way too drastic, and I certainly wouldn’t stop using abstractions because of this issue.&lt;/p&gt;
&lt;p&gt;However, the wisdom we learned is that no matter what query abstractions you’re using (LINQ, OData, or other), you should always run SQL query analyzer on your app to see what SQL statements get run in the end. If you see any queries that doesn't completely make sense based on what your app is doing, get to the bottom of it and address it!&lt;/p&gt;
&lt;p&gt;Of course, this is really ‘obvious’ advice, and the fact that we never did that is certainly a bit embarrassing. Part of the problem is that our tiny NuGet team is mostly focused on the NuGet client, and that the server hasn’t been getting enough love. But yes, these are just bad excuses, and in the end, we messed that one up. But now it’s fixed :)&lt;/p&gt;  &lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/i6E0qWDDIOc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/7897159399027856780/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2011/08/how-odata-quirk-killed-nuget-server.html#comment-form" title="10 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/7897159399027856780?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/7897159399027856780?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/i6E0qWDDIOc/how-odata-quirk-killed-nuget-server.html" title="How an OData quirk slowed down NuGet, and how we fixed it" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><thr:total>10</thr:total><feedburner:origLink>http://blog.davidebbo.com/2011/08/how-odata-quirk-killed-nuget-server.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0ADQnkzeip7ImA9WhdTE0Q.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-1667648208564271569</id><published>2011-07-10T22:53:00.001-07:00</published><updated>2011-07-11T07:49:33.782-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-11T07:49:33.782-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="TechThoughts" /><title>One big feature social networks really need: Channels</title><content type="html">&lt;p&gt;Like many others, I have been playing around with Google+ to see what the new kid on the block has to offer. And it does have some good things going for it, with the concepts of Circles providing a pretty nice approach to privacy.&lt;/p&gt; &lt;p&gt;Unfortunately, it suffers from the same flaw that Facebook and Twitter have always had: &lt;strong&gt;it makes the naïve assumption that when you follow someone, you want to hear everything they have to say&lt;/strong&gt;. In other words, it treats us as one-dimensional beings, which doesn’t match the ‘real world’.&lt;/p&gt; &lt;p&gt;This is something I have always found particularly painful on Twitter, both as a tweet consumer and a tweet producer.&lt;/p&gt; &lt;p&gt;As a &lt;em&gt;consumer&lt;/em&gt;, I end up &lt;em&gt;not&lt;/em&gt; following a bunch of interesting .NET folks because they’re too ‘noisy’, meaning they tweet about a lot of unrelated things that I don’t care about. I’ve tried to follow Scott Hanselman’s philosophy and &lt;a href="http://www.hanselman.com/blog/TwitterLetTheInformationWashOverYou.aspx" target="_blank"&gt;let the river of crap wash over me&lt;/a&gt;, but it just didn’t work for me. I guess I couldn’t take the smell.&lt;/p&gt; &lt;p&gt;As a &lt;em&gt;producer&lt;/em&gt;, I end up not tweeting many things I would want to say, because I know that a lot of my 2500 followers only care about the .NET side, and I don’t want to add crap to their rivers. For instance, I follow tennis closely, but I’m not going to tweet super insightful things like “&lt;em&gt;OMG, Federer lost!!&lt;/em&gt;”, because I know most followers don’t care.&lt;/p&gt; &lt;p&gt;So to summarize, I’m missing out as a consumer, and repressed as a producer. Sad! :(&lt;/p&gt; &lt;h3&gt;Aren’t Twitter hashtags the way to follow topics instead of users?&lt;/h3&gt; &lt;p&gt;Twitter hashtags are an ugly hack over a weak platform, and don’t do much to solve this.&lt;/p&gt; &lt;p&gt;First of all, as a producer, it makes no difference to my followers, since they will see my tweets no matter what hashtags they contain.&lt;/p&gt; &lt;p&gt;As a consumer, hashtags fail pretty badly for a number of reasons. First of all, many people don’t use them correctly. They get misspelled, forgotten, and often conflict with unrelated things. But more importantly, they assume that you want to hear about that topic from everybody, while in many cases &lt;strong&gt;I only want to hear what a selected set of users are saying about that topic&lt;/strong&gt;.&lt;/p&gt; &lt;p&gt;If I could set a search criteria for each user that I follow, I might be getting somewhere, but that’s just not an option today. And even that would work poorly given the inconsistent use of hashtags.&lt;/p&gt; &lt;h3&gt;But don’t Google+ Circles solve this issue?&lt;/h3&gt; &lt;p&gt;No, not one bit! Circles are about privacy and nothing else. The issue I’m discussing here has nothing to do with privacy; it’s about filtering of public information.&lt;/p&gt; &lt;p&gt;I see people saying that Google+ successfully merges what Facebook and Twitter are good at: connecting with friends and having a public voice. They are wrong! Let’s put that to the test…&lt;/p&gt; &lt;p&gt;Let say I convince all my family to get on Google+ (a tough challenge, but bear with me). I add them to my ‘family’ circle and they do the same thing. We can share family things with great privacy; that’s nice, and is where circles shine.&lt;/p&gt; &lt;p&gt;But now let’s say I’m also using Google+ the way I use twitter today, and write a whole bunch of things about .NET.&lt;/p&gt; &lt;p&gt;What happens when my family members click on their ‘family’ circle? They’re inundated with all that .NET stuff from me that they couldn’t care less about! Their first reaction is that they want to go back to Facebook, where they don’t see that ‘work’ stuff.&lt;/p&gt; &lt;p&gt;Now let’s look at a second scenario: I want to publicly share various things about both .NET and tennis. They key word here is &lt;strong&gt;publicly&lt;/strong&gt;. I don’t want to have to add everyone who can read my tennis and .NET comments two circles, since I want it to be wide open. Circles are just not meant to solve this.&lt;/p&gt; &lt;h3&gt;The answer: Channels&lt;/h3&gt; &lt;p&gt;One simple way to solve this is to add a concept called ‘channels’. Here is how it would work:&lt;/p&gt; &lt;p&gt;First everyone can (optionally) define a list of channels. In my case, I might create channels called ‘tech’, ‘tennis’, and ‘personal’. For each channel, you can write a one line ‘advertisement’ of what you generally discuss there. e.g. my tech channel might say ‘&lt;em&gt;stuff I work on, mostly related to .NET and NuGet&lt;/em&gt;'.&lt;/p&gt; &lt;p&gt;Then whenever you share something, you can choose whether it should go to everyone or just some channel. Note that when I say ‘everyone’ here, I really mean ‘&lt;em&gt;everyone that is allowed to see it&lt;/em&gt;’. Again, channels are not a privacy concept; they are orthogonal.&lt;/p&gt; &lt;p&gt;Finally, when you follow someone (i.e. add them to a circle), you get to choose whether you want the whole person, or only some of the channels. e.g. my mom would pick my ‘personal’ channel, while some .NET folks may choose ‘tech’, and others might leave it unfiltered and get it all (which would be the default, as it is today).&lt;/p&gt; &lt;p&gt;As an additional option, you could attach a channel to each circle. e.g. my ‘family’ circle would use to the ‘personal’ channel, so I don’t have to think about it when I share from there. Note that this setting only applies to what I share. For each family member that I follow, I can still select what I want from &lt;em&gt;their&lt;/em&gt; channels (which are likely not named the same as mine).&lt;/p&gt; &lt;p&gt;This may seem a bit complicated, but I don’t think it would be in practice, because:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Users coming from Facebook who only use it to connect to friends would not define any channels.  &lt;li&gt;When you start following someone, you’d typically follow the whole person, as you do today. Then if you start getting too much noise from them, an easy-to-find option would allow you to tune it down. e.g. the context menu on my ‘tennis’ comment would offer “Don’t show any more ‘tennis’ comments from this user”. Conceptually, this is similar to Facebook offering you to ignore Farmville entries from some users, and that’s an easy concept to understand.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;So it would not make the platform any less approachable to newbies, but the extra power would be readily available when needed.&lt;/p&gt; &lt;h3&gt;Good old blogs have had that forever&lt;/h3&gt; &lt;p&gt;Interestingly, if you view ‘things that you share’ as ‘blog posts’, and ‘following someone’ as ‘subscribing to their RSS feed’, you find that the channel feature I describe here is almost identical to the concept of tags/labels in a blog.&lt;/p&gt; &lt;p&gt;e.g. You subscribe to &lt;a href="http://blog.davidebbo.com/"&gt;http://blog.davidebbo.com/&lt;/a&gt; to get all my posts, and to &lt;a href="http://blog.davidebbo.com/search/label/NuGet"&gt;http://blog.davidebbo.com/search/label/NuGet&lt;/a&gt; to only get my posts about NuGet.&lt;/p&gt; &lt;p&gt;So the basic concept is far from new, but for some reason the big social networks have not caught on to it.&lt;/p&gt; &lt;h3&gt;Will this feature ever be available?&lt;/h3&gt; &lt;p&gt;Well, that’s good question! My hope is that enough people want it that the big social networks will eventually want to implement something like it.&lt;/p&gt; &lt;p&gt;If I had to choose, I’d prefer Google+ to be the one offering this, since I think it has a model which lends itself to it best.&lt;/p&gt; &lt;p&gt;And if all else fails, I’ll just have to start a new social network. Or not! :)&lt;/p&gt;  &lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/5rguhpG4da8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/1667648208564271569/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2011/07/one-big-feature-social-networks-really.html#comment-form" title="30 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/1667648208564271569?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/1667648208564271569?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/5rguhpG4da8/one-big-feature-social-networks-really.html" title="One big feature social networks really need: Channels" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><thr:total>30</thr:total><feedburner:origLink>http://blog.davidebbo.com/2011/07/one-big-feature-social-networks-really.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkcHSXY_fyp7ImA9WhdXFkQ.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-3387182620150863142</id><published>2011-06-25T00:03:00.001-07:00</published><updated>2011-08-30T00:40:38.847-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-30T00:40:38.847-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><category scheme="http://www.blogger.com/atom/ns#" term="NuGet" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Razor" /><category scheme="http://www.blogger.com/atom/ns#" term="RazorGenerator" /><title>Unit test your MVC views using Razor Generator</title><content type="html">&lt;p&gt;&lt;b&gt;&lt;em&gt;Click &lt;/em&gt;&lt;a href="http://blog.davidebbo.com/search/label/RazorGenerator"&gt;&lt;em&gt;here&lt;/em&gt;&lt;/a&gt;&lt;em&gt; to find all the posts relating to the Razor Generator&lt;/em&gt;&lt;/b&gt;&lt;/p&gt; &lt;p&gt;A few days ago, I &lt;a href="http://blog.davidebbo.com/2011/06/precompile-your-mvc-views-using.html" target="_blank"&gt;blogged&lt;/a&gt; about how you can use &lt;a href="http://visualstudiogallery.msdn.microsoft.com/1f6ec6ff-e89b-4c47-8e79-d2d68df894ec" target="_blank"&gt;Razor Generator&lt;/a&gt; to precompile your MVC Razor views. &lt;/p&gt; &lt;div&gt;In this post, I will demonstrate how you can then unit test your precompiled views. Note that this is still very much experimental, so at this point the primary goal is to get feedback on the concept.&lt;/div&gt; &lt;div&gt;&amp;nbsp;&lt;/div&gt; &lt;div&gt;&lt;/div&gt; &lt;div&gt; &lt;h3&gt;Simple walkthrough to unit test views&lt;/h3&gt;&lt;/div&gt; &lt;p&gt;After installing RazorGenerator, create an MVC 3 Razor app, using the ‘Internet Application’ template and including the unit test project.&lt;/p&gt; &lt;p&gt;In the previous post, we used precompiled views in a different library, so this time let’s keep them in the MVC project to show something different.&lt;/p&gt; &lt;div&gt;First, use NuGet to install the &lt;em&gt;RazorGenerator.Mvc&lt;/em&gt; package in your MVC project.&lt;/div&gt; &lt;div&gt;&amp;nbsp;&lt;/div&gt; &lt;div&gt;Then, as in the previous post, set the custom tool on Views\Home\Index.cshtml to ‘RazorGenerator’, causing Index.cs to be generated under it.&lt;/div&gt; &lt;div&gt;&amp;nbsp;&lt;/div&gt; &lt;div&gt;But now, let’s do something new and use NuGet again to add the &lt;em&gt;RazorGenerator.Testing&lt;/em&gt; package to the unit test project (&lt;strong&gt;not&lt;/strong&gt; to the MVC app!).&lt;/div&gt; &lt;div&gt;&amp;nbsp;&lt;/div&gt; &lt;div&gt;And that’s all it takes to get set up! Now we can write a unit test for our precompiled Index.cshtml view. e.g. create a Views\HomeViewsTest.cs (in the unit test project): &lt;/div&gt; &lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;pre class="brush: csharp;"&gt;using HtmlAgilityPack;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MvcApplication2.Views.Home;
using RazorGenerator.Testing;

namespace MvcApplication1.Tests.Views {
    [TestClass]
    public class HomeViewsTest {
        [TestMethod]
        public void Index() {
            // Instantiate the view directly. This is made possible by
            // the fact that we precompiled it
            var view = new Index();

            // Set up the data that needs to be accessed by the view
            view.ViewBag.Message = "Testing";

            // Render it in an HtmlAgilityPack HtmlDocument. Note that
            // you can pass a 'model' object here if your view needs one.
            // Generally, what you do here is similar to how a controller
            //action sets up data for its view.
            HtmlDocument doc = view.RenderAsHtml();

            // Use the HtmlAgilityPack object model to verify the view.
            // Here, we simply check that the first &amp;lt;h2&amp;gt; tag contains
            // what we put in view.ViewBag.Message
            HtmlNode node = doc.DocumentNode.Element("h2");
            Assert.AreEqual("Testing", node.InnerHtml.Trim());
        }
    }
}

&lt;/pre&gt;
&lt;h3&gt;A few notes about unit testing views&lt;/h3&gt;
&lt;p&gt;Unit testing views in ASP.NET MVC is something that was very tricky to do before, due to the fact that the views are normally compiled at runtime. But the use of the Razor Generator makes it possible to directly instantiate view classes and unit test them.&lt;/p&gt;
&lt;div&gt;Now the big question, is whether unit testing views is desirable. Some people have expressed concerns that it would be a bit fragile due to the changing nature of the HTML output.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;My take here is that while it would be a bad idea to try to compare the entire HTML output, the test can be made pretty solid by selectively comparing some interesting fragments, as in the sample above.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;That being said, I have not tried this is a real app, so there is still much to learn about how this will all play out. This is just a first step! &lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;h3&gt;What about partial views?&lt;/h3&gt;
&lt;p&gt;When designing this view testing framework, we took the approach that we wanted to focus on the output of just one view at a time. Hence, if a view calls @Html.Partial(…) to render a sub-view, we don’t let the sub-view render itself, and instead just render a token to mark where the sub-view would be.&lt;/p&gt;
&lt;div&gt;This seemed more true to the nature of what a unit test should be, compared to letting the whole composite page render itself, which would be more of a functional test (plus there were some tough challenged to making it work). &lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;h3&gt;Where do we go from here?&lt;/h3&gt;
&lt;p&gt;Well, it’ll be interesting to hear what people think about the general idea. We’re interested in two types of feedback.&lt;/p&gt;
&lt;div&gt;First, what do you think about the overall concept of unit testing views using this approach. Second, please report bugs that you run into to &lt;a href="http://razorgenerator.codeplex.com/"&gt;http://razorgenerator.codeplex.com/&lt;/a&gt;. At this point, I expect it to be a bit buggy and probably blow up on some complex views. Treat it as a proof of concept! :)&lt;/div&gt;  &lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/LagVaI6WtLI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/3387182620150863142/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2011/06/unit-test-your-mvc-views-using-razor.html#comment-form" title="39 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/3387182620150863142?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/3387182620150863142?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/LagVaI6WtLI/unit-test-your-mvc-views-using-razor.html" title="Unit test your MVC views using Razor Generator" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><thr:total>39</thr:total><feedburner:origLink>http://blog.davidebbo.com/2011/06/unit-test-your-mvc-views-using-razor.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkQGRXYzeyp7ImA9WhVWFEU.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-3366259403750275061</id><published>2011-06-23T00:20:00.001-07:00</published><updated>2012-04-26T16:52:04.883-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-04-26T16:52:04.883-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Razor" /><category scheme="http://www.blogger.com/atom/ns#" term="RazorGenerator" /><title>Precompile your MVC Razor views using RazorGenerator</title><content type="html">&lt;p&gt;&lt;b&gt;&lt;em&gt;Click &lt;/em&gt;&lt;a href="http://blog.davidebbo.com/search/label/RazorGenerator"&gt;&lt;em&gt;here&lt;/em&gt;&lt;/a&gt;&lt;em&gt; to find all the posts relating to the Razor Generator&lt;/em&gt;&lt;/b&gt; A while back, I &lt;a href="http://blogs.msdn.com/b/davidebb/archive/2010/10/27/turn-your-razor-helpers-into-reusable-libraries.aspx" target="_blank"&gt;blogged&lt;/a&gt; about a single file generator I wrote that can precompile Razor helpers. A bit later, &lt;a href="http://twitter.com/#!/csteeg" target="_blank"&gt;Chris van de Steeg&lt;/a&gt; started from that code base and extended it to support precompiling MVC views (see &lt;a href="http://www.chrisvandesteeg.nl/2010/11/22/embedding-pre-compiled-razor-views-in-your-dll/" target="_blank"&gt;his post&lt;/a&gt;).&lt;/p&gt; &lt;p&gt;On my side, this project stayed dormant for a little while, but recently we started extending it to support a number of interesting new scenarios, including precompiling MVC views (albeit with a slightly different approach from Chris's).&lt;/p&gt; &lt;p&gt;Most of the new code was written by &lt;a href="http://twitter.com/#!/pranav_km"&gt;Pranav Krishnamoorthy&lt;/a&gt;, a dev on the ASP.NET team. Many thanks to him for moving this project forward. &lt;/p&gt; &lt;h3&gt;Installing the generator&lt;/h3&gt; &lt;p&gt;It’s on the VS extension gallery, so install it from there. It’s called “Razor Generator” (not to be confused with “Razor Single File Generator for MVC”, which is Chris’).&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-BHaijcF6L5E/TgLpK6al5XI/AAAAAAAAAYk/QufweQpBFnk/s1600-h/image%25255B3%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-jkOfjQOV26M/TgLpLIbuETI/AAAAAAAAAYo/B2r3nk0WFKo/image_thumb%25255B1%25255D.png?imgmax=800" width="447" height="71"&gt;&lt;/a&gt; &lt;/p&gt; &lt;h3&gt;&lt;/h3&gt; &lt;h3&gt;Walkthrough to precompile MVC views&lt;/h3&gt; &lt;p&gt;You can use it to precompile MVC views either in a separate library or in the MVC project itself. I’ll demonstrate the separate library case, as it’s a bit more interesting.&lt;/p&gt; &lt;p&gt;To begin with, create a new MVC 3 app using Razor (and the ‘Internet Application’ template). Then add a new class library project to the solution (e.g. call it MyPrecompiledViews), and add a reference to it from the MVC project.&lt;/p&gt; &lt;p&gt;&lt;i&gt;&lt;b&gt;Update (4/26/2012)&lt;/b&gt;: the best approach is to actually create an MVC project for that library, instead of a library project. You'll never actually run it as an Mvc app, but the fact that it comes with the right set of config files allows intellisense and other things to work a lot better than in a library project. See &lt;a href="http://razorgenerator.codeplex.com/"&gt;http://razorgenerator.codeplex.com/&lt;/a&gt; for latest info.&lt;/i&gt; &lt;p&gt;Now the fun part begins: using NuGet, install the RazorGenerator.Mvc package into your class library. This adds a number of things to the project:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;A reference to RazorGenerator.Mvc.dll, which contains the view engine  &lt;li&gt;Logic to register the view engine using WebActivator (in App_Start\PrecompiledMvcViewEngineStart.cs).  &lt;li&gt;Two web.config files that are there to make intellisense work while you author your views (they’re not used at runtime)  &lt;li&gt;A sample view, which you can later remove&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Let’s take a closer look at that sample view:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-hty_mGtEgPw/TgLpLUUvdhI/AAAAAAAAAYs/E-yDXJGRwVI/s1600-h/image%25255B8%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-MQpzV2zjSZs/TgLpLkUkiBI/AAAAAAAAAYw/ji5bVXveX0M/image_thumb%25255B4%25255D.png?imgmax=800" width="207" height="148"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-fsjTaGjT6xI/TgLpL7PXH_I/AAAAAAAAAY0/GZbkR89UuRc/s1600-h/image%25255B16%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-Py4u8iBx64w/TgLpMGkQSzI/AAAAAAAAAY4/1C5hEvLy0pA/image_thumb%25255B8%25255D.png?imgmax=800" width="359" height="119"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Notice that it has a Custom Tool set to RazorGenerator, which causes it to generate a .cs file underneath itself (thanks to the generator we installed earlier).&lt;/p&gt; &lt;p&gt;This is just a sample, so now let’s move the Views\Home\Index.cshtml from the MVC project to the same folder in the class library (you can press Shift during the drag/drop to make it a move). Then set the generator to RazorGenerator as in test.cshtml. You’ll now get an Index.cs nested under Index.cshtml.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;And that’s it you’re done! &lt;/strong&gt;You can now run your app, and it will be using the precompiled version of Home\Index.cshtml. &lt;/p&gt; &lt;h3&gt;Why would you want to do that?&lt;/h3&gt; &lt;p&gt;One reason to do this is to &lt;strong&gt;avoid any runtime hit&lt;/strong&gt; when your site starts, since there is nothing left to compile at runtime. This can be significant in sites with many views.&lt;/p&gt; &lt;p&gt;Also, you no longer need to deploy the cshtml files at all, resulting in a &lt;strong&gt;smaller deployment file set&lt;/strong&gt;.&lt;/p&gt; &lt;p&gt;Another cool benefit is that it gives you the ability to &lt;strong&gt;unit test your views&lt;/strong&gt;, which has always been something very difficult with the standard runtime compilation model. I’ll cover that in more details in a future post. &lt;/p&gt; &lt;h3&gt;Generating files at design time vs. build time&lt;/h3&gt; &lt;p&gt;The way the generation works is very similar to T4 templates you have you project. The generation happens as soon as you save the file. You can also force it to regenerate by right clicking on the .cshtml file and choosing Run Custom Tool.&lt;/p&gt; &lt;p&gt;Generally, the guidance is to commit those generated files along with the cshtml file, the same way that you commit all your ‘hand-written’ source files. If you do that, everything will run just fine in an automated build environment.&lt;/p&gt; &lt;p&gt;Another reason to commit the generated files is that it allows you to write code against them with full VS intellisense. e.g. if you use this technique to write Razor helpers that you want to call from other views, you really want VS to know about the generated file at design time. Ditto if you want to write unit tests against your views.&lt;/p&gt; &lt;p&gt;That being said, if you really want to postpone the generation until build time, we’re working on an MsBuild task that will do that. For now, you can find it by getting the RazorGenerator sources on CodePlex. &lt;/p&gt; &lt;h3&gt;If you want to help or report issues&lt;/h3&gt; &lt;p&gt;This project is hosted on &lt;a href="http://razorgenerator.codeplex.com/"&gt;http://razorgenerator.codeplex.com/&lt;/a&gt; under the Ms-PL Open Source license, so feel free to contribute! You can also use CodePlex to discuss and report issues.&lt;/p&gt;  &lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/Mvhy-QX3g5Y" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/3366259403750275061/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2011/06/precompile-your-mvc-views-using.html#comment-form" title="75 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/3366259403750275061?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/3366259403750275061?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/Mvhy-QX3g5Y/precompile-your-mvc-views-using.html" title="Precompile your MVC Razor views using RazorGenerator" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/-jkOfjQOV26M/TgLpLIbuETI/AAAAAAAAAYo/B2r3nk0WFKo/s72-c/image_thumb%25255B1%25255D.png?imgmax=800" height="72" width="72" /><thr:total>75</thr:total><feedburner:origLink>http://blog.davidebbo.com/2011/06/precompile-your-mvc-views-using.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0MHQXo9cCp7ImA9WhZVE00.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-1699768860006977356</id><published>2011-05-24T18:51:00.001-07:00</published><updated>2011-05-24T22:30:30.468-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-24T22:30:30.468-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="NuGet" /><title>Thoughts on installing and updating NuGet packages outside of Visual Studio</title><content type="html">&lt;p&gt;One thing we hear occasionally from users is that it would be nice to be able to install NuGet packages from the command line (e.g. &lt;a href="http://nuget.codeplex.com/workitem/818"&gt;this issue&lt;/a&gt;, &lt;a href="http://nuget.codeplex.com/workitem/902"&gt;that one&lt;/a&gt;, and &lt;a href="http://nuget.codeplex.com/discussions/246942"&gt;this thread&lt;/a&gt;). There are good reasons why this isn’t supported today, which I will discuss in this post.&lt;/p&gt; &lt;h3&gt;What does installing a package even mean?&lt;/h3&gt; &lt;p&gt;Before we go further, we need to be clear about exactly what we mean by ‘installing a package’. The reason this needs to be clarified is that there are really two definitions, which can cause confusion.&lt;/p&gt; &lt;ol&gt; &lt;li&gt;&lt;strong&gt;Getting the bits onto the machine:&lt;/strong&gt; ‘installing a NuGet package’ is sometimes used to mean the act of getting the contents of the package onto your hard drive.  &lt;li&gt;&lt;strong&gt;Making a project use a package:&lt;/strong&gt; more commonly, it refers to not only downloading the package bits, but also ‘applying’ them to a project.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;#1 is something that is fully supported today outside of Visual Studio using nuget.exe (see my &lt;a href="http://blog.davidebbo.com/2011/01/installing-nuget-packages-directly-from.html"&gt;previous post&lt;/a&gt;). NuGet also supports &lt;a href="http://blog.davidebbo.com/2011/03/using-nuget-without-committing-packages.html"&gt;restoring packages outside of VS&lt;/a&gt; so you don’t have to commit them.&lt;/p&gt; &lt;p&gt;But for the sake of this post, I am strictly referring to #2, and that’s what I mean any time I use the term ‘installing a package’ below.&lt;/p&gt; &lt;p&gt;Now that we have this out of the way, let’s discuss why installing a package outside Visual Studio is non-trivial, as well as why it is in most cases not useful at all, although a case can be made for updating packages.&lt;/p&gt; &lt;h3&gt;What makes installing a package outside Visual Studio non-trivial&lt;/h3&gt; &lt;p&gt;Installing a NuGet package into a project (e.g. a csproj file) is a rich operation which does a lot more than just copying files. Here is a rough list of what NuGet can do when you install a package from VS (whether using the Package Manager Console or the NuGet Dialog):&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Add references to assemblies contained in the package  &lt;li&gt;Add references to framework assemblies in the GAC  &lt;li&gt;Add content files to an app (e.g. JavaScript files, code files, …)  &lt;li&gt;Add assembly binding redirects to deal with version incompatibilities  &lt;li&gt;Perform config transformations, typically to add settings related to the package  &lt;li&gt;Bring in tools that can then be run from Package Manager Console  &lt;li&gt;Run PowerShell scripts which can do arbitrary things by automating the DTE object model&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Now let’s think about what it would take to perform those operations outside of VS.&lt;/p&gt; &lt;p&gt;The first 3 involve making modifications to the csproj file. When done within VS, it happens automatically by calling DTE methods, but outside of VS it would need to be done using custom parsing logic. While it’s clearly possible, it needs to be done carefully to avoid corrupting the csproj file. e.g. a GAC reference should not be added if it’s already there.&lt;/p&gt; &lt;p&gt;#4 to #6 should not be too different from doing it in VS.&lt;/p&gt; &lt;p&gt;#7 is basically impossible, since you cannot really ‘fake’ the DTE to let those script run.&lt;/p&gt; &lt;p&gt;So conceivably, with some good amount of work, we could support all scenarios except #7. It would be a little quirky as some packages would not fully work, but in many cases it would work.&lt;/p&gt; &lt;p&gt;But let’s now discuss how useful it would be.&lt;/p&gt; &lt;h3&gt;Why installing packages outside of Visual Studio rarely makes sense&lt;/h3&gt; &lt;p&gt;So let’s say we had this feature and it fully worked. What would it let you do that you can’t do today?&lt;/p&gt; &lt;p&gt;You could use the command line outside VS to install a Foo package in your project, but that in itself is rarely useful. e.g. suppose the package brings in a Foo.dll. You now have that assembly added as a reference in your project, but you don’t have any code using it. You now need to go in VS to write code against that new assembly, so it would have been simpler to just add it from VS in the first place!&lt;/p&gt; &lt;p&gt;And that’s generally the case for most packages: the logical step after installing them is to go to VS and actually use them, which mostly negates any benefits you may find by installing it outside of VS.&lt;/p&gt; &lt;p&gt;Admittedly, there are exceptions, like the Elmah package which is more or less ‘ready to run’ after you install it. But for the wide majority of packages, there is no direct ‘install and run’ workflow.&lt;/p&gt; &lt;h3&gt;What about package updates?&lt;/h3&gt; &lt;p&gt;If package installs don’t make sense outside of VS, what about package &lt;em&gt;updates&lt;/em&gt;?&lt;/p&gt; &lt;p&gt;So you have this Foo packages that you installed from VS, but now you want to update it to a new versions from the command line. Does that make sense?&lt;/p&gt; &lt;p&gt;I think it does make a lot more sense than the install scenario, because by that point, you (presumably) already wrote some code that uses the package. So by updating it, you might get a newer Foo.dll with bug fixes, but all the code you wrote is still valid and ready to run against.&lt;/p&gt; &lt;p&gt;In particular, update could work well in the constrained scenario where the new version on the package just updates an assembly but doesn’t do much else.&lt;/p&gt; &lt;p&gt;On the other hand, it would be hard to support in the general case, since in theory, the updated package can be completely different from the older one. e.g. suppose the new package contains some new install-time PowerShell scripts. We’d be right back with the same tough issues discussed above.&lt;/p&gt; &lt;h3&gt;Where do we go from here? You tell us!&lt;/h3&gt; &lt;p&gt;My take is that we need to experiment with supporting package update outside on VS for at least a subset of scenarios. The big question is deciding how far this needs to go to reach sufficiently useful state.&lt;/p&gt; &lt;p&gt;The first step would be to start with the ‘only the assembly changed’ scenario, which is relatively simple, and probably is the 90+% case.&lt;/p&gt; &lt;p&gt;If you have some thoughts on this, we’d love to hear them! Would you use such feature, and would limiting it to updating assembly references be enough for your needs?&lt;/p&gt;  &lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/kz7qhwtT-98" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/1699768860006977356/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2011/05/thoughts-on-installing-and-updating.html#comment-form" title="29 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/1699768860006977356?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/1699768860006977356?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/kz7qhwtT-98/thoughts-on-installing-and-updating.html" title="Thoughts on installing and updating NuGet packages outside of Visual Studio" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><thr:total>29</thr:total><feedburner:origLink>http://blog.davidebbo.com/2011/05/thoughts-on-installing-and-updating.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEAGRHs4eyp7ImA9WhZQEEU.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-3267069173334371924</id><published>2011-04-14T02:16:00.001-07:00</published><updated>2011-04-17T16:25:25.533-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-04-17T16:25:25.533-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="NuGet" /><title>The easy way to publish NuGet packages with sources</title><content type="html">&lt;p&gt;The standard way to create NuGet packages today is to:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Create a nuspec file with all the metadata and package dependencies  &lt;/li&gt;&lt;li&gt;Lay out the files that to want to include  &lt;/li&gt;&lt;li&gt;Run ‘nuget pack’ to create the package  &lt;/li&gt;&lt;li&gt;Run ‘nuget push’ to push them to the gallery&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;See &lt;a href="http://haacked.com/archive/2011/01/12/uploading-packages-to-the-nuget-gallery.aspx" target="_blank"&gt;Phil’s post&lt;/a&gt; more more details on those steps.&lt;/p&gt; &lt;p&gt;While this is pretty straightforward, it can be made yet easier if we take advantage of the fact that your VS project already contains a lot of information that shouldn’t have to be repeated.&lt;/p&gt; &lt;p&gt;Today, we are releasing a new nuget.exe feature of that makes this a lot easier.&lt;/p&gt; &lt;h3&gt;Debugging support via SymbolSource.org&lt;/h3&gt; &lt;p&gt;The other really exciting thing we’d like to announce today is that we have partnered with the folks at &lt;a href="http://www.symbolsource.org/"&gt;http://www.symbolsource.org/&lt;/a&gt; to offer a really simple way of publishing your sources and PDB’s along with your package.&lt;/p&gt; &lt;p&gt;Up until now, there really wasn’t a great way for package authors to let their users debug into the package’s binaries. The user would have needed to download the sources separately from wherever the project is hosted, making sure that they exactly match the state of the binary. They would also need to locate the matching PDBs. That’s pretty hard to get right, and most users would generally not bother.&lt;/p&gt; &lt;p&gt;Now with almost no additional effort, package authors can publish their symbols and sources, and package consumers can debug into them from Visual Studio.&lt;/p&gt; &lt;h3&gt;What the package author needs to do&lt;/h3&gt; &lt;p&gt;Let’s first play the part of the author of a package that contains an assembly, which itself makes use of a library from another package. Let’s say that other package is &lt;a href="http://nuget.org/List/Packages/Clay" target="_blank"&gt;Clay&lt;/a&gt; as an example.&lt;/p&gt; &lt;h4&gt;Step 1: create a project&lt;/h4&gt; &lt;p&gt;Let’s start by creating a new Class Library project in VS. I’ll call it DavidSymbolSourceTest.&lt;/p&gt; &lt;h4&gt;Step 2: set some metadata on it&lt;/h4&gt; &lt;p&gt;This is an often forgotten step, but it is important to set some basic metadata on your assembly. As you’ll see later, it’s particularly important with this workflow. To do this, just open the Properties\AssemblyInfo.cs file and change a few values:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;[assembly: AssemblyTitle("DavidSymbolSourceTest")]
[assembly: AssemblyDescription("David's little test package to demonstrate easy package creation")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("David Ebbo")]
// Stuff omitted
[assembly: AssemblyVersion("0.5.0.0")]
&lt;/pre&gt;&lt;p&gt;Here, I set a description for the assembly, and put my name as the ‘Company’ (which is basically the author). I also changed the assembly version to 0.5.&lt;/p&gt;&lt;h4&gt;Step 3: bring in our dependencies using NuGet&lt;/h4&gt;&lt;p&gt;Next, let’s use NuGet to bring in our Clay dependency. I assume you’re familiar with the steps to do this, but in case you’re not, start &lt;a href="http://nuget.codeplex.com/documentation?title=Getting%20Started" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Note that because Clay itself has dependencies, this ends up bringing in 4 packages:&lt;/p&gt;&lt;p&gt;&lt;a href="http://lh3.ggpht.com/_jySMpScpTXc/Taa7SFoYEqI/AAAAAAAAAVs/JW3Yh_OUSEs/s1600-h/image%5B3%5D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_jySMpScpTXc/Taa7SkGDKKI/AAAAAAAAAVw/1Z1Hj0Fnrv8/image_thumb%5B1%5D.png?imgmax=800" width="208" height="93" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;h4&gt;Step 4: let’s write some code!&lt;/h4&gt;&lt;p&gt;In our library, we’ll just write some simple code that uses Clay:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;namespace DavidSymbolSourceTest {
 public class Demo {
     public static dynamic GetPersonObject(string first, string last) {
         dynamic New = new ClaySharp.ClayFactory();

         return New.Person(new {
             FirstName = first,
             LastName = last
         });
     }
 }
}
&lt;/pre&gt;&lt;p&gt;It just has a little test method with builds a Clay object based on two fields. Pretty boring stuff, but enough to demonstrate the concepts.&lt;/p&gt;&lt;h4&gt;Step 5: save your NuGet.org access key&lt;/h4&gt;&lt;p&gt;From here on, we’ll be using the NuGet.exe command line tool. Make sure you get the latest from &lt;a href="http://nuget.codeplex.com/releases/view/58939" target="_blank"&gt;here&lt;/a&gt;, or if you already have an older build, run ‘nuget update’ to self-update it.&lt;/p&gt;&lt;p&gt;Now go to &lt;a href="http://nuget.org/Contribute/MyAccount"&gt;http://nuget.org/Contribute/MyAccount&lt;/a&gt; to get your access key, and use nuget.exe save it so you don’t have to deal with it every time (so this is a one-time step, not for every project!). e.g.&lt;/p&gt;&lt;pre class="brush: plain;"&gt;D:\&amp;gt;nuget setapikey 5a50d497-522a-4436-bf90-b65362e65f52
The API Key '5a50d497-522a-4436-bf90-b65362e65f52' was saved for the NuGet
gallery feed (http://go.microsoft.com/fwlink/?LinkID=207106) and the symbol
server (http://nuget.gw.symbolsource.org/Public/NuGet).
&lt;/pre&gt;&lt;p&gt;Note: no, this is not actually my key, but thanks for asking! :)&lt;/p&gt;&lt;h4&gt;Step 6: specify additional metadata using a nuspec file&lt;/h4&gt;&lt;p&gt;In step 2, we added some metadata in AssemblyInfo.cs, which NuGet can directly understand. Unfortunately, some of the NuGet concepts don’t have a matching CLR attribute yet, so we still need a nuspec file to specify the rest.&lt;/p&gt;&lt;p&gt;To create one, just run ‘nuget spec’ from the folder where the csproj is.&lt;/p&gt;&lt;pre class="brush: plain;"&gt;D:\DavidSymbolSourceTest\DavidSymbolSourceTest&amp;gt;nuget spec
Created 'DavidSymbolSourceTest.nuspec' successfully.
&lt;/pre&gt;&lt;p&gt;NuGet.exe detects that the nuspec file is meant as a ‘companion’ to a VS project, and will generate a file with replacement tokens. e.g.&lt;/p&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;?xml version="1.0"?&amp;gt;
&amp;lt;package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"&amp;gt;
&amp;lt;metadata&amp;gt;
  &amp;lt;id&amp;gt;$id$&amp;lt;/id&amp;gt;
  &amp;lt;version&amp;gt;$version$&amp;lt;/version&amp;gt;
  &amp;lt;authors&amp;gt;$author$&amp;lt;/authors&amp;gt;
  &amp;lt;owners&amp;gt;$author$&amp;lt;/owners&amp;gt;
  &amp;lt;licenseUrl&amp;gt;http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE&amp;lt;/licenseUrl&amp;gt;
  &amp;lt;projectUrl&amp;gt;http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE&amp;lt;/projectUrl&amp;gt;
  &amp;lt;iconUrl&amp;gt;http://ICON_URL_HERE_OR_DELETE_THIS_LINE&amp;lt;/iconUrl&amp;gt;
  &amp;lt;requireLicenseAcceptance&amp;gt;false&amp;lt;/requireLicenseAcceptance&amp;gt;
  &amp;lt;description&amp;gt;$description$&amp;lt;/description&amp;gt;
  &amp;lt;tags&amp;gt;Tag1 Tag2&amp;lt;/tags&amp;gt;
&amp;lt;/metadata&amp;gt;
&amp;lt;/package&amp;gt;
&lt;/pre&gt;Note how a number of the fields use a token syntax like $version$. This basically means: I don’t want to repeat what’s already in my AssemblyInfo.cs, so just get values from there.
&lt;p&gt;Now all you need to do is:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Fill in the fields you care about, like &amp;lt;projectUrl&amp;gt;&lt;/li&gt;&lt;li&gt;Remove the ones you don’t care about. e.g. &amp;lt;iconUrl&amp;gt; if you don’t have an icon.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Note that technically, this whole step is optional, and you can omit the nuspec file entirely if you don’t need any metadata other than what’s in AssemblyInfo.cs. However, since all packages are &lt;em&gt;supposed&lt;/em&gt; to specify a &amp;lt;projectUrl&amp;gt; and a &amp;lt;licenseUrl&amp;gt;, in practice it’s not a step you’ll want to skip.&lt;/p&gt;&lt;h4&gt;Step 7: create the package&lt;/h4&gt;&lt;p&gt;This is where the new and exciting stuff really starts. Go to the folder where the csproj file is and run:&lt;/p&gt;&lt;pre class="brush: plain;"&gt;D:\DavidSymbolSourceTest\DavidSymbolSourceTest&amp;gt;nuget pack -sym DavidSymbolSourceTest.csproj
Attempting to build package from 'DavidSymbolSourceTest.csproj'.
Building project for target framework '.NETFramework,Version=v4.0'.
Packing files from 'D:\DavidSymbolSourceTest\DavidSymbolSourceTest\bin\Release'.
Found packages.config. Using packages listed as dependencies
Successfully created package 'D:\DavidSymbolSourceTest\DavidSymbolSourceTest\DavidSymbolSourceTest.0.5.nupkg'.

Attempting to build symbols package for 'DavidSymbolSourceTest.csproj'.
Building project for target framework '.NETFramework,Version=v4.0'.
Packing files from 'D:\DavidSymbolSourceTest\DavidSymbolSourceTest\bin\Release'.
Found packages.config. Using packages listed as dependencies
Successfully created package 'D:\DavidSymbolSourceTest\DavidSymbolSourceTest\DavidSymbolSourceTest.0.5.symbols.nupkg'.
&lt;/pre&gt;&lt;p&gt;Note that we are passing the -sym flag to the ‘nuget pack’ command, and that we’re giving it as input the csproj file!&lt;/p&gt;&lt;p&gt;The command will build the project if needed, and then create both a regular package (DavidSymbolSourceTest.0.5.nupkg) and a ‘symbolsource’ package (DavidSymbolSourceTest.0.5.symbols.nupkg).&lt;/p&gt;&lt;p&gt;Note how it used the version we had specified in AssemblyInfo.cs in step 2. Likewise, the Author and Description in the package came from there. This happens because of the token replacement logic from step 6.&lt;/p&gt;&lt;p&gt;In addition to the metadata inherited from AssemblyInfo.cs, the package will contain the metadata you explicitly added to the nuspec file, like the Project Url.&lt;/p&gt;&lt;p&gt;And one more thing: it also found our dependency on Clay and added that in the package, again without having to add that explicitly to the nuspec file!&lt;/p&gt;&lt;h4&gt;Step 8: push the packages to NuGet.org and SymbolSource.org&lt;/h4&gt;&lt;p&gt;Now that we created the packaged, we just need to push them out: one goes to NuGet.org and the other one the SymbolSource.org. This can all be done in one command:&lt;/p&gt;&lt;pre class="brush: plain;"&gt;D:\DavidSymbolSourceTest\DavidSymbolSourceTest&amp;gt;nuget push DavidSymbolSourceTest.0.5.nupkg
Pushing DavidSymbolSourceTest 0.5 to the NuGet gallery feed (http://go.microsoft.com/fwlink/?LinkID=207106)...
Publishing DavidSymbolSourceTest 0.5 to the NuGet gallery feed (http://go.microsoft.com/fwlink/?LinkID=207106)...
Your package was published.

Pushing DavidSymbolSourceTest 0.5 to the symbol server (http://nuget.gw.symbolsource.org/Public/NuGet)...
Publishing DavidSymbolSourceTest 0.5 to the symbol server (http://nuget.gw.symbolsource.org/Public/NuGet)...
Your package was published.

&lt;/pre&gt;Note that we ran ‘nuget push’ on the main package, and it automatically pushed the symbol package at the same time.&lt;div&gt;
&lt;/div&gt;&lt;div&gt;And now we’re done, our package is live and ready to be installed from NuGet and debugged with full sources!

&lt;h3&gt;What the package Consumer needs to do&lt;/h3&gt;&lt;p&gt;Now let’s play the part of the package Consumer that uses this package. Here I’ll demonstrate using a simple Console app, though the steps apply equally well to other apps.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Important note&lt;/strong&gt;: these steps are more interesting when done on a different machine than the ‘Package Author’ steps! If you do them on the same machine, rename or delete the Author project to make sure VS doesn’t take any shortcuts on you when debugging (which it will!).&lt;/p&gt;&lt;h4&gt;Step 1: set up the VS debugger settings&lt;/h4&gt;&lt;p&gt;This is a one time setup step. In VS, go under Debug / Options and Settings, and make a few changes:&lt;/p&gt;&lt;ul&gt;
&lt;li&gt;Under General, turn &lt;strong&gt;off&lt;/strong&gt; “Enable Just My Code”
&lt;/li&gt;&lt;li&gt;Under General, turn &lt;strong&gt;on&lt;/strong&gt; “Enable source server support”. You may have to Ok a security warning.
&lt;/li&gt;&lt;li&gt;Under Symbols, add “http://srv.symbolsource.org/pdb/Public” t the list. Dialog will look like this:&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;a href="http://lh6.ggpht.com/_jySMpScpTXc/Taa7TKJfA5I/AAAAAAAAAV0/m0didPJc_o4/s1600-h/image%5B8%5D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_jySMpScpTXc/Taa7TdcTz7I/AAAAAAAAAV4/kZYcxrs7zeY/image_thumb%5B4%5D.png?imgmax=800" width="362" height="335" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;
&lt;/p&gt;&lt;h4&gt;Step 2: create a test console app&lt;/h4&gt;&lt;p&gt;Make sure you set its Target Framework to the Server profile (see my previous &lt;a href="http://blog.davidebbo.com/2011/02/creating-console-apps-that-use-server.html" target="_blank"&gt;post&lt;/a&gt;).&lt;/p&gt;&lt;h4&gt;Step 3: use NuGet to bring in our test package&lt;/h4&gt;&lt;p&gt;Here is what you’ll see in the Online tab of the NuGet dialog:&lt;/p&gt;&lt;p&gt;&lt;a href="http://lh3.ggpht.com/_jySMpScpTXc/Taa7T2Zd-kI/AAAAAAAAAV8/plqJXqpzbJQ/s1600-h/image%5B17%5D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_jySMpScpTXc/Taa7UfAnx_I/AAAAAAAAAWA/wF-6qpF7PsE/image_thumb%5B9%5D.png?imgmax=800" width="571" height="303" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Notice that not only our new package shows up on the public feed, but all the metadata and package dependencies are there as well!&lt;/p&gt;&lt;p&gt;Now click Install to install the package and its dependencies.&lt;/p&gt;&lt;h4&gt;Step 4: write some test code to use the package&lt;/h4&gt;&lt;p&gt;We’ll just call the method we defined and display some output:&lt;/p&gt;&lt;pre class="brush: plain;"&gt;using System;

namespace ConsoleApplication12 {
 class Program {
     static void Main(string[] args) {
         var person = DavidSymbolSourceTest.Demo.GetPersonObject("David", "Ebbo");
         Console.WriteLine("{0} {1}", person.FirstName, person.LastName);
     }
 }
}

&lt;/pre&gt;&lt;h4&gt;Step 5: debug into the package!&lt;/h4&gt;&lt;p&gt;This is the final step that makes it all worth it! Set a breakpoint on the line that calls our GetPersonObject method and press F5 to start debugging.&lt;/p&gt;&lt;p&gt;When you hit the breakpoint, click F11 and be amazed!&lt;/p&gt;&lt;p&gt;&lt;a href="http://lh4.ggpht.com/_jySMpScpTXc/Taa7Uh__OFI/AAAAAAAAAWE/kOPXRYs-Msg/s1600-h/image%5B21%5D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_jySMpScpTXc/Taa7U2KXEYI/AAAAAAAAAWI/TKhIIEDnUYQ/image_thumb%5B11%5D.png?imgmax=800" width="511" height="171" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Here we are debugging into our new package. Here both the sources and PDB files are coming straight from SymbolSource.org!&lt;/p&gt;&lt;h3&gt;Registering with SymbolSource.org&lt;/h3&gt;&lt;p&gt;Note that in all the steps below, we never actually went to the &lt;a href="http://www.symbolsource.org/"&gt;http://www.symbolsource.org/&lt;/a&gt; web site. The nice thing is that everything can work without even setting up an account on there. Note that SymbolSource &lt;em&gt;does&lt;/em&gt; verify that you own the package by checking with nuget.org using your key.&lt;/p&gt;&lt;p&gt;But even though the registration step is optional, it is recommended that you register with the site in order to be able to manage the symbol packages that you upload there. To register, just go to &lt;a href="http://www.symbolsource.org/"&gt;http://www.symbolsource.org/&lt;/a&gt; and follow the instructions. During registration, you’ll be asked for your NuGet key, which is how your account will get associated with your submissions.&lt;/p&gt;  &lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/ZHoZzq4Ubx4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/3267069173334371924/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2011/04/easy-way-to-publish-nuget-packages-with.html#comment-form" title="32 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/3267069173334371924?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/3267069173334371924?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/ZHoZzq4Ubx4/easy-way-to-publish-nuget-packages-with.html" title="The easy way to publish NuGet packages with sources" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/_jySMpScpTXc/Taa7SkGDKKI/AAAAAAAAAVw/1Z1Hj0Fnrv8/s72-c/image_thumb%5B1%5D.png?imgmax=800" height="72" width="72" /><thr:total>32</thr:total><feedburner:origLink>http://blog.davidebbo.com/2011/04/easy-way-to-publish-nuget-packages-with.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0AMR3Y7eSp7ImA9WhZSGU0.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-5576104375479732833</id><published>2011-04-04T00:19:00.001-07:00</published><updated>2011-04-04T00:23:06.801-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-04-04T00:23:06.801-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Visual Studio" /><title>Open your solution files as admin</title><content type="html">&lt;p&gt;When you run under UAC (User Account Control), nothing runs as admin by default, and that’s a good thing! But sometimes, you do need to run some things as administrator.&lt;/p&gt; &lt;p&gt;There are a few well known ways of doing this. You can right click on an EXE and choose ‘Run As Admin’. Or if you have the app pinned on your taskbar, you can Ctrl-Shift click it to run as admin. If you don’t know those tricks, you should learn them as they often come handy.&lt;/p&gt; &lt;p&gt;However, there is one common scenario for which there is no well documented technique: how do you launch a program as admin &lt;strong&gt;from a data file&lt;/strong&gt;? Taking a particularly interesting example, how do you launch Visual Studio as admin from a .sln file?&lt;/p&gt; &lt;p&gt;First, you try the obvious and right click it, hoping to see the familiar ‘Run As Administrator’ item. But no luck there:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_jySMpScpTXc/TZlxF9VXL7I/AAAAAAAAAVc/f_0dli30kOs/s1600-h/image%5B3%5D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_jySMpScpTXc/TZlxGJV5gMI/AAAAAAAAAVg/5hrIH2-SO2g/image_thumb%5B1%5D.png?imgmax=800" width="520" height="91" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;While this at first appears hopeless, it turns that there is a way to do this by adding some simple things to your registry.&lt;/p&gt; &lt;p&gt;The general technique is explained &lt;a href="http://www.howtogeek.com/howto/windows-vista/add-run-as-administrator-to-any-file-type-in-windows-vista/" target="_blank"&gt;here&lt;/a&gt; (thanks to &lt;a href="http://twitter.com/#!/Meligy" target="_blank"&gt;@meligy&lt;/a&gt; for pointing me to it). The post describes how to do it for any file type, but I can save you a bit of time by giving you the reg change you need to make (and it’s not scary!):&lt;/p&gt;&lt;pre class="brush: plain;"&gt;Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\VisualStudio.Launcher.sln\Shell\runas\Command]
@="\"C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\MSEnv\\VSLauncher.exe\" \"%1\""

&lt;/pre&gt;&lt;p&gt;Just save that in a foo.reg file somewhere and run it. After you do that, right clicking on a .sln file will look like this:&lt;/p&gt;&lt;p&gt;&lt;a href="http://lh5.ggpht.com/_jySMpScpTXc/TZlxGXVOpqI/AAAAAAAAAVk/LEOCOnKn6iY/s1600-h/image%5B16%5D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_jySMpScpTXc/TZlxGlLnnoI/AAAAAAAAAVo/7bDFLs5luQk/image_thumb%5B8%5D.png?imgmax=800" width="499" height="115" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;And that’s it, just what we wanted!&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Final note&lt;/strong&gt;: my reg file above is hard coded to “C:\\Program Files (x86)”, which won’t work on all systems so you may need to adjust things. I tried to change it to use the ProgramFiles(x86) env variable but I couldn’t make that work in the registry. Seems default values can’t be REG_EXPAND_SZ? Let me know if you know how to do this!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/NyPdcLF9WLU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/5576104375479732833/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2011/04/open-your-solution-files-as-admin.html#comment-form" title="20 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/5576104375479732833?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/5576104375479732833?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/NyPdcLF9WLU/open-your-solution-files-as-admin.html" title="Open your solution files as admin" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/_jySMpScpTXc/TZlxGJV5gMI/AAAAAAAAAVg/5hrIH2-SO2g/s72-c/image_thumb%5B1%5D.png?imgmax=800" height="72" width="72" /><thr:total>20</thr:total><feedburner:origLink>http://blog.davidebbo.com/2011/04/open-your-solution-files-as-admin.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEcDRXczeyp7ImA9WhZSGU0.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-1604561630846373567</id><published>2011-04-01T00:02:00.001-07:00</published><updated>2011-04-04T00:27:54.983-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-04-04T00:27:54.983-07:00</app:edited><title>New pricing model for NuGet</title><content type="html">&lt;p&gt;&lt;i&gt;Update: In case that's not totally obvious, this post was an April Fool's hoax. A number of people got briefly fooled on the day, which was the idea! Now that April 1st is behind us, I may as well make this super clear :)&lt;/i&gt;&lt;/p&gt;&lt;p&gt;
&lt;/p&gt;&lt;p&gt;Since we launched NuGet in January, its popularity has grown faster than we anticipated. A couple days ago, we reached an important milestone with over 1000 unique packages (see &lt;a href="http://stats.nuget.org/"&gt;http://stats.nuget.org/&lt;/a&gt; for more fun numbers).&lt;/p&gt; &lt;p&gt;Up until now, NuGet has an been entirely free offering both for package authors and consumers. This free model has surely helped contribute to the growth of NuGet, and we are glad to have taken this approach.&lt;/p&gt; &lt;p&gt;Now that NuGet is more mature and has reached fairly wide acceptance, we have decided to switch to a pay model. This is actually something we had been planning from the start, but we chose not to announce early as it may have hindered our initial growth.&lt;/p&gt; &lt;h3&gt;How will the pay model work&lt;/h3&gt; &lt;p&gt;For the most part, it will be similar to the pricing models used in popular phone app stores (though apparently we can’t use that term!). There will be a mix of free and pay packages, based on the author’s decision.&lt;/p&gt; &lt;p&gt;As an example, the basic Fart package might be free, while SuperFarter will be priced at 99c. The more feature rich MegaFarter package may cost as much as $2.99 with all the bells and whistles, though in the end the pricing decision is up to the author.&lt;/p&gt; &lt;p&gt;When you buy a package, you will be allowed 10 downloads of that package for free, after which you will be able to ‘reload’ your purchase at the original price to get 5 more downloads. Why not allow unlimited downloads once you buy a package? Based on our studies, we found that not only the patented ‘reload’ model will end up being more profitable, but by making the user think a bit more about where they choose to use a package, the average quality of the resulting software actually increases (this surprised us as well, but the results were clear).&lt;/p&gt; &lt;p&gt;So that’s the story for the consumer, but what about the author? We deliberated for a while on this, and decided on sharing as much as 5% of the package income with the author. That number was partially inspired by the fact that it is tax season, and that the Beatles wisely wrote in their Taxman song:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;Let me tell you how it will be. There’s one for you, nineteen for me.
Should five per cent appear too small. Be thankful I don’t take it all.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;The last part is key, as we will in fact reserve the right to take it all in certain scenarios. &lt;/p&gt;&lt;p&gt;  &lt;/p&gt;&lt;h3&gt;Everyone is #winning!&lt;/h3&gt; &lt;p&gt;While this is a departure from the current model, this new pricing model will end up benefiting everyone:&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Authors&lt;/strong&gt; win by getting a share of the revenue. To put the 5% in perspective, everyone 20 million downloads of your 99c package, you’ll be making almost a million dollars. We’re talking real money!&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Consumers&lt;/strong&gt; win by getting higher quality packages. With the current free model, there isn’t as much incentive for authors to put hard work into their packages. But with money at stake, we expect it’ll be a different landscape. So packages will do things that you don’t even know are possible today.&lt;/p&gt; &lt;p&gt;Last but not least, &lt;strong&gt;the NuGet team&lt;/strong&gt; wins. Most of the money will end up there, so that should be self-obvious. But we will put it to good use. For instance we will upgrade our cars, which will allow us to get to work fresher in the morning, and make NuGet even more awesome that it is today.&lt;/p&gt; &lt;p&gt;I hope you are all sharing our excitement about this game changing announcement!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/Onm8hZ3FbXI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/1604561630846373567/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2011/04/new-pricing-model-for-nuget.html#comment-form" title="5 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/1604561630846373567?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/1604561630846373567?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/Onm8hZ3FbXI/new-pricing-model-for-nuget.html" title="New pricing model for NuGet" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><thr:total>5</thr:total><feedburner:origLink>http://blog.davidebbo.com/2011/04/new-pricing-model-for-nuget.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DU4HRHc_fCp7ImA9WhdTFUU.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-8286585495782569838</id><published>2011-03-11T17:16:00.001-08:00</published><updated>2011-07-13T13:12:15.944-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-13T13:12:15.944-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="NuGet" /><title>Saving your API key with nuget.exe</title><content type="html">&lt;p&gt;While you can push NuGet packages from &lt;a href="http://nuget.org/"&gt;http://nuget.org/&lt;/a&gt;, it is often more convenient to do it straight from the command line using nuget.exe.&lt;/p&gt; &lt;p&gt;Phil did a nice &lt;a href="http://haacked.com/archive/2011/01/12/uploading-packages-to-the-nuget-gallery.aspx"&gt;post&lt;/a&gt; on how that works, which you should read first if you have not done this before.&lt;/p&gt; &lt;p&gt;The one pain point about this technique is that you need to find your API key every time you push a package. I have had to go to &lt;a href="http://nuget.org/Contribute/MyAccount"&gt;http://nuget.org/Contribute/MyAccount&lt;/a&gt; each time to locate my key, copied it and pasted it on the command line. It gets old quickly! :)&lt;/p&gt; &lt;p&gt;The good news is that the newest version of nuget.exe (get it &lt;a href="http://nuget.codeplex.com/releases/view/58939"&gt;here&lt;/a&gt;) lets you save it once and for all! Credit goes to &lt;a href="http://twitter.com/#!/osbornm"&gt;Matthew Osborn&lt;/a&gt; for this new feature.&lt;/p&gt; &lt;p&gt;Here is how it works.&lt;/p&gt; &lt;h3&gt;Saving your key&lt;/h3&gt; &lt;p&gt;First, you run the new SetAPIKey command, e.g.&lt;/p&gt;&lt;pre class="brush: plain;"&gt;D:\test&amp;gt;nuget SetApiKey 78a53314-c2c0-45c6-9d92-795b2096ae6c
The API Key '78a53314-c2c0-45c6-9d92-795b2096ae6c' was saved for the source 'http://go.microsoft.com/fwlink/?LinkID=207106'.

&lt;/pre&gt;&lt;p&gt;This encrypts the key and saves it in a config file under your %APPDATA% folder. e.g. mine ends up in C:\Users\davidebb\AppData\Roaming\NuGet\NuGet.Config. This file contains:&lt;/p&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;configuration&amp;gt;
&amp;lt;apikeys&amp;gt;
  &amp;lt;add key="http://go.microsoft.com/fwlink/?LinkID=207106" value="AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAnMGkdu4+rkqpSdQUWwjfIgAAAAACAAAAAAADZgAAwAAAABAAAAA5gG4wxeb8Vn4X0Y0p//OvAAAAAASAAACgAAAAEAAAAF/llublBpBgL9lSFaE9/A0oAAAAC4NVHflYsUU5UgVgOq+h3t1jwY6l2BEji6Td4F0lvxsZcZ73L2m6BRQAAABJ0TZLKdIYStn8DWawbtzdo3mrKg==" /&amp;gt;
&amp;lt;/apikeys&amp;gt;
&amp;lt;/configuration&amp;gt;

&lt;/pre&gt;&lt;p&gt;Note that the key is saved per server URL, with the server defaulting to nuget.org (you can pass -src to change that).&lt;/p&gt;&lt;h3&gt;Using the saved key&lt;/h3&gt;&lt;p&gt;Once you have done this one-time step, pushing packages becomes a breeze, as the only thing you need to pass is your package file. e.g.&lt;/p&gt;&lt;pre class="brush: plain;"&gt;D:\test&amp;gt;nuget push DavidTest.1.0.nupkg
Publishing DavidTest 1.0 to the live feed...
Your package was published to the feed.

&lt;/pre&gt;&lt;p&gt;Likewise, if you want to delete a package, you’d do:&lt;/p&gt;&lt;pre class="brush: plain;"&gt;D:\test&amp;gt;nuget delete -noprompt DavidTest 1.0
Deleting DavidTest 1.0 from the server.
DavidTest 1.0 was deleted from the server
&lt;/pre&gt;&lt;p&gt;Hopefully this will make your NuGet package management experience a little bit easier!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/wi0Bo5PfUUM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/8286585495782569838/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2011/03/saving-your-api-key-with-nugetexe.html#comment-form" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/8286585495782569838?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/8286585495782569838?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/wi0Bo5PfUUM/saving-your-api-key-with-nugetexe.html" title="Saving your API key with nuget.exe" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><thr:total>4</thr:total><feedburner:origLink>http://blog.davidebbo.com/2011/03/saving-your-api-key-with-nugetexe.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkYNRXs5cCp7ImA9WhdQFUs.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-5506296071315714803</id><published>2011-03-10T18:07:00.001-08:00</published><updated>2011-08-16T23:56:34.528-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-16T23:56:34.528-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="NuGet" /><title>Using NuGet without committing packages</title><content type="html">&lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Update (8/16/2011): also check out this &lt;/strong&gt;&lt;a href="http://blog.davidebbo.com/2011/08/easy-way-to-set-up-nuget-to-restore.html" target="_blank"&gt;&lt;strong&gt;newer post&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; that describes an easier way to set up this workflow.&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;The current NuGet workflow has always been to commit the Packages folder into source control. The reasoning is that it matches what developers typically do when they don’t have NuGet: they create a ‘Lib’ or ‘ExternalDependencies’ folder, dump binaries into there and commit them to source control to allow others to build.&lt;/p&gt; &lt;p&gt;While this has worked fine for some users, we have also heard from many that committing packages into source control is not what they want to do. When using a DVCS like Mercurial or Git, committing binaries can grow the repository size like crazy over time, making cloning more and more painful. In fact, this has been &lt;a href="http://nuget.codeplex.com/workitem/165"&gt;one of the top requests&lt;/a&gt; on NuGet our issue tracker.&lt;/p&gt; &lt;p&gt;The good news is that NuGet now offers a workflow which goes a long way to solving this problem. It isn’t 100% automated yet, but with some minimal pain you can set up your project to do this.&lt;/p&gt; &lt;h3&gt;Running ‘nuget install’ on a packages.config file&lt;/h3&gt; &lt;p&gt;Earlier, I blogged about how you can &lt;a href="http://blog.davidebbo.com/2011/01/installing-nuget-packages-directly-from.html"&gt;install NuGet packages from the command line&lt;/a&gt; by using NuGet.exe.&lt;/p&gt; &lt;p&gt;Get NuGet.exe from &lt;a href="http://nuget.codeplex.com/releases/view/58939"&gt;here&lt;/a&gt; if you don’t already have it, and run ‘nuget -update’ to self-update it.&lt;/p&gt; &lt;p&gt;This lets you install one package at a time, e.g.&lt;/p&gt;&lt;pre class="brush: plain;"&gt;D:\Mvc3Application&amp;gt;nuget install NHibernate -o Packages
&lt;/pre&gt;
&lt;p&gt;As an aside, the -o flag is new and lets you specify where the package is installed.&lt;/p&gt;
&lt;p&gt;But the big new thing is that you can now run it on a packages.config file. packages.config is a file that NuGet creates at the root of every project that has packages installed. So if you install the ‘EFCodeFirst.Sample’ package in your app, you’ll find a packages.config next to the .csproj file, and it will contain:&lt;/p&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;packages&amp;gt;
&amp;lt;package id="EFCodeFirst" version="0.8" /&amp;gt;
&amp;lt;package id="EFCodeFirst.Sample" version="0.8" /&amp;gt;
&amp;lt;/packages&amp;gt;
&lt;/pre&gt;
&lt;p&gt;So this holds all the information about what packages are needed for your project. Suppose you don’t commit your Packages folder (which lives under the solution folder), and another developer clones your repository. They can now run:&lt;/p&gt;&lt;pre class="brush: plain;"&gt;D:\Mvc3Application&amp;gt;nuget i Mvc3Application\packages.config -o Packages
Successfully installed 'EFCodeFirst 0.8'.
Successfully installed 'EFCodeFirst.Sample 0.8'.
&lt;/pre&gt;
&lt;p&gt;And the Packages will be restored! The other nice thing is that this command is smart enough not to do any expensive work if they are already installed, e.g.&lt;/p&gt;&lt;pre class="brush: plain;"&gt;D:\Mvc3Application&amp;gt;nuget i Mvc3Application\packages.config -o Packages
All packages listed in packages.config are already installed.
&lt;/pre&gt;
&lt;p&gt;This completes very quickly with no network requests.&lt;/p&gt;
&lt;h3&gt;Integrating package restore into msbuild&lt;/h3&gt;
&lt;p&gt;Integrating this into your build is a simple matter of adding a Pre-build event.&lt;/p&gt;
&lt;p&gt;First, I would suggest committing nuget.exe into your solution, e.g. under a Tools folder. Once you do that, you can then add the following Pre-build event:&lt;/p&gt;&lt;pre class="brush: plain;"&gt;$(SolutionDir)Tools\nuget install $(ProjectDir)packages.config -o $(SolutionDir)Packages
&lt;/pre&gt;
&lt;p&gt;Note how packages.config lives under the &lt;em&gt;project&lt;/em&gt; folder while the Packages folder lives under the &lt;em&gt;solution&lt;/em&gt; folder.&lt;/p&gt;
&lt;p&gt;And that’s it, you’re done! Now each time you build, NuGet will first make sure that you have all the packages that you need, and will download anything that’s missing from the live feed.&lt;/p&gt;
&lt;p&gt;If your solution has multiple projects that use NuGet, add the same Pre-Build event to each project.&lt;/p&gt;
&lt;p&gt;As an alternative, you can use an msbuild custom build target to achieve the same thing. Check out Danny Tuppeny's &lt;a href="http://blog.dantup.com/2011/05/setting-up-nuget-to-automatically-fetch-packages-when-deploying-to-appharbor-without-storing-binaries-in-source-control"&gt;post&lt;/a&gt; for details on that. This worked better for him when using App Harbor.&lt;/p&gt;
&lt;h3&gt;We want your feedback&lt;/h3&gt;
&lt;p&gt;This is new, so it’s possible that it doesn’t quite work perfectly in all cases. Please let us know how it works for you: bugs, feedback, suggestion. Thanks!&lt;/p&gt;  &lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/LXjsUefB8yg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/5506296071315714803/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2011/03/using-nuget-without-committing-packages.html#comment-form" title="65 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/5506296071315714803?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/5506296071315714803?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/LXjsUefB8yg/using-nuget-without-committing-packages.html" title="Using NuGet without committing packages" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><thr:total>65</thr:total><feedburner:origLink>http://blog.davidebbo.com/2011/03/using-nuget-without-committing-packages.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0IEQHc4cSp7ImA9Wx9aFkw.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-3513047693888958504</id><published>2011-03-08T01:01:00.001-08:00</published><updated>2011-03-08T12:18:21.939-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-08T12:18:21.939-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="NuGet" /><title>Take NuGet to the next level with sample packages</title><content type="html">&lt;p&gt;&lt;a href="http://nuget.org/" target="_blank"&gt;NuGet&lt;/a&gt; has drastically simplified the process of getting .NET libraries into your projects. What used to be an error prone and painful process has become as simple as adding an assembly reference.&lt;/p&gt; &lt;p&gt;While it has solved an important part of the developer workflow, it has the potential to also solve another key piece of the puzzle: helping user learn to use libraries.&lt;/p&gt; &lt;h3&gt;I found these cool packages, but now what?&lt;/h3&gt; &lt;p&gt;There are tons of cool packages available on NuGet today, and the number is growing daily. I’ve heard of a number of users who go down the list and install all kind of packages into their projects to try them out. But if you’re not familiar with a library, how do you get started with it?&lt;/p&gt; &lt;p&gt;As an example to illustrate the discussion, let’s take the nifty little Clay package written by the Orchard guys. Say you have installed it into your project and want to start using it. Here is what you might do:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;The NuGet dialog gives you a link to the ‘project URL’. Typically, it’s a link to where the project is hosted on CodePlex/BitBucket/github, and indeed this one takes you to &lt;a href="http://clay.codeplex.com/"&gt;http://clay.codeplex.com/&lt;/a&gt;.&lt;/li&gt; &lt;li&gt;Once you’re there, you try clicking on the Documentation tab. Unfortunately, many projects don’t have much there. But here it at least has a pointer to &lt;a href="http://twitter.com/#!/bleroy" target="_blank"&gt;Bertrand&lt;/a&gt;’s blog posts on the topic. So you now go to his &lt;a href="http://weblogs.asp.net/bleroy/archive/2010/08/18/clay-malleable-c-dynamic-objects-part-2.aspx" target="_blank"&gt;post&lt;/a&gt;.&lt;/li&gt; &lt;li&gt;You read through it, and after a while, you can piece together enough bits and pieces to know what it’s about and start using it into your code.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;I took Clay as an example, but this is a fairly typical experience. The fact is that a lot of knowledge about immature (yet useful) projects only exists in ‘blog post series’ rather than in any formal documentation. Not ideal, but that’s how things happen.&lt;/p&gt; &lt;h3&gt;NuGet to the rescue with Sample Packages&lt;/h3&gt; &lt;p&gt;Luckily, there is a simple and effective solution to this problem: use NuGet to distribute basic samples that get your users on the right path with less pain.&lt;/p&gt; &lt;p&gt;So to illustrate this post, I went ahead and created one such package for Clay: &lt;strong&gt;Clay.Sample&lt;/strong&gt;. This package depends on Clay, such that installing it also installs Clay (as well as other things Clay depends on, like Castle).&lt;/p&gt; &lt;p&gt;It’s a ‘source only’ package, meaning that it doesn’t contain any binaries of its own. So let’s go ahead and try it in a brand new Console app (and change it NOT to use the client profile). Go in NuGet’s ‘Add Library Reference’ dialog and search for Clay. You’ll get this:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_jySMpScpTXc/TXXwcRnP7UI/AAAAAAAAAUw/d8Od_Rzllf8/s1600-h/image%5B13%5D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_jySMpScpTXc/TXXwc4POocI/AAAAAAAAAU0/k-Gr7AnCT5E/image_thumb%5B7%5D.png?imgmax=800" width="800" height="450" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;After you install it, your project will look like this:&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_jySMpScpTXc/TXXwdTTRzZI/AAAAAAAAAU4/G_NZImNC1LU/s1600-h/image%5B19%5D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_jySMpScpTXc/TXXwdiVcNvI/AAAAAAAAAU8/zDQcBUpmZHw/image_thumb%5B13%5D.png?imgmax=800" width="312" height="372" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;First, note how you got all the expected references to Clay and to its dependencies: Castle.* and log4net.&lt;/p&gt; &lt;p&gt;But more interestingly, it also brought in a ClaySamples source file under Samples\Clay. It contains a number of Clay samples, which I shamelessly copied from Bertrand’s post. Here is one example:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;public static void AnonymousObject() {
   dynamic New = new ClayFactory();

   var person = New.Person(new {
       FirstName = "Louis",
       LastName = "Dejardin"
   });

   Console.WriteLine("{0} {1}", person.FirstName, person.LastName);
}
&lt;/pre&gt;
There are about 10 such samples in there, which demonstrate everything that the post discusses. Now go to your Console Main and make a call to a method that runs all the samples:
&lt;pre class="brush: csharp;"&gt;class Program {
   static void Main(string[] args) {
       Samples.Clay.ClaySamples.RunAll();
   }
}

&lt;/pre&gt;&lt;p&gt;While there is nothing in there that’s not in the blog post, the big advantage is that you can trivially get it into your project via NuGet, and you can then directly run/debug the samples without having to piece them together.&lt;/p&gt;&lt;p&gt;Of course, the blog post (or documentation) may still be worth reading for extra insight. But you may find that the samples give you all you need for now, and save the deeper reading for later.&lt;/p&gt;&lt;h3&gt;Call to packages authors: write Sample packages!&lt;/h3&gt;&lt;p&gt;I think this type of packages can have a huge impact on developer productivity. But for that to actually happen, those packages need to be created! And while I created the one for Clay, I am not volunteering to create all the sample packages :) Clearly, the best person to do that is the author of the package, though anyone who knows it well enough can certainly do it as well.&lt;/p&gt;&lt;p&gt;So if you own a NuGet package, please try to take on that task. It’s super easy, and your users will thank you for it!&lt;/p&gt;&lt;h3&gt;Conventions, conventions, conventions&lt;/h3&gt;&lt;p&gt;I recently blogged about using the &lt;a href="http://blog.davidebbo.com/2011/02/appstart-folder-convention-for-nuget.html" target="_blank"&gt;App_Start convention&lt;/a&gt; for WebActivator startup code and got a great response, with almost all WebActivator users converting their existing packages to use this.&lt;/p&gt;&lt;p&gt;The situation here is quite similar, and calls for a similar convention, which is what I showed above. In a nutshell:&lt;/p&gt;&lt;ul&gt;
&lt;li&gt;If your package is named Blah, call the sample package Blah.Sample. If you want multiple sample packages, you can call them Blah.Sample.&lt;i&gt;Something &lt;/i&gt;and Blah.Sample.&lt;i&gt;SomethingElse&lt;/i&gt;.&lt;/li&gt;
&lt;li&gt;Make your Blah.Sample package dependent on Blah.&lt;/li&gt;
&lt;li&gt;Within that package, just include source files. Place those file under the Samples\Blah. You can have one or more, and call them whatever you think make sense.&lt;/li&gt;
&lt;li&gt;The code on there is up to you, but the general idea to to include whatever you think will help the user get started. Try to make the sample code &lt;strong&gt;easily runnable&lt;/strong&gt; without too much extra setup. This may be harder for some packages, but do your best :)&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Creating the package&lt;/h3&gt;&lt;p&gt;Taking Clay as an example, here is the structure of the files before packing them into a nupkg:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;├  Clay.Sample.nuspec
└──Content
└──Samples
 └──Clay
    └  ClaySamples.cs.pp&lt;/pre&gt;&lt;p&gt;So there are just two files, the nuspec and the preprocessed sample file. Here is the nuspec:&lt;/p&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;?xml version="1.0"?&amp;gt;
&amp;lt;package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&amp;gt;
&amp;lt;metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"&amp;gt;
&amp;lt;id&amp;gt;Clay.Sample&amp;lt;/id&amp;gt;
&amp;lt;version&amp;gt;1.0&amp;lt;/version&amp;gt;
&amp;lt;authors&amp;gt;Outercurve Foundation&amp;lt;/authors&amp;gt;
&amp;lt;owners&amp;gt;Outercurve Foundation&amp;lt;/owners&amp;gt;
&amp;lt;licenseUrl&amp;gt;http://www.opensource.org/licenses/ms-pl&amp;lt;/licenseUrl&amp;gt;
&amp;lt;projectUrl&amp;gt;http://clay.codeplex.com&amp;lt;/projectUrl&amp;gt;
&amp;lt;requireLicenseAcceptance&amp;gt;false&amp;lt;/requireLicenseAcceptance&amp;gt;
&amp;lt;description&amp;gt;This package contains samples that demonstrate the use of the Clay library.&amp;lt;/description&amp;gt;
&amp;lt;language&amp;gt;en-US&amp;lt;/language&amp;gt;
&amp;lt;dependencies&amp;gt;
&amp;lt;dependency id="Clay" version="1.0" /&amp;gt;
&amp;lt;/dependencies&amp;gt;
&amp;lt;/metadata&amp;gt;
&amp;lt;/package&amp;gt;
&lt;/pre&gt;&lt;p&gt;The interesting parts here are the package Id, the description, and the dependency on Clay.&lt;/p&gt;&lt;p&gt;Then ClaySamples.cs.pp is a normal source file, except for a tiny bit of preprocessing for the namespace, e.g.&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;using System;
using ClaySharp;

namespace $rootnamespace$.Samples.Clay {
   public static class ClaySamples {
      // Sample code here
   }
}

&lt;/pre&gt;And that’s it! Once you have that, just run ‘nuget pack’ from the folder with the nuspec, and you’ll have a sample package ready to be pushed to the feed.&lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/m68g9V4RlLA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/3513047693888958504/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2011/03/take-nuget-to-next-level-with-sample.html#comment-form" title="18 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/3513047693888958504?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/3513047693888958504?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/m68g9V4RlLA/take-nuget-to-next-level-with-sample.html" title="Take NuGet to the next level with sample packages" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/_jySMpScpTXc/TXXwc4POocI/AAAAAAAAAU0/k-Gr7AnCT5E/s72-c/image_thumb%5B7%5D.png?imgmax=800" height="72" width="72" /><thr:total>18</thr:total><feedburner:origLink>http://blog.davidebbo.com/2011/03/take-nuget-to-next-level-with-sample.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DE8FQngyfSp7ImA9WhRXFEg.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-9078624311767027528</id><published>2011-03-06T22:24:00.001-08:00</published><updated>2011-12-21T00:40:13.695-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-21T00:40:13.695-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MVC" /><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><title>Using a custom build of MVC 3</title><content type="html">&lt;p&gt;&lt;em&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt;: running a custom build of MVC 3 is not recommended in most scenarios. Please run against the official MVC 3 bits unless you really cannot. Be aware that using custom builds will make it harder to use 3rd party libraries built against the official bits (you’ll need to rebuild those libraries).&lt;/em&gt;&lt;/p&gt; &lt;p&gt;One nice thing about ASP.NET MVC is that you &lt;a href="http://aspnet.codeplex.com/releases/view/58781" target="_blank"&gt;can get the full sources on CodePlex&lt;/a&gt; and compile them yourself.&lt;/p&gt; &lt;p&gt;Once you copy the sources locally, you can open the WebRuntime solution in VS 2010 and build it. As an aside, note that this solution also contains the ASP.NET WebPages sources, since MVC3 makes you of some of that logic (mostly for Razor support).&lt;/p&gt; &lt;p&gt;So this lets you modify the sources and build everything. However, one thing that makes the use of the resulting assemblies a bit tricky is that unlike the official bits, the bits produced by this solution are unsigned.&lt;/p&gt; &lt;p&gt;Let’s take this step by step.&lt;/p&gt; &lt;h3&gt;Step 1: Create a new MVC 3 application&lt;/h3&gt; &lt;p&gt;So let’s start by creating a new MVC 3 Web Application using the regular project template that come from installing MVC 3.&lt;/p&gt; &lt;p&gt;This gives you a working app, but obviously at this point you're still using the official MVC 3 bits.&lt;/p&gt; &lt;h3&gt;Step 2: Reference your custom assemblies&lt;/h3&gt; &lt;p&gt;The next step is to reference your custom MVC assemblies. Start by removing the System.Web.Mvc and System.Web.WebPages references. Instead, reference the version you’ve built of those same assemblies, which you’ll find under mvc3\bin\Debug (from the root of the WebRuntime solution).&lt;/p&gt; &lt;p&gt;Once you do that, your MVC project will build fine. However, if you try running it, you’ll get some scary looking runtime compilation error. Something like:&lt;/p&gt;&lt;pre class="brush: plain;"&gt;CS0433: The type 'System.Web.Mvc.WebViewPage&amp;lt;TModel&amp;gt;' exists in both 'c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Web.Mvc\v4.0_3.0.0.0__31bf3856ad364e35\System.Web.Mvc.dll' and 'c:\Users\David\AppData\Local\Temp\Temporary ASP.NET Files\root\d305385c\948d4291\assembly\dl3\ef116fd6\5f110ce1_44dccb01\System.Web.Mvc.DLL'
&lt;/pre&gt;&lt;p&gt;The reason this happens is that while you’ve changed the &lt;strong&gt;project references&lt;/strong&gt; to point to your assembly, the two web.config files that come with the project template are still pointing to the official assemblies left and right. Which leads us to…&lt;/p&gt;&lt;h3&gt;Step 3: Fix up your web.config files&lt;/h3&gt;&lt;p&gt;The project comes with two web.config files, and they each contain all kind of references to the official assemblies (which are strong name). e.g. in the root web.config, you’ll find:&lt;/p&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&amp;gt;
&amp;lt;add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&amp;gt;
&lt;/pre&gt;Luckily, the fix is as simple as yanking the strong name from a few assemblies. This is easily done using a project-wide search/replace. Specifically, do the following three replacements:
&lt;p&gt;1. Replace all instances of (&lt;strong&gt;excluding the quotes!&lt;/strong&gt;)&lt;/p&gt;&lt;p&gt;“System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35”&lt;/p&gt;&lt;p&gt;by&lt;/p&gt;&lt;p&gt;“System.Web.Mvc”&lt;/p&gt;&lt;p&gt;2. Replace all instances of&lt;/p&gt;&lt;p&gt;“System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35”&lt;/p&gt;&lt;p&gt;by&lt;/p&gt;&lt;p&gt;“System.Web.WebPages”&lt;/p&gt;&lt;p&gt;3. Replace all instances of&lt;/p&gt;&lt;p&gt;“System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35”&lt;/p&gt;&lt;p&gt;by&lt;/p&gt;&lt;p&gt;“System.Web.WebPages.Razor”&lt;/p&gt;&lt;p&gt;And that should be it. Your app will now be up and running against your custom MVC bits.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/8tN91EP5K9Q" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/9078624311767027528/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2011/03/using-custom-build-of-mvc-3.html#comment-form" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/9078624311767027528?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/9078624311767027528?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/8tN91EP5K9Q/using-custom-build-of-mvc-3.html" title="Using a custom build of MVC 3" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><thr:total>4</thr:total><feedburner:origLink>http://blog.davidebbo.com/2011/03/using-custom-build-of-mvc-3.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkcGQ3g7fSp7ImA9Wx9aEE8.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-400214190627907649</id><published>2011-02-25T00:03:00.001-08:00</published><updated>2011-03-01T16:00:22.605-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-01T16:00:22.605-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WebActivator" /><category scheme="http://www.blogger.com/atom/ns#" term="NuGet" /><title>App_Start folder convention for NuGet and WebActivator</title><content type="html">&lt;p&gt;&lt;/p&gt;&lt;p&gt;[Please see the &lt;a href="https://bitbucket.org/davidebbo/webactivator/wiki/Home"&gt;WebActivator wiki&lt;/a&gt; for the latest docs]&lt;/p&gt;&lt;div&gt;When I first &lt;a href="http://blogs.msdn.com/b/davidebb/archive/2010/10/11/light-up-your-nupacks-with-startup-code-and-webactivator.aspx" target="_blank"&gt;blogged&lt;/a&gt; about WebActivator, I showed in my example using a source file named AppStart_SparkMvc.cs.pp under the Content folder in the package, which means when you install it you end up with a file named AppStart_SparkWebMvc.cs at the root of your web project.&lt;/div&gt;&lt;p&gt;&lt;/p&gt; &lt;p&gt;Now suppose you install a few more packages that use the same WebActivator pattern, and you would end up with something like that at the root of your project:&lt;/p&gt;&lt;pre class="brush: plain;"&gt;AppStart_SparkWebMvc.cs
AppStart_SQLCEEntityFramework.cs
AppStart_BarPackage.cs
AppStart_BlahPackage.cs
Global.asax
Global.asax.cs
Web.config
More files...
&lt;/pre&gt;&lt;p&gt;That starts getting really ugly, and most devs like to keep the root of their app free of clutter.&lt;/p&gt;&lt;h3&gt;We need a better convention!&lt;/h3&gt;&lt;p&gt;The solution is simply to agree on a different convention where we put all this startup code into a folder. To match ASP.NET conventions, the obvious name to pick is App_Start. And once we do that, we no longer need to prefix the file names with AppStart, so we would have:&lt;/p&gt;&lt;pre class="brush: plain;"&gt;App_Start
SparkWebMvc.cs
SQLCEEntityFramework.cs
BarPackage.cs
BlahPackage.cs
Global.asax
Global.asax.cs
Web.config
More files...
&lt;/pre&gt;&lt;p&gt;Likewise, the full class names would change from WebApplication1.AppStart_SQLCEEntityFramework to WebApplication1.App_Start.SQLCEEntityFramework. Note that the namespace doesn’t matter a whole lot since you won’t call this code explicitly. But since existing convention is to have the namespace match the folder structure, we may as well do that here.&lt;/p&gt;&lt;p&gt;As of today, there are 17 packages that use WebActivator, so I’ll need to try to convince all the authors to follow this. Fun time ahead! :)&lt;/p&gt;&lt;p&gt;But note that it’s just a convention, with no code changes to enforce it. Nothing written here &lt;em&gt;breaks &lt;/em&gt;any existing packages. It’s just something where by agreeing on a better convention, we make NuGet yet a little bit better!&lt;/p&gt;&lt;h3&gt;An example: EFCodeFirst.SqlServerCompact&lt;/h3&gt;&lt;p&gt;As an example, here is what I ended up with for the EFCodeFirst.SqlServerCompact package using this pattern.&lt;/p&gt;&lt;p&gt;The source file transform in the package is in Content\App_Start\SQLCEEntityFramework.cs.pp, and contains:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;// namespaces, etc...

[assembly: WebActivator.PreApplicationStartMethod(
typeof($rootnamespace$.App_Start.SQLCEEntityFramework), "Start")]

namespace $rootnamespace$.App_Start {
public static class SQLCEEntityFramework {

//etc...
&lt;/pre&gt;Note the use of $rootnamespace$ and of App_Start in the namespace.&lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/g_-kMa9Ho4c" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/400214190627907649/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2011/02/appstart-folder-convention-for-nuget.html#comment-form" title="7 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/400214190627907649?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/400214190627907649?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/g_-kMa9Ho4c/appstart-folder-convention-for-nuget.html" title="App_Start folder convention for NuGet and WebActivator" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><thr:total>7</thr:total><feedburner:origLink>http://blog.davidebbo.com/2011/02/appstart-folder-convention-for-nuget.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CU4NQHwyeyp7ImA9Wx9aEE8.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-8038335484347916213</id><published>2011-02-24T18:47:00.001-08:00</published><updated>2011-03-01T15:59:51.293-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-01T15:59:51.293-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="WebActivator" /><category scheme="http://www.blogger.com/atom/ns#" term="NuGet" /><title>New features in WebActivator 1.4</title><content type="html">&lt;p&gt;[Please see the &lt;a href="https://bitbucket.org/davidebbo/webactivator/wiki/Home"&gt;WebActivator wiki&lt;/a&gt; for the latest docs]&lt;/p&gt;&lt;p&gt;Back in October, I &lt;a href="http://blogs.msdn.com/b/davidebb/archive/2010/10/11/light-up-your-nupacks-with-startup-code-and-webactivator.aspx" target="_blank"&gt;blogged&lt;/a&gt; about the WebActivator NuGet package, which allows packages to bring in some source code that runs on startup in a Web Application. It’s been a pretty popular package, as there are many scenarios where running startup logic is important. The alternative of forcing the user to modify their global.asax is just not compelling.&lt;/p&gt; &lt;p&gt;There have also been a few feature requests since the initial 1.0 release, and I will describe them here.&lt;/p&gt; &lt;h3&gt;Ability to run code after Application_Start&lt;/h3&gt; &lt;p&gt;When you use a WebActivator PreApplicationStartMethod attribute, the method it points to runs before your global.asax’s. Yep, that’s fairly obvious from the name Pre ApplicationStart :)&lt;/p&gt; &lt;p&gt;But in some cases, that’s just too early. Scott Hanselman ran into that when trying to register MVC areas, and I added this feature as a result (see &lt;a href="http://www.hanselman.com/blog/UpdatingAndPublishingANuGetPackagePlusMakingNuGetPackagesSmarterAndAvoidingSourceEditsWithWebActivator.aspx" target="_blank"&gt;his post&lt;/a&gt;).&lt;/p&gt; &lt;p&gt;This feature works exactly the same as the PreApplicationStartMethod attribute, except using a different attribute named… drums rolling… &lt;strong&gt;Post&lt;/strong&gt;ApplicationStartMethod! e.g.&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;[assembly: WebActivator.PostApplicationStartMethod(
typeof(TestLibrary.MyStartupCode), "CallMeAfterAppStart")]

&lt;/pre&gt;&lt;p&gt;So when does that run exactly? It runs at the time the very first HttpModule get initialized. Internally, it’s using the dynamic module registration mechanism &lt;a href="http://blog.davidebbo.com/2011/02/register-your-http-modules-at-runtime.html" target="_blank"&gt;I blogged about recently&lt;/a&gt;.&lt;/p&gt;&lt;h3&gt;Ability to run code when the app shuts down&lt;/h3&gt;&lt;p&gt;WebActivator can also help you execute cleanup logic when the app shuts down. This is done via yet another attribute that works much like the other two, e.g.&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;[assembly: WebActivator.ApplicationShutdownMethod(
typeof(TestLibrary.MyStartupCode), "CallMeWhenAppEnds")]

&lt;/pre&gt;&lt;p&gt;This code runs at the time Dispose is called on the last HttpModule in the app.&lt;/p&gt;&lt;h3&gt;Support for code in App_Code in Web Sites&lt;/h3&gt;&lt;p&gt;In a Web Site (as opposed to a Web Application), you typically put your shared code in the App_Code folder. Now if you have code in there that uses the PostApplicationStartMethod attribute, it will get called when the app starts, giving Web Sites some WebActivator love.&lt;/p&gt;&lt;p&gt;Please note that you can only use PostApplicationStartMethod in App_Code, and not PreApplicationStartMethod. The reason is that when PreApplicationStartMethod fires, the App_Code folder has not even been compiled!&lt;/p&gt;&lt;h3&gt;Support for invoking the start methods outside of ASP.NET&lt;/h3&gt;&lt;p&gt;This change came courtesy of &lt;a href="http://stackoverflow.com/users/449906/jakub-konecki" target="_blank"&gt;Jakub Konecki&lt;/a&gt;, who needed it for unit testing purpose. This comes as a set of static methods that you can use to invoke the startup methods:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;// Run all the WebActivator PreStart methods
WebActivator.ActivationManager.RunPreStartMethods();

// Run all the WebActivator PostStart methods
WebActivator.ActivationManager.RunPostStartMethods();

// Run all the WebActivator start methods
WebActivator.ActivationManager.Run();

// Run all the WebActivator shutdown methods
WebActivator.ActivationManager.RunShutdownMethods();

&lt;/pre&gt;&lt;span style="font-family: georgia, serif; white-space: normal; font-size: 16px" class="Apple-style-span"&gt;You can find the WebActivator sources &lt;a href="https://bitbucket.org/davidebbo/webactivator"&gt;on bitbucket&lt;/a&gt;.&lt;/span&gt;&lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/lAuTT5RlshU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/8038335484347916213/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2011/02/new-features-in-webactivator-13.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/8038335484347916213?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/8038335484347916213?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/lAuTT5RlshU/new-features-in-webactivator-13.html" title="New features in WebActivator 1.4" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><thr:total>1</thr:total><feedburner:origLink>http://blog.davidebbo.com/2011/02/new-features-in-webactivator-13.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CU8MQHY7eCp7ImA9Wx9UFko.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-1306560022894718266</id><published>2011-02-14T00:56:00.001-08:00</published><updated>2011-02-14T00:58:01.800-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-14T00:58:01.800-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><title>Build your Web Application at runtime</title><content type="html">&lt;p&gt;&lt;em&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt;: let me start by saying that the technique described in this blog is experimental, and is meant as a first step to see where this might take us. This is not in any way an officially supported technique!&lt;/em&gt;&lt;/p&gt; &lt;p&gt;If you are an ASP.NET user, you are likely aware that there are two different types of apps that you can create: Web Sites and Web Applications. Here is a quick summary of how they differ:&lt;/p&gt; &lt;h3&gt;Web Sites&lt;/h3&gt; &lt;p&gt;In web sites, all compilation is done at runtime rather than design time. They don’t use any VS project systems, and msbuild is never involved.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;: very dynamic. You can just FTP files to the server, and everything just works. In that sense, it’s similar to ASP Classic and PHP.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;: lack of fine control over the build process; hard to unit test; often slower in VS; not available for MVC.&lt;/p&gt; &lt;h3&gt;Web Applications&lt;/h3&gt; &lt;p&gt;In Web Applications, all the source code is built by VS in the designer using a standard .csproj file and msbuild. Pages and views (.aspx, .cshtml, …) are still built dynamically at runtime, so it’s sort of a mixed mode model.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;: full power of msbuild, easy to unit test code, fast build in VS.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;: once you xcopy your built app to the server, you can’t modify the code by just changing files (though you can still do this for pages &amp;amp; views).&lt;/p&gt; &lt;h3&gt;What if we could get the best of both worlds?&lt;/h3&gt; &lt;p&gt;I was recently chatting with my coworker &lt;a href="http://twitter.com/#!/loudej" target="_blank"&gt;Louis DeJardin&lt;/a&gt; about compilation models, and he put out the idea that we might get something interesting if we were to run msbuild on the server, which is where this came from.&lt;/p&gt; &lt;p&gt;In a sense, it’s sort of an ‘obvious’ thing to try if you look at the Pros can Cons of Web Sites and Web Applications. We want the full power of msbuild, but we also want the more dynamic nature of Web Sites, so the only logical thing to do is to run msbuild dynamically on the server!&lt;/p&gt; &lt;h3&gt;Try it now using NuGet!&lt;/h3&gt; &lt;p&gt;Before I give you more details, let me show you how you can try this in no time via &lt;a href="http://nuget.org/" target="_blank"&gt;NuGet&lt;/a&gt;:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Create a new MVC app&lt;/li&gt; &lt;li&gt;Install my ‘WebAppBuilder’ NuGet package&lt;/li&gt; &lt;li&gt;Run the app&lt;/li&gt; &lt;li&gt;Change the message in Controllers\HomeController.cs, and &lt;strong&gt;don’t rebuild&lt;/strong&gt;&lt;/li&gt; &lt;li&gt;Refresh the page in the browser (and then again per the message you’ll get)&lt;/li&gt; &lt;li&gt;Now try to make a change with a compile error and refresh again&lt;/li&gt;&lt;/ol&gt; &lt;h3&gt;How does it all work?&lt;/h3&gt; &lt;p&gt;There really isn’t much code at all to make this work. First, it uses the technique I described in my previous post to &lt;a href="http://blog.davidebbo.com/2011/02/register-your-http-modules-at-runtime.html" target="_blank"&gt;dynamically register a module&lt;/a&gt;. This is what allows it to kick in without any registration.&lt;/p&gt; &lt;p&gt;Whenever the appdomain starts, the module looks for the csproj file and builds it. Doing this is quite simple since msbuild is well exposed to managed code (take a look at &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.build.execution.buildmanager.aspx" target="_blank"&gt;Microsoft.Build.Execution.BuildManager&lt;/a&gt;). Note that it always does that on startup, with the assumption that the incremental build will be super fast if there is nothing to build.&lt;/p&gt; &lt;p&gt;Then if something actually got built, it sends back a simple page telling the user to refresh. This is a bit ugly as it effectively takes two refreshes to get the result, but it’s necessary since we can’t use the freshly built assembly in the same domain used to build it (since creating it causes a domain unload).&lt;/p&gt; &lt;p&gt;The other thing it does is listen to file change notification so it can unload the domain if any source files change. Then on the next request things get built as above.&lt;/p&gt; &lt;p&gt;There may be smarter ways of doing this, but this works pretty well as a proof of concept.&lt;/p&gt; &lt;p&gt;You can see &lt;a href="https://bitbucket.org/davidebbo/webappbuilder" target="_blank"&gt;find code on bitbucket&lt;/a&gt;.&lt;/p&gt; &lt;h3&gt;Caveat: requires full trust&lt;/h3&gt; &lt;p&gt;One big caveat of this approach is that it doesn’t work in partial trust, because launching msbuild requires full trust. This is not something that I think can be worked around easily, so I’d say it’s an inherent limitation.&lt;/p&gt; &lt;h3&gt;Where can we take this?&lt;/h3&gt; &lt;p&gt;Well, I’m not really sure yet, but it is certainly interesting to think about the possibilities of using this type of build model in ASP.NET.&lt;/p&gt; &lt;p&gt;Let me know if you think this is crazy or may have potential :)&lt;/p&gt;  &lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/NfWUeKkDsZs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/1306560022894718266/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2011/02/build-your-web-application-at-runtime.html#comment-form" title="14 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/1306560022894718266?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/1306560022894718266?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/NfWUeKkDsZs/build-your-web-application-at-runtime.html" title="Build your Web Application at runtime" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><thr:total>14</thr:total><feedburner:origLink>http://blog.davidebbo.com/2011/02/build-your-web-application-at-runtime.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0MCRHo6fip7ImA9Wx9aEUU.&quot;"><id>tag:blogger.com,1999:blog-1310592211703201999.post-1841753696121561747</id><published>2011-02-13T21:56:00.001-08:00</published><updated>2011-03-03T13:57:45.416-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-03T13:57:45.416-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET" /><title>Register your HTTP modules at runtime without config</title><content type="html">&lt;p&gt;In ASP.NET 4, we added the concept of a PreApplicationStart method that an assembly can use to execute code early on in the appdomain without any configuration. Phil Haack covered it a while back in &lt;a href="http://haacked.com/archive/2010/05/16/three-hidden-extensibility-gems-in-asp-net-4.aspx" target="_blank"&gt;this post&lt;/a&gt;. It’s pretty simple to use. You just define a class that looks like:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;public class PreApplicationStartCode {
public static void Start() {
    // Your startup code here
}
}

&lt;/pre&gt;&lt;p&gt;And then you add an assembly level attribute pointing to it:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;[assembly: PreApplicationStartMethod(typeof(PreApplicationStartCode), "Start")]

&lt;/pre&gt;&lt;p&gt;With the release of MVC3 and ASP.NET Web Pages, we added another little gem: a RegisterModule() API that lets you dynamically register an IHttpModule without touching config. Sadly, the method is hidden so deep that it is hard to find by accident (it’ll get cleaned up in the next framework version).&lt;/p&gt;&lt;p&gt;By combining the two techniques, you have everything you need to register a module dynamically, e.g.&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;public class PreApplicationStartCode {
public static void Start() {
    // Register our module
    Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule(typeof(MyModule));
}
}
&lt;/pre&gt;&lt;p&gt;I warned you it was well hidden! :)&lt;/p&gt;&lt;p&gt;The module type that you pass in to that is just a standard IHttpModule, e.g. here is a basic module that writes to the response on every request:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;class MyModule : IHttpModule {
public void Init(HttpApplication context) {
    context.BeginRequest += (sender, e) =&amp;gt; {
        var response = ((HttpApplication)sender).Response;
        response.Write("MyModule.BeginRequest");
    };
}

public void Dispose() { }
}

&lt;/pre&gt;&lt;p&gt;The beauty of this is that it allows you to create fully encapsulated assemblies that you can just drop into a web app’s bin folder and have them light up without having to add any ugly registration to the app.&lt;/p&gt;&lt;p&gt;And yes, all this works fine in partial trust!&lt;/p&gt;&lt;p&gt;You can download a minimal sample from &lt;a href="https://docs.google.com/uc?id=0B9LFjrvVZR24ZGQ4ZWY3YjYtN2Y3NC00ODcyLTlmMDktNWUxNWM0ZmM2ZjAw&amp;amp;export=download&amp;amp;hl=en"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/DavidEbbo/~4/nvRFl7_KVqM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://blog.davidebbo.com/feeds/1841753696121561747/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://blog.davidebbo.com/2011/02/register-your-http-modules-at-runtime.html#comment-form" title="16 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/1841753696121561747?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1310592211703201999/posts/default/1841753696121561747?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/DavidEbbo/~3/nvRFl7_KVqM/register-your-http-modules-at-runtime.html" title="Register your HTTP modules at runtime without config" /><author><name>David Ebbo</name><uri>http://www.blogger.com/profile/10231048261702011658</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="http://3.bp.blogspot.com/_jySMpScpTXc/TRfwC8DSTUI/AAAAAAAAALo/mMkuAfFVg4Q/s1600-R/3c4e7f8b11f8b8c1d77ebb70678097b4%253Fs%253D128%2526d%253Didenticon%2526r%253DPG" /></author><thr:total>16</thr:total><feedburner:origLink>http://blog.davidebbo.com/2011/02/register-your-http-modules-at-runtime.html</feedburner:origLink></entry></feed>
