Monday, June 4, 2012

MVC.Net 3 and Team Foundation Build

A lot has been written about bin deployments of MVC.Net 3 and seperately about building MVC.Net 3 projects on Team Foundation Build.  I haven't seen anyone put the whole package together in a step by step format, so this post is inteded to do just that.  The issue here is that TFS Build by default does not copy required MVC.Net 3 dependencies to the output folder.  When you install your MVC.Net 3 application from the build server's output on a server that doesn't have MVC.Net 3 installed from the Microsoft MSI your app won't run because the required dependencies aren't there.  This article shows you step by step how to fix that.  You'll need Visual Studio 2010 SP1 for this to work.

  1. From your project, right click on your project and select 'Add Deployable Dependencies'
  2. Choose 'ASP.Net Web Pages with Razor Syntax' (You are using razor right?) and click OK.
  3. Visual Studio will add a folder called _bin_deployableAssemblies and put the proper .dlls in there for you
  4. Now, edit your .csproj file and add the following XML inside of the <Project></Project> tag: 
  <Target Name="CopyBinDeployableAssemblies" AfterTargets="CopyFilesToOutputDirectory" Condition="Exists('$(MSBuildProjectDirectory)\_bin_deployableAssemblies')">
     <ItemGroup>
         <_binDeployableAssemblies Include="$(MSBuildProjectDirectory)\_bin_deployableAssemblies\**\*.*" />
         <FilesForPackagingFromProject Include="%(_binDeployableAssemblies.Identity)">
                         <DestinationRelativePath>bin\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
         </FilesForPackagingFromProject>
     </ItemGroup>

     <Copy SourceFiles="@(_binDeployableAssemblies)" DestinationFolder="$(OutDir)%(RecursiveDir)" SkipUnchangedFiles="true" />
     <Copy Condition="'$(WebProjectOutputDir)' != ''" SourceFiles="@(_binDeployableAssemblies)"             DestinationFolder="$(WebProjectOutputDir)\bin\%(RecursiveDir)" SkipUnchangedFiles="true"/>
  </Target>

This XML will instruct the build server to copy the contents  of the folder created by Visual Studio to the output folder.  Check in your changes and check your drop folder for success.

2 comments: