Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T4 files not added to project on package install #128

Open
InteXX opened this issue Oct 16, 2020 · 24 comments
Open

T4 files not added to project on package install #128

InteXX opened this issue Oct 16, 2020 · 24 comments

Comments

@InteXX
Copy link

InteXX commented Oct 16, 2020

I installed the latest package v4.2.4, but the files T4MVC.tt and T4MVC.tt.hooks.t4 weren't added to my VS 2019 MVC5 project.

I suspect this may have something to do with the fact that a file referenced in the package's install script (install.ps1) doesn't exist in the package:

$project.ProjectItems.Item("T4MVC.tt.settings.xml").Properties.Item("BuildAction").Value = 0

The script may be failing entirely because of its absence, but I'm not certain of this.

Questions:

  1. Am I correct with the above?
  2. Is the workaround to simply manually add these files to the project?
  3. Where can I obtain the T4MVC.tt.settings.xml file?
@davidebbo
Copy link
Contributor

Nothing has changed in a long time, so it shouldn't be broken. Note that T4MVC is only for .NET Classic, and not .NET Core. Maybe you are using Core?

@InteXX
Copy link
Author

InteXX commented Oct 16, 2020

  1. Am I correct with the above?

Apparently not. I just discovered the T4MVCVB package.

But it seems far behind the C# version. Is there anything critical that I'll be missing by using it?

@InteXX
Copy link
Author

InteXX commented Oct 16, 2020

p.s. Yes, I'm using .NET Classic, v4.8, in a VB.NET project

@davidebbo
Copy link
Contributor

It was maintained by someone else a while back, but has not been updated since 2016. That being said, things have not changed fundamentally since, so it may still work. But I won't be able to support it if it doesn't :)

@InteXX
Copy link
Author

InteXX commented Oct 16, 2020

Hm, I just installed the T4MVCVB package. Same result. Nothing was added to my project.

  1. Is the workaround to manually add these files to the project?

@InteXX
Copy link
Author

InteXX commented Oct 16, 2020

I've just put it on my to-do list to work with you to update that VB.NET version.

Trouble is, I don't know when I'll be able to get to it. I'm swamped. It'll be well into the Spring months of next year, I'm sure.

But you've got someone out here who wants to help :-)

@davidebbo
Copy link
Contributor

I can't explain why nothing gets added. I'm a bit out of the .NET world, so having tried any of this in a while. Maybe some setting changed in VS, or something that affects it.

Thanks for the offer to support VB!

@InteXX
Copy link
Author

InteXX commented Oct 16, 2020

Thanks for the offer to support VB!

Sure thing, happy to do it.

But can you confirm these:

  1. Is the workaround to manually add these files to the project?
  2. Where can I obtain the T4MVC.tt.settings.xml file?

@davidebbo
Copy link
Contributor

davidebbo commented Oct 16, 2020

It would be best to figure out why it's not working. I just tried creating a new VB MVC project and I was able to add T4MVCVB:

Attempting to gather dependency information for package 'T4MVCVB.3.7.8' with respect to project 'WebApplicationVBT4MVC', targeting '.NETFramework,Version=v4.7.2'
Gathering dependency information took 15.36 sec
Attempting to resolve dependencies for package 'T4MVCVB.3.7.8' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'T4MVCVB.3.7.8'
Resolved actions to install package 'T4MVCVB.3.7.8'
  GET https://api.nuget.org/v3-flatcontainer/t4mvcvb/3.7.8/t4mvcvb.3.7.8.nupkg
  GET https://api.nuget.org/v3-flatcontainer/t4mvcextensions/3.7.4/t4mvcextensions.3.7.4.nupkg
  OK https://api.nuget.org/v3-flatcontainer/t4mvcvb/3.7.8/t4mvcvb.3.7.8.nupkg 250ms
  OK https://api.nuget.org/v3-flatcontainer/t4mvcextensions/3.7.4/t4mvcextensions.3.7.4.nupkg 259ms
Installing T4MVCExtensions 3.7.4.
Installing T4MVCVB 3.7.8.
Adding package 'T4MVCExtensions.3.7.4' to folder 'C:\Users\david\source\repos\WebApplicationVBT4MVC\packages'
Added package 'T4MVCExtensions.3.7.4' to folder 'C:\Users\david\source\repos\WebApplicationVBT4MVC\packages'
Added package 'T4MVCExtensions.3.7.4' to 'packages.config'
Successfully installed 'T4MVCExtensions 3.7.4' to WebApplicationVBT4MVC
Adding package 'T4MVCVB.3.7.8' to folder 'C:\Users\david\source\repos\WebApplicationVBT4MVC\packages'
Added package 'T4MVCVB.3.7.8' to folder 'C:\Users\david\source\repos\WebApplicationVBT4MVC\packages'
Added package 'T4MVCVB.3.7.8' to 'packages.config'
Executing script file 'C:\Users\david\source\repos\WebApplicationVBT4MVC\packages\T4MVCVB.3.7.8\tools\install.ps1'...
Successfully installed 'T4MVCVB 3.7.8' to WebApplicationVBT4MVC
Executing nuget actions took 10.71 sec
Time Elapsed: 00:00:27.0991883

