T4MVC 似乎正在丢失它已经生成的代码
我遇到 T4MVC 丢失每次执行 SVN 更新时生成的代码的问题。我可以通过删除 . generated.cs 文件并重新运行模板来修复它。但事实证明这有点令人厌烦。我有什么遗漏的吗?
首先是一些背景信息...
我使用 C# v4、VS2010 和 ASP.NET MVC2。我使用 Subversion 进行源代码管理。我还在 VS2010 中运行许多加载项和扩展...
- Huagati DBML.EDMX 工具
- Zippy.Chirp(用于自动运行 T4MVC 模板)
- Resharper v5
- Visual SVN
- 对齐分配
- ASP.NET OpenID 网站
- Brace Completer(已禁用)
- Code4Blog
- devColor
- 突出显示所选单词的所有出现位置(已禁用)
- HTML 拼写检查器(已禁用)
- Lipsum 2010 - Lorem Ipsum Generator
- Visual Studio 2010 的 PowerCommands
- 生产力强力工具
- 拼写检查器(已禁用)
- Visual Studio 背景定制器
- Visual Studio 颜色主题编辑器
- VS10x 代码标记
- 世界VS 默认浏览器切换器
我实际上写这个问题是为了更新我的工作副本并捕获我在每个阶段可以做的事情...
第 1 步
我已经打开我的 IDE 开始今天的工作在更新我的工作副本之前,我已经收到了 4 个编译器警告...
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
第 2 步
我现在通过右键单击解决方案资源管理器中的根节点并选择 <从上下文菜单的 Visual SVN 部分更新。
我的大多数 . generated.cs 文件都有树冲突...
- HomeController. generated.cs (树冲突)
- T4MVC.cs (树冲突)
- T4MVC.ExplicitExtensions.cs (已删除,已添加)
- GoodsInController. generated.cs (树冲突) )
- SharedController. generated.cs (已删除、已添加)
- StockListController. generated.cs (树冲突)
- StockCheckController. generated.cs (树冲突)
- AuthController. generated.cs (树冲突)
- GoodsOutController. generated.cs (树冲突)
第 3 步
我现在正在解决我的冲突。我怀疑这就是问题所在,因为我总是保留本地文件并将其标记为已解决。我刚刚为第一个冲突(HomeController. generated.cs)做到了这一点。然后,我尝试与本地副本进行比较,并收到以下错误消息...
无法找到“C:/Data”的存储库位置 文件/项目/Web/ByBox.Vanventory/ByBox.Vanventory/HomeController. generated.cs' 在修订版 14638 中
WOAH - 坚持住!
今天早些时候,我意识到树冲突的原因是生成的文件实际上被删除并重新添加到项目中。现在,我不知道是 T4MVC 本身还是 Chirpy 扩展在这样做。我查看了 Chirpy 的源代码(只是在 codeplex 上的网络浏览器中浏览),但它似乎并没有这样做。
我认为 subversion 中树冲突的原因是有两个人都对控制器进行更改,这导致我们都生成具有相同文件名的新文件。因此,subversion 有 2 个新文件并将其标记为树冲突,因为它不知道该如何处理。
我已经向一位也在使用 T4MVC 的同事确认,他们的问题为零,但他们是唯一对控制器代码进行更改的人。在我的项目有两个人之前,我从来没有遇到过问题。自从第二个人开始处理该项目并对控制器代码进行更改以来,该问题就出现了。
那么,我是否在这里遗漏了一些明显明显的东西,或者我是否滥用了 T4MVC 和/或 Chirpy?
目前我有一个有点古怪的解决方案。我编写了一个 powershell 脚本来“触摸”所有的controller.cs 文件。我已将其放入 VS2010 中的外部工具中。当我遇到问题时,我运行该 powershell 脚本,然后构建强制 T4MVC 模板运行的软件,然后所有错误都会消失。这并不理想,我希望它“正常工作”。
编辑
澄清一下,我想要的情况是能够在早上打开 Visual Studio,进行 SVN 更新(通过 VisualSVN),而不必花费任何时间来完成它构建是因为昨天生成的文件中缺少代码。
那么,模板/T4MVC 的东西在 Visual Studio 中到底是如何工作的?
(如果它删除生成的文件并在每次运行时重新创建它们,那么我将不得不停止使用它,因为这不适合使用 subversion 以及多人处理生成的代码添加到的代码)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不认为 Chirpy 或 T4MVC 是直接罪魁祸首。我认为问题的根源是 T4,因为 Visual Studio 处理代码生成的方式。
例如,我最近在更新服务参考时看到了类似的问题。某些生成文件的 Subversion 状态已替换。这意味着 Visual Studio(通过 Subversion 集成插件)告诉 Subversion 删除一个文件,然后添加一个同名的文件。
我认为除了确保在进行任何导致 T4MVC 重新生成其文件的更改之前和之后与同事进行协调之外,对此没有什么可以做的。不过,根据我对 T4MVC 的理解,这意味着每次修改控制器或添加新的内容文件时都必须进行协调。
I don't think either Chirpy or T4MVC is directly to blame. I think the root of the problem is T4 because of the way Visual Studio handles code generation.
I recently saw a similar issue when updating a service reference, for example. The Subversion status for the generated files was replaced for some of the generated files. This means that Visual Studio (via the Subversion integration addin) has told Subversion to delete a file, then to add a file with the exact same name.
I don't think there's anything that can be done about this other than making sure that you coordinate with your colleague before and after you make any changes that will cause T4MVC to regenerate it's files. From my understanding of T4MVC though, that means you'd have to coordinate every time you modify a controller, or add a new content file.
我关闭了 chirpy 的“智能运行”功能,现在一切正常。我宁愿不必在极少数需要的情况下手动运行它。当我构建时它仍然运行并且满足了我 99% 的需求。
I turned off the "smart run" feature of chirpy and all is well now. I'd rather not have to run it manually on the rare occasion I need to. It still runs when I build and that catches 99% of my needs.
我知道这是一个老问题,但我们也有类似的问题。我认为应该归咎于 VisualSVN。我在Visual Studio中使用ANKH,只是为了当我通过Visual Studio添加文件时让它将文件添加到SVN。据我所知,我从未见过 TortioseSVN 想要删除某个总是从存储库中删除的 T4MVC 文件。
其他人都使用 VisualSVN。我不确定,但这是我唯一能想到正在发生的事情。
I know this is an old question, but we have similar issues. I think it is VisualSVN that is to blame. I use ANKH in Visual Studio, only to let it add files to SVN when I add them through Visual Studio. From what I can recall I've never seen TortioseSVN want to delete a certain T4MVC file that always gets deleted from the repo.
Everyone else uses VisualSVN. I'm not certain, but it's the only thing I can think of that is happening.