適用於Visual Studio的Python代碼生成器? (Python code generator for Visual Studio?)


問題描述

Visual Studio 的 Python 代碼生成器? (Python code generator for Visual Studio?)

我有一個想法,如果我將 python .py 文件添加到我的 C# 項目中,並使用將執行 python 文件的自定義生成器標記該文件,並將輸出視為代碼生成的結果,即。將其放入 C# 文件中,這樣我就可以在構建過程中生成大量代碼。

有人知道是否存在這樣的 Visual Studio 2008 自定義生成器嗎?


參考解法

方法 1:

I think Cog does what you want.

方法 2:

I recall that in previous versions of VS, there was a way to add custom build steps to the build process. I used that a lot to do exactly the kind of automated code generation you describe.

I imagine the custom build step feature is still there in 2008.

方法 3:

I don't understand what you are trying to do here. Are you trying to execute a Python script that generates a C# file and then compile that with the project? Or are you trying to compile a Python script to C#?

方法 4:

OK, I see. Well, as far as I know there isn't any code generator for Python. There is a good introduction on how to roll your own here.

Actually, that's quite an under‑used part of the environment, I suppose it's so because it needs you to use the IDE to compile the project, as it'd seem only the IDE knows about these "generators", but MSBuild ignores them.

方法 5:

I dug through my old bookmarks (I love Del.icio.us!) and found this article: Code Generation with Python, Cog, and Nant. Keep in mind that anything you can do in NAnt can probably be done in MSBuild as well. This should be enough to get you started.

(by Lasse V. KarlsenjwfearnGreg Hewgilldguaragliadguaragliatechnomalogical)

參考文件

  1. Python code generator for Visual Studio? (CC BY‑SA 2.5/3.0/4.0)

#Code-Generation #Python #visual-studio-2008






相關問題

關於編譯器中代碼生成的參考(中間表示、SSA、指令選擇、寄存器分配等)? (References on code generation in a compiler (intermediate representations, SSA, instruction selection, register allocation, etc.)?)

如何在每個新模塊中自動注入輔助類? (How to automatically inject helper classes in each new module?)

適用於Visual Studio的Python代碼生成器? (Python code generator for Visual Studio?)

為什么生成執行操作的 Java 代碼比“解釋器循環”運行得更慢? (Why does Java code generated to perform an operation run more slowly than an "interpreter loop"?)

ORM 映射的代碼生成工具 (code generation tool for ORM mapping)

Delphi 的 x86 代碼生成器框架 (x86 code generator framework for Delphi)

適用於 xpand 的 Actionscript 3 代碼美化器(MWE2 工作流程) (Actionscript 3 code beautifier for xpand (MWE2 Workflow))

Maven 中的代碼生成 (Code generation in Maven)

在自定義生成器中生成嵌套路由 (Generating nested routes in a custom generator)

是否有類似 JET(Java Emitter Templates)但沒有 Eclipse 依賴項的東西? (Is there something like JET (Java Emitter Templates) but without Eclipse-dependencies?)

Python函數,它返回自己的帶有參數的簽名 (Python function which returns its own signature with parameters)

為什麼 protobuf 更喜歡代碼生成器而不是運行時動態加載 (why protobuf prefer code-generator other than dynamic loading at runtime)







留言討論