I have not updated VS in a while though, in case that makes a difference. Can you try on a clean new project to isolate? I'll update my VS...

@InteXX
Copy link
Author

InteXX commented Oct 16, 2020

OK, I figured it out.

The files don't get installed when the package is added to a project that uses PackagReference instead of 'packages.config'. Is that what you were referring to earlier with Classic/Core?

In this case, is the workaround simply to manually add the files to the project?

FYI I've been able to find an answer to my other question:

  1. Where can I obtain the T4MVC.tt.settings.xml file?

The answer is that it's automatically generated at design time. In fact, I think I remember reading that somewhere in the docs.

@InteXX
Copy link
Author

InteXX commented Oct 16, 2020

I'm getting this warning when I run the .tt file:

Running transformation: T4MVCVB.tt doesn't support HomeController.SignUpAsync because it doesn't return a supported System.Threading.Tasks.Task(Of System.Web.Mvc.ActionResult) type

Here's the action signature:

<HttpPost>
<ActionName("SignUp")>
<ValidateAntiForgeryToken>
Public Async Function SignUpAsync(Model As SignInOrSignUp) As Task(Of ActionResult)
  ...
End Function

Is this because I'm running these as Async?

@davidebbo
Copy link
Contributor

davidebbo commented Oct 16, 2020

Yes, I think that was never supported. See #108

@davidebbo
Copy link
Contributor

Actually, not sure that bug is related. It's been a long time, so I don't recall whether there was an issue with async methods on the C# side. It's possible that it's VB specific.

@InteXX
Copy link
Author

InteXX commented Oct 16, 2020

Actually, not sure that bug is related

Ah, I was wondering about that ;-)

OK, I'll dig in and see what I can find.

Since I've now got generated code, it seems my proposed workaround is correct:

Is the workaround to manually add these files to the project?

Can you confirm?

@InteXX
Copy link
Author

InteXX commented Oct 16, 2020

Found it. It's a bug.

On line 819 of T4MVCVB.tt, I changed this:

if (!method.Type.CodeType.get_IsDerivedFrom("System.Web.Mvc.ActionResult") && method.Type.CodeType.FullName !="System.Threading.Tasks.Task<System.Web.Mvc.ActionResult>")

...to this:

if (!method.Type.CodeType.get_IsDerivedFrom("System.Web.Mvc.ActionResult") && method.Type.CodeType.FullName !="System.Threading.Tasks.Task(Of System.Web.Mvc.ActionResult)")

Also: as it turns out, the generator strips out the Async when adding the Overrides. I'll dig through and see if I can't fix that as well.

@InteXX
Copy link
Author

InteXX commented Oct 16, 2020

the generator strips out the Async when adding the Overrides

As far as I can tell, the problem seems to be related to this:

method.CanOverride = true;

As method is a COM object, I'm unable to discover its members. Is there something like an IsAsync property, to ensure that the Async modifier is retained?

@InteXX
Copy link
Author

InteXX commented Oct 16, 2020

Oops, I just noticed I'm drifting the topic.

Shall I move these to a new issue?

@davidebbo
Copy link
Contributor

About manually adding the files to the project, yes, you can do that if all else fails.

For the ActionResult issue you found, it's likely something that was copied from the C# version and was not tested.

The doc can help to discover methods. e.g. I think this is the right doc: https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.vccodemodel.vccodefunction?view=visualstudiosdk-2019. But not sure about detecting async.

@InteXX
Copy link
Author

InteXX commented Oct 16, 2020

That looks to be the right doc, but there's nothing in there about Async.

Hm. It looks like we'll have to manually restore that modifier after the Overrides insertion steps on it. It'll only be once per new controller, so that's not too bad.

@InteXX
Copy link
Author

InteXX commented Oct 16, 2020

OK, getting back on topic...

The original problem of the files not being added to a PackageReference project... do you prefer to keep this issue open for tracking? Or is the workaround of adding them manually sufficient to close?

If the latter, I'll go ahead and close it.

@davidebbo
Copy link
Contributor

It's fine to keep it open, but realistically, it's unlikely to get fixed. As time goes, more and more people move to Core, so T4MVC is less and less used.

@InteXX
Copy link
Author

InteXX commented Oct 16, 2020

I understand.

I'd love to move to Core myself, but unfortunately Microsoft is dropping the ball with VB.NET.

@davidebbo
Copy link
Contributor

Oh, I didn't realize that. I've left MS and I'm quite disconnected from this world now.

@InteXX
Copy link
Author

InteXX commented Oct 16, 2020

I fantasize about becoming disconnected from this world as well ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants