T4MVC 3.7.4 doesn't work in VS 2013 (in VS 201

2019-07-04 10:56发布

问题:

I created a new ASP.NET MVC Web Application project in VS 2013 and installed T4MVC package via nuget. I'm receiving this error below when I am trying to Run Custom Tool for T4MVC.tt in the action menu. Line 792 in T4MVC.tt looks like this:

if (method.Type.TypeKind != vsCMTypeRef.vsCMTypeRefCodeType || !(method.Type.CodeType is CodeClass2)) continue;

Error   1   Running transformation: System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
   at Microsoft.VisualStudio.CSharp.Services.Language.CodeModel.CCodeFunction.get_Type()
   at EnvDTE80.CodeFunction2.get_Type()
   at Microsoft.VisualStudio.TextTemplating98C322A13A6BCC1DAF8B2CBDB87780CF395EE5EDAD72B82A75D505BDDC8999456241B0D6A9EEE4B4EDBBFC85FFB857E4BED539824B09260C2453F2B9684ABF73.GeneratedTextTransformation.ProcessControllerActionMethods(ControllerInfo controllerInfo, CodeClass2 current) in c:\Users\Sergey\Documents\Visual Studio 2013\Projects\WebApplication3\WebApplication3\T4MVC.tt:line 792
   at Microsoft.VisualStudio.TextTemplating98C322A13A6BCC1DAF8B2CBDB87780CF395EE5EDAD72B82A75D505BDDC8999456241B0D6A9EEE4B4EDBBFC85FFB857E4BED539824B09260C2453F2B9684ABF73.GeneratedTextTransformation.ProcessControllerType(CodeClass2 type, AreaInfo area, DateTime controllerLastWriteTime) in c:\Users\Sergey\Documents\Visual Studio 2013\Projects\WebApplication3\WebApplication3\T4MVC.tt:line 693
   at Microsoft.VisualStudio.TextTemplating98C322A13A6BCC1DAF8B2CBDB87780CF395EE5EDAD72B82A75D505BDDC8999456241B0D6A9EEE4B4EDBBFC85FFB857E4BED539824B09260C2453F2B9684ABF73.GeneratedTextTransformation.ProcessControllersRecursive(ProjectItem projectItem, AreaInfo area) in c:\Users\Sergey\Documents\Visual Studio 2013\Projects\WebApplication3\WebApplication3\T4MVC.tt:line 625
   at Microsoft.VisualStudio.TextTemplating98C322A13A6BCC1DAF8B2CBDB87780CF395EE5EDAD72B82A75D505BDDC8999456241B0D6A9EEE4B4EDBBFC85FFB857E4BED539824B09260C2453F2B9684ABF73.GeneratedTextTransformation.ProcessControllersRecursive(ProjectItem projectItem, AreaInfo area) in c:\Users\Sergey\Documents\Visual Studio 2013\Projects\WebApplication3\WebApplication3\T4MVC.tt:line 610
   at Microsoft.VisualStudio.TextTemplating98C322A13A6BCC1DAF8B2CBDB87780CF395EE5EDAD72B82A75D505BDDC8999456241B0D6A9EEE4B4EDBBFC85FFB857E4BED539824B09260C2453F2B9684ABF73.GeneratedTextTransformation.ProcessAreaControllers(ProjectItems areaFolderItems, AreaInfo area) in c:\Users\Sergey\Documents\Visual Studio 2013\Projects\WebApplication3\WebApplication3\T4MVC.tt:line 591
   at Microsoft.VisualStudio.TextTemplating98C322A13A6BCC1DAF8B2CBDB87780CF395EE5EDAD72B82A75D505BDDC8999456241B0D6A9EEE4B4EDBBFC85FFB857E4BED539824B09260C2453F2B9684ABF73.GeneratedTextTransformation.ProcessArea(ProjectItems areaFolderItems, String name) in c:\Users\Sergey\Documents\Visual Studio 2013\Projects\WebApplication3\WebApplication3\T4MVC.tt:line 576
   at Microsoft.VisualStudio.TextTemplating98C322A13A6BCC1DAF8B2CBDB87780CF395EE5EDAD72B82A75D505BDDC8999456241B0D6A9EEE4B4EDBBFC85FFB857E4BED539824B09260C2453F2B9684ABF73.GeneratedTextTransformation.ProcessAreas(Project project) in c:\Users\Sergey\Documents\Visual Studio 2013\Projects\WebApplication3\WebApplication3\T4MVC.tt:line 541
   at Microsoft.VisualStudio.TextTemplating98C322A13A6BCC1DAF8B2CBDB87780CF395EE5EDAD72B82A75D505BDDC8999456241B0D6A9EEE4B4EDBBFC85FFB857E4BED539824B09260C2453F2B9684ABF73.GeneratedTextTransformation.PrepareDataToRender(TextTransformation tt) in c:\Users\Sergey\Documents\Visual Studio 2013\Projects\WebApplication3\WebApplication3\T4MVC.tt:line 522
   at Microsoft.VisualStudio.TextTemplating98C322A13A6BCC1DAF8B2CBDB87780CF395EE5EDAD72B82A75D505BDDC8999456241B0D6A9EEE4B4EDBBFC85FFB857E4BED539824B09260C2453F2B9684ABF73.GeneratedTextTransformation.TransformText() in c:\Users\Sergey\Documents\Visual Studio 2013\Projects\WebApplication3\WebApplication3\T4MVC.tt:line 40   c:\Users\Sergey\Documents\Visual Studio 2013\Projects\WebApplication3\WebApplication3\T4MVC.tt  792 1   WebApplication3

回答1:

Some questions/suggestions to help investigate:

  • Is your solution a completely unmodified new MVC5 project, or does it have some of your changes?
  • Does this happen consistently, even after restarting VS?
  • Do you see the same problem with my sample solution?