NeVeSpl / NTypewriter

File/code generator using Scriban text templates populated with C# code metadata from Roslyn API.
https://nevespl.github.io/NTypewriter/
MIT License
117 stars 24 forks source link

Allow to use Regex (from System.Text.RegularExpressions) in .nt.cs files #84

Closed tanguy-c closed 11 months ago

tanguy-c commented 1 year ago

Hello,

Code generation on CI is not working properly with Regex (it works great in Visual Studio) I have the following error :

error CS1069: The type name 'Regex' could not be found in the namespace 'System.Text.RegularExpressions'. This type has been forwarded to assembly 'System.Text.RegularExpressions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.

I suppose it has to be added to NTypewriter.SourceGenerator/NTypewriter.SourceGenerator.csproj (the same way as for System.Text.Json) I use Regex to "slugify" my routes

Thanks

tanguy-c commented 1 year ago

I use something like this to slugify controller names in routes (ex: PetShop → pet-shop) https://learn.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-6.0#parameter-transformers-1 In order to generate the typescript services, I have to slugify the controller name (or maybe there's another way ?) Should I create a custom CLI for this ? (is it the use case ?)

I can try to take a look at this problem and send a PR, but I don't know to build NTypewriter.SourceGenerator using local code instead of the '0.4.1' nuget.

Thank you!

Edit: I found a way to build with a local nuget.config so here is a PR. Let me know if you want a test on this