dotnet / aspire

Tools, templates, and packages to accelerate building observable, production-ready apps
https://learn.microsoft.com/dotnet/aspire
MIT License
3.88k stars 469 forks source link

Unclear error if you remove `IsAspireHost` from csproj #6142

Open afscrome opened 1 month ago

afscrome commented 1 month ago

Is there an existing issue for this?

Describe the bug

If you remove the <IsAspireHost>true</IsAspireHost> from your csproj, you end up with an error WaitFor.AppHost is an Aspire AppHost project but necessary dependencies aren't present. Are you missing an Aspire.Hosting.AppHost PackageReference even if you already reference the Aspire.Hosting.AppHost package.

Expected Behavior

The error should be updated to make it clear you need to add IsAspireHost to your csproj.

Alternatively, is this property even needed after moving from a workload to the SDK? The SDK is called Aspire.AppHost.Sdk so I'd have thought the presence of the SDK in the csproj implies the project is an Aspire Host.

Steps To Reproduce

<Project Sdk="Microsoft.NET.Sdk">
  <Sdk Name="Aspire.AppHost.Sdk" Version="9.0.0-preview.4.24504.2" />
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <UserSecretsId>18d77ca6-cadf-4565-aa98-fd8321daf6c4</UserSecretsId>
    <!-- <IsAspireHost>true</IsAspireHost> -->
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\WaitFor.ApiService\WaitFor.ApiService.csproj" />
    <ProjectReference Include="..\WaitFor.Web\WaitFor.Web.csproj" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Aspire.Hosting.AppHost" Version="9.0.0-preview.4.24504.11" />
    <PackageReference Include="Aspire.Hosting.PostgreSQL" Version="9.0.0-preview.4.24504.11" />
    <PackageReference Include="Aspire.Hosting.Redis" Version="9.0.0-preview.4.24504.11" />
    <PackageReference Include="Aspire.Hosting.SqlServer" Version="9.0.0-preview.4.24504.11" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
  </ItemGroup>

</Project>

Exceptions (if any)

Severity    Code    Description Project File    Line    Suppression State
Warning (active)    ASPIRE002   WaitFor.AppHost is an Aspire AppHost project but necessary dependencies aren't present. Are you missing an Aspire.Hosting.AppHost PackageReference? WaitFor.AppHost C:\Users\alex\.nuget\packages\aspire.apphost.sdk\9.0.0-preview.4.24504.2\Sdk\Sdk.targets    39  

.NET Version info

.NET SDK: Version: 9.0.100-rc.1.24452.12 Commit: 81a714c6d3 Workload version: 9.0.100-manifests.c7c7028a MSBuild version: 17.12.0-preview-24422-09+d17ec720d

Runtime Environment: OS Name: Windows OS Version: 10.0.22631 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\9.0.100-rc.1.24452.12\

.NET workloads installed: Configured to use loose manifests when installing new manifests. [aspire] Installation Source: VS 17.11.35312.102 Manifest Version: 9.0.0-preview.4.24454.4/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\9.0.0-preview.4.24454.4\WorkloadManifest.json Install Type: FileBased

Host: Version: 9.0.0-rc.1.24431.7 Architecture: x64 Commit: static

.NET SDKs installed: 8.0.400 [C:\Program Files\dotnet\sdk] 8.0.401 [C:\Program Files\dotnet\sdk] 9.0.100-rc.1.24452.12 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 9.0.0-rc.1.24452.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 9.0.0-rc.1.24431.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 9.0.0-rc.1.24452.1 [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

Anything else?

Microsoft Visual Studio Community 2022 (64-bit) - Current Version 17.11.4

davidfowl commented 1 month ago

cc @joperezr

joperezr commented 1 month ago

Fair enough, @timheuer also alluded to this last week suggesting that we should probably move the property to be defined on the SDK level instead, in favor of simplifying the AppHost project. We can fix this for 9.0 GA.

joperezr commented 2 weeks ago

This didn't end up making it for 9.0 GA, but will look into this for 9.1.