I'm having a problem with T4MVC losing the code it generated each time I do an SVN update. I can fix it by deleting the .generated.cs files and re-running the template. But this is proving a bit tiresome. Is there something I am missing?
First a little background information ...
I am using C# v4, VS2010 and ASP.NET MVC2. I use subversion for my source control. I am also running a number of add-ins and extensions within VS2010 ...
- Huagati DBML.EDMX Tools
- Zippy.Chirp (for auto running the T4MVC template)
- Resharper v5
- Visual SVN
- Align Assignments
- ASP.NET OpenID web site
- Brace Completer (disabled)
- Code4Blog
- devColor
- Highlight all occurrences of selected word (disabled)
- HTML Spell Checker (disabled)
- Lipsum 2010 - Lorem Ipsum Generator
- PowerCommands for Visual Studio 2010
- Productivity Power Tools
- Spell Checker (disabled)
- Visual Studio Background Customizer
- Visual Studio Color Theme Editor
- VS10x Code Marker
- World of VS Default Browser Switcher
I'm actually writing this question as update my working copy and capturing what I can at each stage...
Step 1
I've opened up my IDE to start my work for the day and I already have 4 compiler warnings before I've even updated my working copy...
Warning 1 The C# 2.0 and C# 3.5 compilers are no longer supported. Templates will always be compiled with the version 4 compiler instead of 'v3.5' as specified. C:\Data Files\Projects\Web\ByBox.Vanventory\ByBox.Vanventory\T4MVC.tt 18 4
Warning 2 Compiling transformation: Unreachable code detected c:\Users\antony\AppData\Local\Temp\z04plrve.0.cs 1015 17
Warning 3 Compiling transformation: Assuming assembly reference 'EnvDTE, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' matches 'EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a', you may need to supply runtime policy C:\Data Files\Projects\Web\ByBox.Vanventory\ByBox.Vanventory\T4MVC.tt 1 1
Warning 4 Compiling transformation: Unreachable expression code detected c:\Data Files\Projects\Web\ByBox.Vanventory\ByBox.Vanventory\T4MVC.tt 968 33
Step 2
I'm now updating my working copy by right clicking on the root node in my solution explorer and selecting Update from the Visual SVN part of the context menu.
I have Tree conflicts on most of my .generated.cs files...
- HomeController.generated.cs (Tree conflict)
- T4MVC.cs (Tree conflict)
- T4MVC.ExplicitExtensions.cs (Deleted, Added)
- GoodsInController.generated.cs (Tree conflict)
- SharedController.generated.cs (Deleted, Added)
- StockListController.generated.cs (Tree conflict)
- StockCheckController.generated.cs (Tree conflict)
- AuthController.generated.cs (Tree conflict)
- GoodsOutController.generated.cs (Tree conflict)
Step 3
I'm now resolving my conflicts. I suspect this is where the problem lies, as I always keep my local file and mark it as resolved. I have just done that for the first conflict (HomeController.generated.cs). I've then tried comparing with my local copy and got the following error message...
Unable to find repository location for 'C:/Data Files/Projects/Web/ByBox.Vanventory/ByBox.Vanventory/HomeController.generated.cs' in revision 14638
WOAH - HOLD ON THERE!
I got as far as this earlier today, when I realised the reason for the tree conflict is that the generated files are actually being deleted and re-added to the project. Now, I don't know if T4MVC itself is doing this or the Chirpy extension. I've looked through the source code of Chirpy (just browsing in my web browser on codeplex) and it doesn't seem to do that.
I think the cause for the Tree Conflicts in subversion is that there are two people both making changes to the controllers, which is causing both of us to generated new files with the same filenames. Therefore, subversion has 2 new files and flags it as a Tree Conflict because it doesn't know what to do about it.
I've confirmed with a colleague who is also using T4MVC that they are having zero problems with it, but they are the only person making changes to the controller code. Before there were two people on my project I never had a problem. The issue has appeared since the second person started working on the project and making changes to the controller code.
So, am I missing something blatantly obvious here, or am I abusing T4MVC and/or Chirpy?
For the moment I have a bit of a hacky solution. I've written a powershell script to "touch" all the controller.cs files. I've put that in my External Tools in VS2010. When I get the issue, I run that powershell script then build the software which forces the T4MVC template to run and all my errors go away. This is not ideal and I would like it to "just work".
Edit
To clarify, the situation I would like get to is being able to just open up visual studio in the morning, do an SVN update (via VisualSVN) and to not have to spend any time getting it to build because code is missing from the generated files that was there yesterday.
So, how exactly does the template/T4MVC stuff work in visual studio?
(If it's deleting the generated files and re-creating them each time it runs, then I will have to stop using it, as that just doesn't sit well with using subversion and with multiple people working on the code which the generated code is adding to)