Using Solution Factory + NuPack to create Opinionated Visual Studio Solutions.

Using Solution Factory inside of NuPack opens up a great new world of creating Solution Level templates. Previously, I wrote a lot of code in Solution Factory that just kept running into edge cases working against the Visual Studio automation API ,DTE. Most of what I wanted to achieve was setting some defaults and installing dependencies.  This is where using solution factory with Nupack really shines.


The following code is a prototype of what you could use to make a MetaPackage for NuPack . (A meta package is a package that would not contain any assemblies or content to add to a project but would rather chain together a set of packages). In this scenario, using Visual Studio I can create a MVC project and using this script I automate setting up a test project with the latest versions of the testing tools that I like to work in.



The commands that Solution Factory adds to the Package Management Console are:

  • Add-Project
  • Add-ProjectReference
  • Remove-LibraryReference
  • Set-DefaultNamespace


After running this code, you will see the following output in the console


You can see the console pretty much echoes the commands of my little PowerShell script.  Lets look at the solution explorer to see what was added.

image The Test project was added and it follows the convention/ naming pattern that I like.  You can see that the assembly references are pretty clean.  This is pretty much the way I like it but with previous solutions like solution factory, I get the benefit of having the latest version of each of the libraries, thanks to NuPack.


While this is a little proof of concept, this can be turned into something much larger. At Headspring, I put together a standard File –> New –> Headspring project and it followed a more complex project structure that had some pretty specific ways of controlling dependencies so that Core logic did not depend on 3rd party assemblies.  You can read more about this approach on Jeffrey’s Blog. The part that broke down for us, is that it took a lot of effort to automate the process of setting up our structure with the latest and greatest bits. I think building on what I demonstrated here will really go far, for projects like Sharp Architecture, FUBU MVC, and any other project that wants to setup an opinionated way of working. 


I can see bundling up known solutions together in a way that just was not easy to create and share with the community, I really think that will change now. And I am very excited about what will come as NuPack and Solution Factory evolve over the next few months.


Solution Factory is in the current NuPack feed so you can start using this now.  The code for Solution Factory is located on codeplex, but exists in one of my Forks, I will spend some time over the next few weeks moving this into the main trunk and I removing all of the existing Solution Factory Add-in and Command Line applications. The code is just not needed anymore.. And deleting code that has no value, makes me happy!


Comments?  Let me know. If this is something you have a passion for, let me know and we can work together on building out more of solution factory!

About Eric Hexter

I am the CTO for QuarterSpot. I (co)Founded MvcContrib, Should, Solution Factory, and Pstrami open source projects. I have co-authored MVC 2 in Action, MVC3 in Action, and MVC 4 in Action. I co-founded online events like mvcConf, aspConf, and Community for MVC. I am also a Microsoft MVP in ASP.Net.
This entry was posted in nupack, OSS, Solution Factory, Tools, VS2010. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Matt roberts

    This is great, looking forwards to creating some templates of my own :)

  • Nandu

    I see a tool called “Should” references in your project. What is this tool about? Thanks

  • Now that I got around to reading this, this is awesome! I have the same problem setting up the reference tree on new projects and it’s all manual. I had gone down the Microsoft Factory path but it’s a complicated add-in just to get the same end result. This is much simpler and really rocks. Thanks!

  • Juan


    I need a template of my solution. It has 4 projects. I installed your addin, but can not findhow to create the template.

    In a previous project to Visual Studio 2008 called “solutionFactory” this was possiblethrough a menu with an option called ”Export a Solution Template”

    Is it possible to do this with your addin? Can you explain in a nutshell?

    Sorry for my English if it is wrong 

    • Anonymous

      The new version of solution factory does not do an existing solution export. It only provides an API to create new projects and that allows you to integrate with NuGet. At somepoint in the future I could see transforming this to create new nuget package.
      Eric Hexter

      blog |
      info |