Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

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

未關閉
#39 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
35/100
Issue 類型
功能
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
csharp
領域
tooling

研究方向

先閱讀 dotnet-codegencs 進入點以及 issue 中提到的 TemplateBuilder 和 TemplateLoader 類別,然後追蹤 .csx 範本及其 #r 參考的處理方式。比較所要求的重用選項—#load、多個範本和本機 DLL 參考—並將「完成」定義為提供一種受支援的方式來共用範本邏輯,而不必在範本之間複製它。

由索引模型根據 Issue 內容生成。

描述

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!

主要語言
C#
星號
309
分支
40
PR 合併指標
30 天內沒有已合併 PR

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

Drizin/CodegenCS 的其他 Issue

查看 Drizin/CodegenCS 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。