dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
34.88k stars 9.85k forks source link

MVC View not found when deploying to Azure with Azure DevOps pipeline since SDK 8.0.200 #56298

Open Eirenarch opened 5 months ago

Eirenarch commented 5 months ago

Not sure where to report this but since the release of .NET SDK 8.0.2 my builds in Azure DevOps that deploy to Azure do not include the MVC razor views so the websites can't find them. If I modify the pipeline to fix the SDK to 8.0.100 they work as intended. I downloaded and decompiled the dll deployed with the 8.x setting and indeed it does not contain AspNetCoreGeneratedDocument namespace with the compiled views. I verified that with 8.x setting Azure DevOps pipeline logs do indeed show 8.0.200 as the version of the SDK used. If I publish a build to locally to a folder on my computer the dll does contain the MVC views

To Reproduce

Not sure honestly. This is the relevant part of the pipeline yaml

- task: UseDotNet@2
  displayName: 'Use .NET Core sdk'
  inputs:
    packageType: sdk
    version: 8.x
    installationPath: $(Agent.ToolsDirectory)/dotnet

- task: NuGetToolInstaller@1
  displayName: Use NuGet

- task: NuGetCommand@2
  displayName: NuGet Restore
  inputs:
    restoreSolution: '$(solution)'
    command: restore

- task: VSBuild@1
  displayName: Build Solution
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
bardiente commented 5 months ago

We had this same issue as well. We were getting this error:

System.InvalidOperationException: Cannot find the fallback endpoint specified by route values: { page: /_Host, area: }. at async Task Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.DynamicPageEndpointMatcherPolicy.ApplyAsync(HttpContext httpContext, CandidateSet candidates) at async Task Microsoft.AspNetCore.Routing.Matching.DfaMatcher.SelectEndpointWithPoliciesAsync(HttpContext httpContext, IEndpointSelectorPolicy[] policies, CandidateSet candidateSet) at async Task Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)+AwaitMatch(?)

Downgrading the SDK to 8.0.102 also fixed our error.

johnjardinemd commented 4 months ago

Is this the same as the error reported here https://www.reddit.com/r/dotnet/comments/14zd7zp/comment/krftd75/?utm_source=share&utm_medium=web2x&context=3 and here https://techcommunity.microsoft.com/t5/net-runtime/net-8-0-2-update-causes-asp-net-core-mvc-index-view-not-found/m-p/4058976 ? I too, have noticed that the latest .NET8 SDK seems to be responsible.

For the sake of helping with SEO, the error reads:

An unhandled exception occurred while processing the request.
InvalidOperationException: The view 'Index' was not found. The following locations were searched:
/Views/Home/Index.en-CA.cshtml
/Views/Home/Index.en.cshtml
/Views/Home/Index.cshtml
/Views/Shared/Index.en-CA.cshtml
/Views/Shared/Index.en.cshtml
/Views/Shared/Index.cshtml

And the cshtml files exist on disk. For me this only impact local development. My release build, (published as a self-contained executable) still works fine.

I'll use the old SDK for now, but hopefully this can be looked at.

EDIT: my bad. doesn't appear to be the exact same thing, even though they are both related to Views that cannot be found. EDIT 2: If you have my issue, upgrade VS to the latest and it will go away. No SDK downgrade required.

Scriptman commented 1 month ago

I'm currently having the same issue.

Debugging with VS is working fine (runtime compilation enabled).

But publishing is not working.

Compiled on my laptop, running 8.0.200, results in InvalidOperationException: The view 'Index' was not found. Compiled on an Ubuntu server running 8.0.105, results in InvalidOperationException: The view 'Index' was not found.

So my site is looking fantastic online with a 500 - Internal Server Error page :)

MackinnonBuck commented 1 month ago

Could someone confirm whether the latest SDK fixes the problem? @johnjardinemd's comment here suggests that an SDK update might have fixed it.

Scriptman commented 1 month ago

It did not solve anything for me. Upgrading, downgrading.. i removed all my controllers and then it was working, so im serving some static razor pages now.

MackinnonBuck commented 4 weeks ago

Thanks, @Scriptman.

If possible, could you (or anyone else experiencing this issue) provide us with a minimal repro project that demonstrates the problem, hosted as a public GitHub repository? That would allow us to investigate this issue further. Thanks!

danroth27 commented 4 weeks ago

@Scriptman What's the latest version of the .NET 8 SDK that you have tried? 8.0.200 is pretty old at this point. Latest is 8.0.302.

Eirenarch commented 3 weeks ago

It seems to be working with the latest SDK on Azure Pipelines. However I tested 8.0.200 and it also worked. Maybe the problem was on the side of Azure Pipelines and they fixed it (or I messed up the tests)