Cadl MSBuild Target Library
This package enables API First development of RPaaS services using Cadl. It adds build targets to generate an ASP.Net MVC controller and OpenAPI definition from a Cadldescription for the service. The package includes msbuild target files and a custom Cadl build task, integrating API-First development using Cadl into the project simply.
Getting started
- create a ASP.NET project.
- add the nuget package reference to the project dependencies in VisualStudio.
- init a cadl project into './cadl' by following the below instructions:
cd path/to/your/project
mkdir cadl
npm init -y
npm install -g @cadl-lang/compiler
npm install @cadl-lang/rest @azure-tools/cadl-autorest @azure-tools/cadl-rpaas @azure-tools/cadl-rpaas-controller
-
add a .cadl file into the './cadl' folder.
-
add the following configuration in your project file (using 'main.cadl' as example):
<ItemGroup>
<CadlCompile Include="cadl\main.cadl" />
</ItemGroup>
- then you can edit the cadl file to define models and ARM resources, the service code and swagger will be generated into the output directory automatically.
Configuration
Cadl Root directory
Specify the Root
option if you want to put your .cadl files into other folder instead of the './cadl' , it must be a relative path .
<ItemGroup>
<CadlCompile Include="cadl\main.cadl" Root="<other dir>" />
</ItemGroup>
Output path
Specify the OutputDir
option, this changes the directory where the OpenAPI specification (openapi.json) and service code wil be omitted, by default the directory is '$(IntermediateOutputPath)' which is a common msbuild project property.
<ItemGroup>
<CadlCompile Include="cadl\main.cadl" OutputDir="<other dir>" />
</ItemGroup>