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
35.44k stars 10.02k forks source link

Compile Error After Upgrading - SDK 8.0.300, "AspNetCore" cannot be found #56220

Open mwmatlock-eprod opened 5 months ago

mwmatlock-eprod commented 5 months ago

Description

After upgrading from SDK 8.0.204 to SDK 8.0.300, "AspNetCore" cannot be found within "Microsoft.AspNetCore.Mvc" using statement. Compile fails, and attempts to extend/use ControllerBase fail because ControllerBase cannot be found due to this. Reverting to SDK 8.0.204 solves this.

Reversion process: choco uninstall dotnet-sdk choco install dotnet-sdk --version=8.0.204

To Reproduce

Can't currently provide a full repo or project to repro due to lack of time (sincere apologies), but the following file is a version of the file I'm seeing this in, with sensitive info renamed or removed.

namespace TestSupport;
using Autofac;
using Infrastructure.Logging.Modules;
using Microsoft.AspNetCore.Mvc;

public abstract class WebApiControllerScenario<TDerived, TController> : TransactionScopedScenario<TDerived>
    where TDerived : WebApiControllerScenario<TDerived, TController>
    where TController : ControllerBase {

    protected WebApiControllerScenario() {
        Controller = this.Resolve<TController>();
    }

    protected TController Controller { get; }

    protected override void RegisterModules(ContainerBuilder builder) {
        builder.RegisterModule<LoggingModule>();
    }

    protected override void RegisterScenarioTypes(ContainerBuilder builder) {
        builder.RegisterType<TController>().AsSelf();
    }
}

Exceptions (if any)

Further technical details

Runtime Environment: OS Name: Windows OS Version: 10.0.19045 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.300\

.NET workloads installed: [aspire] Installation Source: VS 17.10.34916.146 Manifest Version: 8.0.0/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.0.0\WorkloadManifest.json Install Type: Msi

[maui-windows] Installation Source: VS 17.10.34916.146 Manifest Version: 8.0.21/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maui\8.0.21\WorkloadManifest.json Install Type: Msi

[android] Installation Source: VS 17.10.34916.146 Manifest Version: 34.0.95/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.android\34.0.95\WorkloadManifest.json Install Type: Msi

[maccatalyst] Installation Source: VS 17.10.34916.146 Manifest Version: 17.2.8053/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maccatalyst\17.2.8053\WorkloadManifest.json Install Type: Msi

[wasm-tools-net6] Installation Source: VS 17.10.34916.146 Manifest Version: 8.0.5/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.workload.mono.toolchain.net6\8.0.5\WorkloadManifest.json Install Type: Msi

[wasm-tools-net7] Installation Source: VS 17.10.34916.146 Manifest Version: 8.0.5/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.workload.mono.toolchain.net7\8.0.5\WorkloadManifest.json Install Type: Msi

[ios] Installation Source: VS 17.10.34916.146 Manifest Version: 17.2.8053/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.ios\17.2.8053\WorkloadManifest.json Install Type: Msi

[wasm-tools] Installation Source: VS 17.10.34916.146 Manifest Version: 8.0.5/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.workload.mono.toolchain.current\8.0.5\WorkloadManifest.json Install Type: Msi

Host: Version: 8.0.5 Architecture: x64 Commit: 087e15321b

.NET SDKs installed: 3.1.426 [C:\Program Files\dotnet\sdk] 5.0.408 [C:\Program Files\dotnet\sdk] 6.0.422 [C:\Program Files\dotnet\sdk] 7.0.407 [C:\Program Files\dotnet\sdk] 8.0.105 [C:\Program Files\dotnet\sdk] 8.0.205 [C:\Program Files\dotnet\sdk] 8.0.300 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables: Not set

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download


- The IDE (VS / VS Code/ VS4Mac) you're running on, and its version
IDE: Visual Studio 2022, Rider 2024.1.2, Nuke, and dotnet build all produce this.

Workaround: Revert to sdk 8.0.204
MackinnonBuck commented 4 months ago

@mwmatlock-eprod, we think this is probably related to your environment. If you're able to provide us with a minimal repro project (hosted on GitHub as a public repository), we could try to reproduce the issue on our end.

Could you also please confirm whether updating to the latest SDK resolves the issue?

mwmatlock-eprod commented 4 months ago

@mwmatlock-eprod, we think this is probably related to your environment. If you're able to provide us with a minimal repro project (hosted on GitHub as a public repository), we could try to reproduce the issue on our end.

Could you also please confirm whether updating to the latest SDK resolves the issue?

@MackinnonBuck - Unfortunately, the newest (302) does not solve this issue. Reverting (to 204) still fixes it. I will see what I can do to get you a minimal repro repo.

mwmatlock-eprod commented 4 months ago

@MackinnonBuck - I was having trouble getting a repro repo for y'all (everything I tried that I could share without confidential IP just...worked. It was only within the stuff I wasn't allowed to share that was broken... >_>), and in the process I figured out the issue. One of the TestSupport CSPRoj's in the chain of projects (It's a DDD solution with a bunch of csproj's that all reference each other, and utilizes Autofac, MediatR, and DotNet TestContainers) needed this added:

<ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.OpenApi"/>
</ItemGroup>

I truly don't understand why it works on 204 and below without that reference but not anything after, but 300 and 302 both require that packageref being added at the lower level csproj. 204 does not need it, apparently. (Note: We build our projects using Nuke, and it always clears bin and obj folders before restoring and rebuilding, so I know it's not something getting left behind sometimes causing flickering issues). I would have expected it to just always be broken, honestly.

Either way, my situation is fixed and I can update to the newer framework. Thank y'all for your time!

mkArtakMSFT commented 4 months ago

@captainsafia maybe you see anything interesting here to suggest regarding why the package reference is now required?

mwmatlock-eprod commented 4 months ago

Some information about the structure of the project here, via a solution explorer screenshot. The ones with arrows pointed at them are directly all involved in the chain of the controller testing (almost all of them are referenced in a chain, but those are the key ones), and the one with a check mark is the one that already with 204 had MS.APNC.OPenApi referenced in it. The one with the star is the one I needed to add it to for 300 and 302. image