Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#39 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
csharp
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu bằng cách đọc entry point dotnet-codegencs và các lớp TemplateBuilder và TemplateLoader được đề cập trong issue, sau đó theo dõi cách một template .csx và các tham chiếu #r của nó được xử lý. So sánh các tùy chọn tái sử dụng được yêu cầu—#load, nhiều template và các tham chiếu DLL cục bộ—và xác định hoàn thành là khi có một cách được hỗ trợ để dùng chung logic của template mà không phải sao chép logic đó giữa các template.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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!

Ngôn ngữ chính
C#
Star
307
Fork
40
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Drizin/CodegenCS

Tất cả issue của Drizin/CodegenCS

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.