Compiler Warning ASPIRE012
此内容尚不支持你的语言。
‘[ProjectName]’ uses the Aspire.AppHost.Sdk, which is obsolete but remains available for staged migration. Switch the project’s Sdk attribute to Microsoft.NET.Sdk, add explicit PackageReference items for Aspire.Hosting.AppHost and Aspire.Hosting.Dotnet, and migrate C# resource ProjectReference items to AddDotnetProject calls. See https://aka.ms/aspire/diagnostics/aspire012 for migration guidance.
This diagnostic warning is reported when a C# AppHost uses Aspire.AppHost.Sdk, either in a project file’s Sdk attribute or in a file-based app’s #:sdk directive. The SDK still works, including AppHost project references and AddProject resources, so you can migrate in stages.
C# AppHosts now use Microsoft.NET.Sdk with explicit Aspire.Hosting.AppHost and Aspire.Hosting.Dotnet packages, and add .NET projects with AddDotnetProject. Running aspire update doesn’t remove the SDK for you.
Example
Section titled “Example”The following project file produces ASPIRE012:
<Project Sdk="Aspire.AppHost.Sdk/17.0.0">The following file-based AppHost directive also produces ASPIRE012:
#:sdk Aspire.AppHost.Sdk@17.0.0To correct this warning
Section titled “To correct this warning”Replace the SDK with Microsoft.NET.Sdk and explicit package references:
<Project Sdk="Microsoft.NET.Sdk">
<!-- Keep your existing PropertyGroup -->
<ItemGroup> <PackageReference Include="Aspire.Hosting.AppHost" Version="17.0.0" /> <PackageReference Include="Aspire.Hosting.Dotnet" Version="17.0.0" /> </ItemGroup>
</Project>In a file-based AppHost, replace the #:sdk directive with package directives:
#:package Aspire.Hosting.AppHost@17.0.0#:package Aspire.Hosting.Dotnet@17.0.0Then review the AppHost’s project references. Without the SDK, project references no longer generate Projects.* metadata automatically. Migrate resources to AddDotnetProject, or mark references that legacy APIs still need. For complete steps, see Remove the obsolete AppHost SDK.
Suppress the warning
Section titled “Suppress the warning”Suppress ASPIRE012 only temporarily while you migrate. Set the following property in the AppHost project file:
<PropertyGroup> <SuppressAspireAppHostSdkObsoleteWarning>true</SuppressAspireAppHostSdkObsoleteWarning></PropertyGroup>Alternatively, add ASPIRE012 to NoWarn:
<PropertyGroup> <NoWarn>$(NoWarn);ASPIRE012</NoWarn></PropertyGroup>Suppressing ASPIRE012 doesn’t suppress CS0618 warnings for obsolete resource APIs such as AddProject, and doesn’t remove the Aspire CLI bundle requirement.