dotnet / dotnet/Scaffolding

Scaffolding won't work with with GRPC/Protobuf generator

Open
#1,316 3 comments 0 reactions 0 assignees View on GitHub
area-scaffolding Feature
Dominant language
C#
Stars
818
Forks
260
Avg merge
1d 8h
Merged PRs (30d)
10

Description

## Steps to reproduce:

1. Follow the tutorial on https://docs.microsoft.com/en-us/aspnet/core/tutorials/grpc/grpc-start?view=aspnetcore-3.1&tabs=visual-studio to create a project with GRPC & proto definitions. Make sure EF Core/DB context are used & generated
- Install `Grpc.Net.Client`, `Google.Protobuf` and `Grpc.Tools`
- Add proto definition in .csproj
- Use the auto-generated protobuf class anywhere in the code, e.g. create a GreeterClient anywhere
2. Try scaffolding an identity page with data context:
`dotnet aspnet-codegenerator identity -fi Account.Register -dc ScaffoldingAndGrpc.Data.ApplicationDbContext`

The code was uploaded to https://github.com/sakamoto-poteko/ScaffoldingAndGrpcBug
## Expected behavior:
Generate scaffolded identity codes.

## Actual behavior:
App successfully builds and runs. However, when scaffolding identity, it fails with output "Failed to compile the project in memory", indicating protobuf generated classes are not found.
```
PM> $env:codegen_trace = 1
PM> dotnet aspnet-codegenerator identity -fi Account.Register -dc ScaffoldingAndGrpc.Data.ApplicationDbContext
[Trace]: Command Line: identity -fi Account.Register -dc ScaffoldingAndGrpc.Data.ApplicationDbContext
Building project ...
[Trace]: Command Line: --no-dispatch --port-number 45089 identity -fi Account.Register -dc ScaffoldingAndGrpc.Data.ApplicationDbContext --dispatcher-version 3.1.2+aa58b3de6300ec8ebe2bf027748f910f02012660
Finding the generator 'identity'...
Running the generator 'identity'...
dotnet : Failed to compile the project in memory
At line:1 char:1
+ dotnet aspnet-codegenerator identity -fi Account.Register -dc Scaffol ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Failed to compile the project in memory:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

D:\deleteme\ScaffoldingAndGrpc\ScaffoldingAndGrpc\Program.cs(15,23): error CS0246: The type or namespace name 'Greeter2' could not be found (are you missing a using directive or an assembly reference?)

D:\deleteme\ScaffoldingAndGrpc\ScaffoldingAndGrpc\Program.cs(31,27): error CS0246: The type or namespace name 'Greeter2' could not be found (are you missing a using directive or an assembly reference?)

at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.b__6_0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.Execute(String[] args)
at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)
RunTime 00:00:08.05
```

## Additional information about the project being scaffolded
### Target framework(s):
.Net Core 3.1

### Package version of Microsoft.AspNetCore.App or Microsoft.AspNetCore.All (if applicable):

### Package version of Microsoft.VisualStudio.Web.CodeGeneration.Design - this may be added to your project by scaffolding:
3.1.1

```
PM> dotnet tool update -g dotnet-aspnet-codegenerator
Tool 'dotnet-aspnet-codegenerator' was reinstalled with the latest stable version (version '3.1.2').
PM> dotnet list package
Project 'ScaffoldingAndGrpc' has the following package references
[netcoreapp3.1]:
Top-level Package Requested Resolved
> Google.Protobuf 3.11.4 3.11.4
> Grpc.Net.Client 2.28.0 2.28.0
> Grpc.Tools 2.28.1 2.28.1
> Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore 3.1.3 3.1.3
> Microsoft.AspNetCore.Identity.EntityFrameworkCore 3.1.3 3.1.3
> Microsoft.AspNetCore.Identity.UI 3.1.3 3.1.3
> Microsoft.EntityFrameworkCore.SqlServer 3.1.3 3.1.3
> Microsoft.EntityFrameworkCore.Tools 3.1.3 3.1.3
> Microsoft.VisualStudio.Web.CodeGeneration.Design 3.1.1 3.1.1
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.