dotnet / Scaffolding

Code generators to speed up development.
MIT License
639 stars 228 forks source link

Identity scaffolding failed in VS 2019 when updating the package to v3.0.0-preview5-19264-04 #997

Closed Yuant-tobing closed 5 years ago

Yuant-tobing commented 5 years ago

While I add the new scaffold item for the fresh my ASP-NET Core 3 Web-Api project for the first time, it worked perfectly. But, I found the scaffold-generator making several folders on my project and all identity data was placed in the area folder. For some reason, I want to re-scaffold new one and try other costumes in the parameters. Before I try again using the scaffold-generator, I delete all the files and folders added by the previous scaffold-generator and update some packages by Nuget Package Manager, this time an error appears as below.

Error message on console

Finding the generator 'identity'...
Running the generator 'identity'...
There was an error running the template C:\Users\yuant\.nuget\packages\microsoft.visualstudio.web.codegenerators.mvc\3.0.0-preview5-19264-04\Templates\Identity\Pages\_Layout.cshtml: Template Processing Failed:(95,13): error CS0103: The name 'BeginWriteAttribute' does not exist in the current context
(96,13): error CS0103: The name 'EndWriteAttribute' does not exist in the current context
   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)

Error message on IDE

Error-scaffold

my.csproj

<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <LangVersion>8.0</LangVersion>
  </PropertyGroup>

<ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.0.0-preview5-19227-01" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.0.0-preview5-19227-01" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0-preview5-19227-01" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0-preview5.19227.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite" Version="3.0.0-preview5.19227.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0-preview5.19227.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0-preview5.19227.9" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0-preview5-19264-04" />
  </ItemGroup>

</Project>

Is the error message like above caused by a package update or something else? Can I get clues to resolve this problem. TY

Microsoft Visual Studio 2019 16.0.4 Microsoft Windows 10

seancpeters commented 5 years ago

The problem is most likely caused by using the older version of the Microsoft.VisualStudio.Web.CodeGeneration.Design package, in conjunction with newer EntityFramework and Razor packages. There are some breaking changes in the 3.0.0-* EF & Razor packages, which caused some changes to need to be made in the scaffolding code.

If you can post the .csproj file with the package versions that caused the error to occur, I should be able to confirm that this is the problem.

seancpeters commented 5 years ago

One more thought - you may want to update your Visual Studio instance to 16.0.5 preview 1. There are also some changes in VS for scaffolding to deal with the Razor & EF changes.

lailaDev commented 5 years ago

I have the same problem when i try to generate 'new scaffold item' for the first time for a 'react' project , with latest version of visual studio 2019 (16.2.0 Preview 1.0) and .net core SDK. in attachement my .csproj file Csproj.txt

midub commented 5 years ago

The same issue when using ASP.NET Core Angular template with Authentication

seancpeters commented 5 years ago

Looking deeper in to this, I have found the root cause of the issue. Working on a fix - I'll update this thread when a PR is ready.

ghost commented 5 years ago

@seancpeters Are we anywhere close to a release? Having same issue with a .NET Core API + Angular app with Authentication. Any workarounds in the mean time?

seancpeters commented 5 years ago

The 3.0.0 release will have a fix for this issue, and is coming relatively soon We may release another preview prior to that, but uncertain at this point.

acorrow commented 5 years ago

@seancpeters is there going to be a Preview 7 to go along with the changes in core 3.0 preview 7?

vijayrkn commented 5 years ago

Latest version of Scaffolding packages that matches the .NET Core releases has been released. Closing the issue.

GateauChoco commented 3 years ago

Hey guys ! know this post is not recent but I am dealing with the same issue. @seancpeters Your PR has been approved ?