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.

Source Distribution

dotnet-generate-0.5.0.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

dotnet_generate-0.5.0-py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page