3

I'm a using the repository pattern and Unity to manage the dependency to my concrete repository objects. In itself this is not an issue however I am running into a problem when using publish website in both VS and the TFS build process.

I believe the problem is being caused by the fact that although the project which contains the concrete repository objects is referenced in my application, the classes that it contains are never used directly. This is because I am using Unity to create instances of the concrete objects at runtime using the Unity config held in my web.config.

The repository project is being compiled when and included in the output when built but when publish website is used in either VS of TFS the repository assembly is missing. Therefore when the web application is deployed to the web server it is not possible to use it as you are greeted with the error:

The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)

This is because Unity cannot find the missing assembly as you would expect.

So my specific question is; Is there a way to ensure that repository assembly is copied to the output directly when publishing the website in VS and TFS without directly using one of the concrete classes in the project?

lexx
  • 637
  • 3
  • 9
  • did you try editing the build process in TFS? – onof Sep 02 '11 at 11:02
  • @onof Which part in particular? The project is being complied and the assebly is in the build output it just doesnt get copied as part of the publish. – lexx Sep 02 '11 at 11:08
  • Oh, I see. The problem is in the visual studio publish tool. I guess you need another tool to publish the site – onof Sep 02 '11 at 11:14
  • @onof This might be the case. Either that or I could create a custom build process which copies the missing assembly after the publish. I was just wondering if there was something I could do to make sure it is included as standard. – lexx Sep 02 '11 at 11:21
  • 1
    I gave up using Publish Website as it's not particularly useful with msbuild or build machines etc, and switched to using Web Deployment Projects, which are far more useful and seem to copy my Unity assemblies no problem. – Simon Steele Sep 02 '11 at 12:51
  • @Simon Steele Thats not a bad idea (Have an up vote). I have however just found a solution to my problem which I am going to post below. – lexx Sep 02 '11 at 13:22

1 Answers1

1

So with some digging around I have found a solution to my problem. This soltuion only fixes the problm when building with TFS but to be honest with continuos integration I'm not bothered about publishing from VS.

My inspiration came from an answer given by Mike Hadlow

What's the best way to get TFS to output each project to its own directory?

Basically the solution is to modify the build script for web project so that it copies the missing assembly to the publish website output folder.

Here is what I did:

  1. I right clicked on my web project in the solution explorer and clicked 'Unload Project'.
  2. I then right clicked on the unloaded project and clicked 'Edit [Project Name]'
  3. Scrolling right down to the bottom of the file I found the following commented out build target:

    <Target Name="AfterBuild"> </Target>

  4. I modified this adding the command to copy the missing assembly:

    <Target Name="AfterBuild">

    <Copy SourceFiles="$(OutDir)[Missing Assembly Name]" DestinationFolder="$(OutDir)_PublishedWebsites\$(MSBuildProjectName)\bin" SkipUnchangedFiles="true" />

    </Target>

  5. Now when building the solution in TFS the missing assembly is included in the bin folder of the published website output.

This solution could be used to copy any other missing content to the published website output. As the files that you want to copy are likely to be different for each project doing it in this way is probably the best option. I am however thinking about creating a custom version of Microsoft.WebApplication.targets which copies minified CSS and script files.

Community
  • 1
  • 1
lexx
  • 637
  • 3
  • 9