[Feature request, dotnet-codegencs] Be able to reuse code for templates
- 主要言語
- C#
- スター
- 307
- フォーク
- 40
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
Hi!
First of all, thank you very much for the tool! It is easy to use, it's simple and it keeps saving a lot of time for our team.
Second, I need an advice on how to to reuse code for templates while keeping "text template + codegen tool" approach. We do use dotnet-codegencs tool to scaffold boilerplate code for our projects. Something like `dotnet new` but with some logic involved. It will be nice to be able to reuse basic logic and do not copypaste it across csx templates.
What I have tried so far
## Use `#load` directive
Sadly, this option is not supported. The `TemplateBuilder` supports only `#r` directives.
## Pass multiple templates as args to the dotnet-codegencs tool
Not supported, there currently can be only one template
## reference local dll (not nuget package)
```
#r "ScaffoldHelpers.dll"
...
```
or
```
dotnet-codegencs template run .\TestTemplate.csx -r .\ScaffoldHelpers.dll
```
Fail with
```
Unhandled exception: System.TypeInitializationException: The type initializer for 'TestTemplate' threw an exception.
---> System.IO.FileNotFoundException: Could not load file or assembly 'ScaffoldHelpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
```
the reason is that referenced assemblies are not copied into the build directory and are not loaded by TemplateLoader.
## Write custom runner using TemplateBuilder / TemplateLoader classes
Sadly, these are not distributed as a nuget packages, only as a part of dotnet-codegencs tool
## Fork the dotnet-codegencs
We are currently using custom fork but it looks like a hack, I'd prefer to keep using original tool:)
Thanks in advance, hope you have a good Holidays!
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
まず dotnet-codegencs のエントリーポイントと、issue で言及されている TemplateBuilder クラスおよび TemplateLoader クラスを読み、次に .csx テンプレートとその #r 参照がどのように処理されるかを追跡します。要求されている再利用方法—#load、複数のテンプレート、ローカル DLL 参照—を比較し、テンプレート間でコピーせずにテンプレートのロジックを共有できるサポートされた方法を提供できた状態を完了と定義します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- csharp
- 領域
- tooling
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100