frhagn / Typewriter

Automatic TypeScript template generation from C# source files
http://frhagn.github.io/Typewriter
Apache License 2.0
536 stars 132 forks source link

ASP.NET 5 Support #76

Open ArieJones opened 8 years ago

ArieJones commented 8 years ago

I am trying to setup an ASP.NET project to use typewriter for generating out my typescript interfaces for my data models, however, even though it says that rendering is complete...it never renders the files. My project structure is

Web (MVC 6) -- Entities (Class Library - Package Version) -- Services (Class Library - Package Version)

I am trying to generate code based off of the Entities project. I have tried to have the file both in the MVC 6 project as well as the within the Entities class library..but no joy there.

I have also tried to add in a regular class library project but of course adding a reference to the Entities library project fails....

Is there going to be up and coming support for the new ASP.NET 5 platform?

ArieJones commented 8 years ago

Ok, after pulling down the code and checking on a couple of things.... it looks like it is coming up with an error ....(see below)....

23:11:34.349 ERROR: Error processing queue: Exception has been thrown by the target of an invocation. 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 Typewriter.Generation.Template.SetMappedSourceFile(ProjectItem item, String path) at Typewriter.Generation.Template.SaveFile(File file, String output) at Typewriter.Generation.Template.RenderFile(File file) at Typewriter.Generation.Controllers.GenerationController.<>c__DisplayClass5_0.b__0() at Typewriter.Generation.Controllers.EventQueue.ProcessQueue()

Looking at the code ...looks like this is happening here if (property == null) throw new InvalidOperationException("Cannot find CustomToolNamespace property");

            property.Value = relativeSourcePath;

Where you are trying to set the CustomToolNamespace property... the odd thing is that the property value does not come back NULL but it obviously has a problem setting it.

Further looking at the difference between the files in an MVC 5 vs an MVC 6 project ...when looking at the properties of the files... they are totally different and I see no instance of a CustomToolNamespace there...

I am going to raise the issue with the ASP.NET teams to see what the dealio is..

Thanks AJ

frhagn commented 8 years ago

Hi @ArieJones, I'm looking at adding support for ASP.NET 5, but as you've noticed there are a couple of issues to resolve i order to make it all work. One issue is the lack of support for custom meta-data for the rendered files in the new project system. The other major issue is the lack of support for nesting the rendered files under the templates. I'm currently testing out some alternative solutions to theese issues but it's hard to find an optimal solution...

Please let me know what the ASP.NET team has to say, thanks

ArieJones commented 8 years ago

Yeah, I am sure it has been a real PIA. What's sad is that the system confirms that the property is "there" then fails on writing.

I found that if I comment out this line for writing the property value out to the file then everything generates..

property.Value = relativeSourcePath;

But it is pretty disconcerting that they are treating all of these types of generators a 'non-important' for the sake of being able to run cross platform.

I'm posting the issues here right now and will see what they actually come back with.. .

Thanks for your hard work on this... tool is useful beyond belief...

ArieJones commented 8 years ago

Ok, so for your #2 feature.. .they do have some sort of heuristics based process that we will be able to arbitrarily nest one file under another type of file. This was discussed in the last community standup on just 1/5 ...so at least things look a little brighter.

ruant commented 8 years ago

+1 Would love to see ASP.NET 5 support.

I got several models files, but only one file gets generated. What I do for a workaround right now is renaming the files extension from .cs to .cs_ so it's not recognized and then generate one and one by renaming them back to .cs

The generated content looks OK to me. So I guess this is just the nesting issue?

frhagn commented 8 years ago

Hi @ruant, I'm currently working on ASP.NET 5 support and a more flexible output file manager. I don't know when I'll be done, but I've made some good progress so far...

Your issue is probably caused by a crash when saving the path of the source file (or possibly the nesting problem) that stops the rendering after the first rendered file is saved. I don't have any workaround for this at the moment, sorry.

ruant commented 8 years ago

@frhagn If you need any help testing new stuff I'm more then happy to assist.

ruant commented 8 years ago

@frhagn With version 1.4 it seams to be working a lot better. I can now generate more then one file at the time :+1:

The only warning I get in the Typewriter output is this: WARNING: Falied to save source map for 'Controller OR Model.cs'. Project type not supported.

If that's something with my setup or it's because it's a asp.net core project I'm not sure.

frhagn commented 8 years ago

Great @ruant. The warning you're getting is because ASP.NET Core projects are not supported. I've simply added a try/catch block in 1.4 around the code that's not working. It should work ok, but tracking of renames and deletes won't work in ASP.NET Core projects.

Full support for Core is coming in 2.0

ruant commented 8 years ago

@frhagn Thanks for working on this. You're saving many people hours and hours of tedious coding hours :) :hand:

akshayKhot commented 8 years ago

Appreciate the efforts, any updates on this? is it compatible with ASP.NET 5 now? Thanks.

matgr1 commented 8 years ago

A workaround that I'm using (which works for .NET Core RC2) is to create a separate Windows console application (as in NOT .NET Core) and then use the settings.IncludeProject() method to load my .NET Core projects... I'm guessing it would work with a class library rather than a console app as well, but I haven't tried that

Not sure if this is related, but I do have some issues where it occasionally refuses to regenerate on save, but restarting Visual Studio seems to clear that up...

allenmoatallen commented 8 years ago

Any update on this? Now that .NET Core 1.0.1 is out and 1.1 is right around the corner...

ruant commented 7 years ago

So they've changed the project setup again.

https://blogs.msdn.microsoft.com/dotnet/2016/05/23/changes-to-project-json/ https://blogs.msdn.microsoft.com/dotnet/2016/10/19/net-core-tooling-in-visual-studio-15/ https://blogs.msdn.microsoft.com/dotnet/2016/11/16/announcing-net-core-tools-msbuild-alpha/

https://github.com/dotnet/roslyn-project-system

Looks like this is gonna be the end product, so maybe we should start looking to support this? Atleast for Visual Studio 2017..

tomerpeled commented 7 years ago

Any plans?

JavanXD commented 7 years ago

I am getting 15:52:12.731 WARNING: Falied to save source map for 'C:\Projects\Asd\Asd\src\WebApp\Core\ViewModels\Asd.cs'. Project type not supported. if I save my Template.

Otherwise, it works great in my Visual Studio 15.3.2 Core 2.0 Project.

michaelaird commented 6 years ago

I think the new style .csproj file has stabilized. Is it time to revisit this feature?

My use case is that I want to use the simplified project structure/netstandard for shared DTO projects. TypeWriter doesn't currently see the types in those projects so they're missing from the generated output.