Skip to main content
net9.0

ASP.NET Core OData Web API Template Pack for Microsoft Template Engine To install the templates in this package, run 'dotnet new --install Microsoft.OData.WebApiTemplate::1.0.0-preview.2'.

Published
Apr 27, 2025
1y ago
Total Downloads
1.7K
1,738

Install

dotnet add package Microsoft.OData.WebApiTemplate --version 1.0.0-preview.2
ProductVersions
.NET
net9.0

README

ASP.NET Core OData Web API Template Pack

This .NET template helps you create an ASP.NET Core Web API project with OData support. It supports different configurations for .NET 8.0 and above, with appropriate setup for each version.

Prerequisites

Getting Started

Follow these steps to use the template locally:

1. Install the Template

Install the template using the dotnet new command:

dotnet new install Microsoft.OData.WebApiTemplate

To specify the PackageVersion explicitly:

dotnet new install Microsoft.OData.WebApiTemplate::<PackageVersion>

2. Create a New Project Using the Template

You can create a new project using the template with different target frameworks and OData versions. Here are some examples:

View Template Options
dotnet new odata-webapi --help
Usage:
  dotnet new odata-webapi [options] [template options]

Options:
  -n, --name <name>       The name for the output being created. If no name is specified, the name of the output directory is used.
  -o, --output <output>   Location to place the generated output.
  --dry-run               Displays a summary of what would happen if the given command line were run if it would result in a template creation.
  --force                 Forces content to be generated even if it would change existing files.
  --no-update-check       Disables checking for the template package updates when instantiating a template.
  --project <project>     The project that should be used for context evaluation.
  -lang, --language <C#>  Specifies the template language to instantiate.
  --type <project>        Specifies the template type to instantiate.

Template options:
  -f, --framework <net8.0|net9.0>                           The target framework for the project.
                                                            Type: choice
                                                              net8.0  Target net8.0
                                                              net9.0  Target net9.0
                                                            Default: net9.0
  -qo, --query-option <count|expand|filter|orderby|select>  OData query options
                                                            Type: choice
                                                              filter   Enable $filter query option
                                                              select   Enable $select query option
                                                              expand   Enable $expand query option
                                                              orderby  Enable $orderby query option
                                                              count    Enable $count query option
                                                            Multiple values are allowed: True
                                                            Default: filter|select|expand|orderby|count
  --no-dollar                                               Whether or not the OData query options should be prefixed with '$'
                                                            Type: bool
                                                            Default: true
  -ci, --case-insensitive                                   Enable case insensitive for the controller/action/property name in conventional routing
                                                            Type: bool
                                                            Default: true
  --enable-batching                                         Allowing OData batching
                                                            Type: bool
                                                            Default: false
  --configurehttps                                          Configure HTTPS
                                                            Type: bool
                                                            Default: true
  --enable-openapi                                          Enable OpenAPI (Swagger) support
                                                            Type: bool
                                                            Default: false
  --use-program-main                                        Whether to generate an explicit Program class and Main method instead of top-level statements.
                                                            Type: bool
                                                            Default: false
  --exclude-launch-settings                                 Whether to exclude launchSettings.json in the generated template.
                                                            Type: bool
                                                            Default: false
  --no-restore                                              If specified, skips the automatic restore of the project on create.
                                                            Type: bool
                                                            Default: false
Create template with default settings
dotnet new odata-webapi -n MyODataService1
Specify .NET framework
dotnet new odata-webapi -n MyODataService2 -f net8.0
Enable OData batching
dotnet new odata-webapi -n MyODataService3 --enable-batching true
Enable query options
dotnet new odata-webapi -n MyODataService4 --query-option filter select expand
Enable OpenAPI/Swagger
dotnet new odata-webapi -n MyODataService5 --enable-openapi true

3. Run the Project

Navigate to the project directory and run the project using the dotnet run command:

cd MyODataService.API1
dotnet run

4. Uninstall the Template

Uninstall the template using the dotnet new command:

dotnet new uninstall Microsoft.OData.WebApiTemplate

Project Structure

The generated project will have the following structure:

ODataWebApiApplication/
β”œβ”€β”€ Controllers/
β”‚   └── CustomersController.cs
β”œβ”€β”€ Models/
β”‚   └── Customer.cs
β”‚   └── EdmModelBuilder.cs
β”‚   └── Order.cs
β”œβ”€β”€ Properties/
β”‚   └── launchSettings.json
β”œβ”€β”€ ODataWebApiApplication.csproj
β”œβ”€β”€ ODataWebApiApplication.http
β”œβ”€β”€ Program.cs
└── appsettings.Development.json
└── appsettings.json

Repository

https://github.com/OData/ODataDotNetTemplate

Changes from Previous Version

No structural changes between v1.0.0-preview.1 and v1.0.0-preview.2.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 1 target framework; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.