Before it was possible to plug custom templates (without recompiling the whole project) by creating custom template projects, copying the template dll and then adding the key to the AutoRest.json file.
This seems included as an embedded resource now (Resources.ConfigurationKnownPlugins)
https://github.com/Azure/autorest/blob/master/src/core/AutoRest.Core/Extensibility/AutoRestConfiguration.cs
It seems not possible anymore to customize the templates easily (without forking and changing the whole project). This also means that one can't use the default templates and custom templates side by side.
Do you intend to bring that back ?
Maybe it could just read this stuff from a yaml file if it exists.
We indeed moved to an embedded resource, mainly because the acquisition of this file was a mess (I think in the repo alone, we had ~ 10 different versions at one point). It's great to hear someone was actually making use of this extension point (sorry for breaking you!). :-)
From where we stand right now, we may add a configuration setting that you as the caller can pass to AutoRest in order to use another dll for CodeGen (see https://github.com/Azure/autorest/tree/master/Samples to learn about our new configuration concept - configurability using CLI was blowing up)
We're making the plugins much more pluggable and replaceable in the next month or so. (was supposed to work on that this week, but got pre-empted by the overlords).
In the end, it should be much easier to use autorest with your own build of a given generator, and you won't need to build the whole project.
(sorry in the mean-time)
G
Any update on this?
Yes! :) If you...
We'd gladly provide more information depending on which way you wanna go or what your goals are :-)
@olydis
The first option is not an option as the goal of custom templates is to put them in a private repo and re-use Autorest as an npm package and then republish all together (this should work in a software factory in a scriptable way)
So second option seems to make this possible. But the goal is still to reuse existing stuff from AutoRest code generators. Can you confirm that it is possible to reuse AutoRest core classes i.e. for Swagger parsing and then just generate code with customized templates (that still implement AutoRest base classes) ?
@fhoering
The first option is almost exactly what you're stating.
The templates in the AutoRest Generators are based on Razor Templates, which are _compiled_ into c# code and then compiled with the rest of the code, so you can't just change the template and load it at runtime, as there's no way to even do that with Razor.
But the good news is, that it's terribly easy to change the generator, build your own package and reference it from the AutoRest command line:
# install gulp globally first
npm install -g gulp
# clone your fork
git clone https://github.com/YOURID/autorest.csharp
cd autorest.csharp
npm install
# make your changes and build
gulp build
# to test your changed version
autorest --use=csharp@c:\work\autorest.csharp --csharp --input-file=...
# when you are ready, create a package
npm pack
> microsoft.azure-autorest.csharp-2.1.0.tgz
You can then distribute your custom .tgz file or host it somewhere, and when someone needs to use it:
# from a URL
autorest --use=csharp@http://foo/microsoft.azure-autorest.csharp-2.1.0.tgz ...
#or a file location
autorest --use=csharp@c:/packages/microsoft.azure-autorest.csharp-2.1.0.tgz ...
@fearthecowboy I can be wrong, but it seems that those --use options are not working.
When I issue a commandline with ``--use=csharp@c:\mypath\mypackage.tgzI get an error message thatfoo@csharp@c:\mypath\mypackage.tgz``` could not be resolved.
I searched the code for foo and this is the part which must go sideways for some reason:
https://github.com/Azure/autorest/blob/master/src/autorest-core/lib/configuration.ts#L616
the command line I tried:
autorest --use=csharp@d:/work/autorest.csharp/microsoft.azure-autorest.csharp-2.2.0.tgz --input-file=swagger.yaml --csharp
It is pretty sure, that the regex is failing the test, because it filters out the path separators.
When I tried to use this:
autorest --use=d:/work/autorest.csharp/microsoft.azure-autorest.csharp-2.2.0.tgz --input-file=swagger.yaml --csharp
Then the error was the given argument is not a folder: Error: ENOTDIR: not a directory, scandir
This however worked:
autorest --use=d:/work/autorest.csharp --input-file=swagger.yaml --csharp
ah, yeah without the csharp@ at the front... sorry
I would be very interested in this. Has anyone created a Refit csharp generator? It would be awesome to have that as a core option, along with --fluent and --azure-arm
@fearthecowboy Why is this closed? Is it now possible to plug custom templates without recompiling the whole project?
NSWag supports this long time ago: https://github.com/RicoSuter/NSwag/wiki/Templates
Anybody?
Most helpful comment
@fearthecowboy Why is this closed? Is it now possible to plug custom templates without recompiling the whole project?
NSWag supports this long time ago: https://github.com/RicoSuter/NSwag/wiki/Templates