aspnet / Tooling

Issue tracker and info on Visual Studio tooling for ASP.NET
Other
256 stars 124 forks source link

Visual Studio hangs when running a T4 template which generates more than one file #399

Open kevinkuszyk opened 8 years ago

kevinkuszyk commented 8 years ago

As discussed in aspnet/Home#272, trying to run T4MVC in a MVC Core 1 application causes Visual Studio to hang.

I have posted a sample repro here: https://github.com/kevinkuszyk/aspnet-core-t4mvc.

DrLeh commented 8 years ago

+1 I'm also experiencing this.

Reonekot commented 8 years ago

+1 I have installed "AspNet5.ENU.RC1_Update1_KB3137909" and "VS14-KB3110221" if that has any relevance on the issue.

sayedihashimi commented 8 years ago

Thanks for the report TFS: 192619 I've added this to our internal TFS, we will reply back here soon.

mlorbetske commented 8 years ago

You should be able to avoid this behavior by changing projectSyncAction.EndInvoke(projectSyncAction.BeginInvoke(generatedFileNames, null, null)); in T4MVC.tt (Line 2810) to projectSyncAction(generatedFileNames);

kevinkuszyk commented 8 years ago

Thanks @mlorbetske.

I have to admit I don't really know much T4. I tried that change, but the template generates this error when it runs now:

Severity    Code    Description Project File    Line    Suppression State
Error       Running transformation: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: The "None" rule is missing the "{ItemType}" property.
   at Microsoft.Verify.Operation(Boolean condition, String unformattedMessage, Object arg1, Object arg2)
   at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.DynamicTypeBrowseObject.<>c__DisplayClass127_0.<<VSLangProj80-FileProperties2-set_ItemType>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.ProjectNode.<>c__DisplayClass521_0.<<Mutate>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread()
   at Microsoft.VisualStudio.ProjectSystem.ThreadHandlingMultithreaded.ExecuteSynchronously(Func`1 asyncAction)
   at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.ProjectNode.Mutate(Func`1 asyncAction, Boolean includesFileSystemChange)
   at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.PropertyPages.DynamicTypeBrowseObject.VSLangProj80.FileProperties2.set_ItemType(String value)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
   at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAPropertyInfo.set_Value(Object value)
   at EnvDTE.Property.set_Value(Object lppvReturn)
   at Microsoft.VisualStudio.TextTemplatingD9F9CBC9F29E1DAF5DF07EEA190FFA475A27D88337ADD219654542F162139F4518CB54785B737454709430D57DF1278D4DA3D395511B4ABFF0BBCB570E629371.GeneratedTextTransformation.XmlSettings.SaveChanges(Manager manager) in c:\Projects\aspnet-core-t4mvc\src\AspNet Core T4MVC\T4MVC.tt:line 2657
   at Microsoft.VisualStudio.TextTemplatingD9F9CBC9F29E1DAF5DF07EEA190FFA475A27D88337ADD219654542F162139F4518CB54785B737454709430D57DF1278D4DA3D395511B4ABFF0BBCB570E629371.GeneratedTextTransformation.TransformText() in c:\Projects\aspnet-core-t4mvc\src\AspNet Core T4MVC\T4MVC.tt:line 431    AspNet Core T4MVC   c:\Projects\aspnet-core-t4mvc\src\AspNet Core T4MVC\T4MVC.tt    2657    

I pushed the change in my sample repro here.

/cc @davidebbo

mlorbetske commented 8 years ago

On line 2653, this code item.Properties.Item("ItemType").Value = "None"; attempts to set the build action on the .cs file being generated (which isn't supported in .xproj projects). If you comment out this line, the template generates successfully, however there seem to be some issues with the content being generated, was this based on a .NET 4.5 project?

/cc @sayedihashimi

kevinkuszyk commented 8 years ago

Thanks @mlorbetske that seems to fix it.

If you comment out this line, the template generates successfully, however there seem to be some issues with the content being generated, was this based on a .NET 4.5 project?

Yes, it's the stock T4MVC template. It looks like we have some work to do if we want to support MVC Core. I'll continue that conversation with @davidebbo over at T4MVC/T4MVC#65.

@DrLeh, @Reonekot does @mlorbetske's suggested changes fix the issues you are seeing too?

webtools-bot commented 7 years ago

The GitHub Issue Tracker for the aspnet/Tooling repo is being deprecated in favor of Visual Studio's Report a Problem tool.

If this issue is still a problem with the RTW release of Visual Studio 2017, please report a new issue using the Report a Problem tool. While you can still use .NET Core and ASP.NET Preview tools with Visual Studio 2015, Visual Studio 2017 is now the officially supported tool for developing .NET Core and ASP.NET Core projects.

By using the Report a Problem tool (available in both VS 2017 and VS 2015), you can collect detailed information about the problem, and send it to Microsoft with just a few button clicks. See Visual Studio's Talk to Us page for more details.

Please use the discussion topic here for feedback and questions on the deprecation of this issue tracker. Thanks!

kEph13 commented 6 years ago

If anyone else is running into this using EntityFrameworkTemplateFileManager in a tt template (among other things, the default database-first setup with an edmx uses this), you can use the file manager from this project instead:

https://github.com/renegadexx/T4.Helper

You'll need to include a reference to TemplateFilemanager.CS.ttinclude in your file, and then you can replace EntityFrameworkTemplateFileManager.Create(this) with TemplateFileManager.Create(this).