Drizin / Drizin/CodegenCS

[Feature request, dotnet-codegencs] Be able to reuse code for templates

未关闭
#39 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
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!

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。