Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASP.NET Core MVC scaffolding fails in vs 2019 #104

Closed
jrydow opened this issue Nov 25, 2019 · 3 comments
Closed

ASP.NET Core MVC scaffolding fails in vs 2019 #104

jrydow opened this issue Nov 25, 2019 · 3 comments
Labels
help wanted need info More info needed to diagnose the issue

Comments

@jrydow
Copy link

jrydow commented Nov 25, 2019

When using the following code in .net core 3 mvc web project the scaffolding of views fails.

public class HomeController : Controller
    {
        public IActionResult About()
        {
            ViewData["Message"] = $"Built from commit: {ThisAssembly.Git.Sha}";
            return View();
        }
}

When trying to scaffold a view via add->View I get this:

Finding the generator 'view'...
Running the generator 'view'...
Could not get the reflection type for Model : SubscriptionViewModel
   at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.<BuildCommandLine>b__6_0()

If I remove the {ThisAssembly.Git.Sha} I have no problem scaffolding a view.

Steps to reproduce in VS 2019:

  1. File -> New project ASP .net Core Web Application
  2. Give a name, Create
  3. use .net core, ASP .net core 3.0, Web application (Model-Veiw-Controller)
  4. Add this class to Models
namespace ScaffoldFail.Models
{
    public class CustomerViewModel
    {
        public int MyProperty { get; set; }
    }
}
  1. Add nuget gitinfo version 2.0.21, latest at time of writing.
  2. Add this to Home Controller:
        public IActionResult About()
        {
            ViewData["Message"] = $"Built from commit: {ThisAssembly.Git.Sha}";
            return View();
        }
  1. Right click Views (in solution explorer) -> Add -> view
  2. View name: Details, Template: Details Model class: CustomerViewModel -> Click Add
    After a while a dialog shows up saying 'Could not get the reflrction type for Model : CustomerViewModel'.
    The Output window gives the following information:
Finding the generator 'view'...
Running the generator 'view'...
Could not get the reflection type for Model : CustomerViewModel
   at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.<BuildCommandLine>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)

Modifying the line in HomeController to this:

        public IActionResult About()
        {
            ViewData["Message"] = $"Built from commit: ";// {ThisAssembly.Git.Sha}";
            return View();
        }

and try to scaffold again (redo point 7 and 8 above) and the scaffolding does produce what it is supposed to. This means that using ThisAssembly.Git.Sha breaks the scaffolding of views.

@kzu
Copy link
Member

kzu commented Sep 20, 2020

I'm afraid I don't know what targets the MVC scaffolding are calling on why it would need (or even fail) the generated file. Could use help here.

@kzu kzu changed the title Scaffolding fails in vs 2019 ASP.NET Core MVC scaffolding fails in vs 2019 Sep 20, 2020
@kzu kzu added the need info More info needed to diagnose the issue label Sep 20, 2020
@YounesCheikh
Copy link

@jrydow I'm having the same problem with VS2019 and with aspnet-codegenerator 😢
Did you find a solution?

@kzu
Copy link
Member

kzu commented Feb 7, 2023

Doesn't look like there's anything actionable here. I tried with nothing but some other source generator based packages (any from ThisAssembly.* for example) and they also fail the same way. Looks like the way the scaffolding is using roslyn to build the project during scaffold doesn't properly support packages or analyzers or both. I've scanned many such issues all over. Seems to be a very brittle feature on the ASP.NET MVC side :(

@kzu kzu closed this as not planned Won't fix, can't repro, duplicate, stale Feb 7, 2023
@devlooped devlooped locked and limited conversation to collaborators Sep 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted need info More info needed to diagnose the issue
Projects
None yet
Development

No branches or pull requests

3 participants