Skip to main content

Tool for generating dotnet code

Project description

Dotnet generate

PyPI

Script generator for dotnet core 2.x

Tool for making it easier to generate MVC and API controllers in Asp.NET Core applications. Helps also with managing DB migrations and updates.

Installation

I have tested it with Python 3.6 only

Install it via pip/pip3 pip install dotnet-generate.

Examples

Examples executed in dotnet core 2.1 solution folder, with the following structure

├── DAL
│   └── AppDbContext.cs
├── Domain
│   ├── BaseEntity.cs
│   ├── Contact.cs
│   ├── ContactType.cs
│   ├── Domain.csproj
│   ├── Identity
│   │   ├── AppRole.cs
│   │   └── AppUser.cs
│   └── Person.cs
└── WebApp
    ├── Startup.cs
    ├── Program.cs
    ...

Migrations

To make new migrations run:

dotnet-generate migrate MigrationName

Migrate command has some additional options:

  • -u, -update for updating DB to latest migration.
  • -m, --mvc for creating MVC controllers.
  • -a, --api for creating API controllers.
  • -t, --try this option runs the tool without actually executing any commands, instead it will print those commands to console.

You can also combine these flags, for example you can generate shell script with all the commands as follows:

dotnet-generate migrate MigrationName -umat > script.sh

Which will produce the following script.sh

dotnet ef migrations add MigrationName --project DAL --startup-project WebApp
dotnet ef database update --project DAL --startup-project WebApp
cd WebApp/
dotnet aspnet-codegenerator controller -name PersonsController -actions -m Person -dc AppDbContext -outDir Controllers --useDefaultLayout --useAsyncActions --referenceScriptLibraries -f
dotnet aspnet-codegenerator controller -name ContactsController -actions -m Contact -dc AppDbContext -outDir Controllers --useDefaultLayout --useAsyncActions --referenceScriptLibraries -f
dotnet aspnet-codegenerator controller -name ContactTypesController -actions -m ContactType -dc AppDbContext -outDir Controllers --useDefaultLayout --useAsyncActions --referenceScriptLibraries -f
cd ../
cd WebApp/
dotnet aspnet-codegenerator controller -name PersonsController -actions -m Person -dc AppDbContext -outDir Api/Controllers -api --useAsyncActions -f
dotnet aspnet-codegenerator controller -name ContactsController -actions -m Contact -dc AppDbContext -outDir Api/Controllers -api --useAsyncActions -f
dotnet aspnet-codegenerator controller -name ContactTypesController -actions -m ContactType -dc AppDbContext -outDir Api/Controllers -api --useAsyncActions -f
cd ../

Db updating

For updating db run

dotnet-generate update

MVC controllers.

For generating MVC controllers run

dotnet-generate mvc

API controllers.

For generating API controllers run

dotnet-generate api

Installation for local build

If you want to make this tool better, then you can make local releases like this:

  1. Fork/Clone this project.
  2. Navigate to project dir.
  3. Edit the code.
  4. Install the CLI tool. pip3 install --editable .
  5. Check that tool is installed dotnet-generate --help
  6. If everything works, make new pull request?

Built with

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for dotnet-generate, version 0.5.0
Filename, size File type Python version Upload date Hashes
Filename, size dotnet_generate-0.5.0-py3-none-any.whl (4.7 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size dotnet-generate-0.5.0.tar.gz (3.5 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page