Scaffolding fails with partial methods an source generator
- Dominant language
- C#
- Stars
- 818
- Forks
- 260
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 10
Description
### Describe the bug
When trying to scaffold identity pages in a project that contains `GeneratedRegex` it fails with `Failed to compile the project in memory`.
The full output:
```
Start checking required NuGet packages...
Checking 'Microsoft.EntityFrameworkCore.SqlServer' NuGet Package...
Checking 'Microsoft.EntityFrameworkCore.Tools' NuGet Package...
Checking 'Microsoft.AspNetCore.Identity.UI' NuGet Package...
Checking 'Microsoft.AspNetCore.Identity.EntityFrameworkCore' NuGet Package...
Checking 'Microsoft.VisualStudio.Web.CodeGeneration.Design' NuGet Package...
Building project 'Gnomeshade.WebApi'...
Check and install Code Generation tool...
Start scaffolding 'Identity'...
Running command: C:\Gnomeshade\source\Gnomeshade.WebApi\obj\dotnet-aspnet-codegenerator.exe --project C:\Gnomeshade\source\Gnomeshade.WebApi\Gnomeshade.WebApi.csproj --target-framework net7.0 --configuration "Release" --no-build identity --dbContext Gnomeshade.Data.Identity.IdentityContext --files "Account.Login" --layout ~/Views/Shared/_Layout.cshtml
Finding the generator 'identity'...
Running the generator 'identity'...
Failed to compile the project in memory
C:\Gnomeshade\source\Gnomeshade.WebApi\V1\Importing\Paperless\Rimi\RimiPurchaseIdentifier.cs(70,31): error CS8795: Partial method 'RimiPurchaseIdentifier.PriceRegex()' must have an implementation part because it has accessibility modifiers.
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:04.95
Scaffolding 'Identity' has finished with errors:
* Scaffold item command has finished with error: Failed to compile the project in memoryC:\Gnomeshade\source\Gnomeshade.WebApi\V1\Importing\Paperless\Rimi\RimiPurchaseIdentifier.cs(70,31): error CS8795: Partial method 'RimiPurchaseIdentifier.PriceRegex()' must have an implementation part because it has accessibility modifiers.
```
And the code causing the error
```csharp
public sealed partial class RimiPurchaseIdentifier
{
[GeneratedRegex(@"\d{1,},\d{2}", RegexOptions.IgnoreCase)]
private static partial Regex PriceRegex();
}
```
Also seems similar to #1552, but that one did not mention source generators.
### Further technical details
Microsoft.VisualStudio.Web.CodeGeneration.Design version 7.0.4
dotnet --version 7.0.102
Contributor guide
Assessment
This issue has not been assessed yet.