Visual Studio 2010 project upgrade bug; test assemblies being copied to release folders in error
After I upgraded an ASP.NET Web Application VS2008 solution to VS2010 I found a strange problem. When I build either the whole solution or the test project in the solution the test assembly gets copies to Web Applications bin directory. However if I build the solution from the command line with MSBUILD they are not copied (so MSBUILD behaves as VS2008 used to).
Turns out it is easy to repeat, the process is as follows:
- Open Vs2008 SP1
- Create an empty solution
- Add a C# Class library project (targeted on .NET 3.5)
- Add a C# ASP.NET Web application (targeted on .NET 3.5)
- Add reference from the web application to the class library
- Build the solution, note that we see the class library and web application assemblies are in the web application bin directory
- Add a C# Test project 3.5 (targeted on .NET 3.5)
- Add reference to the Web application project
- Build the solution, note that we still just see the class library and web application assemblies are in the web application bin directory – there is no test assembly
- Exit VS2008 and load VS2010
- Load the solution and allow it to be upgraded. On the dialog about .NET versions say to leave the projects on .NET 3.5.
- Rebuild the solution and note that now in the Web Application bin directory we have the class library, web application and test assemblies
- Do a clean of the solution, note that in the Web Application bin directory the test assembly is not removed.
So why is this a problem? .NET 4.0 is a replacement for previous .NET version not an extension as 3.0 and 3.5. were for 2.0. This means basically that in any given deployment you need to have all 4.0 assemblies or all 2.0, 3.0, 3.5 ones. However, under VS2010 a test project must target .NET 4.0 (to get all the new cool testing features), so the fact at this 4.0 test assembly ends up in a 3.5 based Web Application directory is a problem.
I have no answer to the problem as yet, though I have reported it. At present the workaround is to either
- Delete the test assemblies from the Web Application bin directory. once this is done everything behaves as you would expect.
- Or make sure you only target .NET 4.0, though I suspect this might be an issue for some people developing web applications as it will be a while before we see ISP deploying .NET 4.0
Read the complete post at http://blogs.blackmarble.co.uk/blogs/rfennell/archive/2009/07/03/visual-studio-2010-project-upgrade-bug-test-assemblies-being-copied-to-release-folders-in-error.aspx