This is a TypeSpec library that will emit a .NET SDK from TypeSpec.
Install Node.js 16 or above. (Verify by node --version
)
Install .NET 8.0 SDK for your specific platform. (or a higher version)
Follow TypeSpec Getting Started to initialize your TypeSpec project.
Make sure npx tsp compile .
runs correctly.
Run npm install @typespec/http-client-csharp
.
Run command npx tsp compile --emit @typespec/http-client-csharp <path-to-typespec-file>
e.g.
npx tsp compile main.tsp --emit @typespec/http-client-csharp
You can further configure the SDK generated, using the emitter options on @typespec/http-client-csharp.
You can set options in the command line directly via --option @typespec/http-client-csharp.<optionName>=XXX
, e.g. --option @typespec/http-client-csharp.namespace=MyService.Namespace
or
Modify tspconfig.yaml
in typespec project, add emitter options under options/@typespec/http-client-csharp.
emit:
- "@typespec/http-client-csharp"
options:
"@typespec/http-client-csharp":
+ namespace: MyService.Namespace
Supported Emitter options:
namespace
define the client library namespace. e.g. MyService.Namespace.emitter-output-dir
define the output dire path which will store the generated code.generate-protocol-methods
indicate if you want to generate protocol method for every operation or not. The default value is true.generate-convenience-methods
indicate if you want to generate convenience method for every operation or not. The default value is true.unreferenced-types-handling
define the strategy how to handle the unreferenced types. It can beremoveOrInternalize
,internalize
orkeepAll
model-namespace
indicate if we want to put the models in their own namespace which is a sub namespace of the client library namespace plus ".Models". if it is setfalse
, the models will be put in the same namespace of the client. The default value istrue
.clear-output-folder
indicate if you want to clear up the output folder.package-name
define the package name.
By default, TypeSpec csharp generates all protocol APIs and convenience APIs. A few exceptions are API of JSON Merge Patch, and API of long-running operation with ambiguous response type.
You can configure whether generate convenience API or not via convenienceAPI
decorator.