Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/WebSdk/Web/Targets/Sdk.Server.targets
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,10 @@ Copyright (c) .NET Foundation. All rights reserved.
Trim="true" />
</ItemGroup>

<Target Name="WarnOnDeprecatedAssets"
BeforeTargets="CoreCompile"
Condition="'$(IncludeOpenAPIAnalyzers)' == 'true'">
<Warning Code="ASPDEPR007" Text="The IncludeOpenAPIAnalyzers property and its associated MVC API analyzers are deprecated and will be removed in a future release." HelpLink="https://aka.ms/aspnet/deprecate/007" />
</Target>

</Project>
81 changes: 81 additions & 0 deletions test/Microsoft.NET.Sdk.Web.Tests/DeprecationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider enabling nullable reference types instead of disabling them globally. This would improve type safety and align with modern C# practices.

Suggested change
#nullable disable
#nullable enable

Copilot uses AI. Check for mistakes.

namespace Microsoft.NET.Sdk.Web.Tests;

public class DeprecationTests(ITestOutputHelper log) : SdkTest(log)
{
[Fact]
public void It_does_not_show_deprecation_warning_when_IncludeOpenAPIAnalyzers_is_not_set()
{
var testProject = new TestProject()
{
Name = "WebAppWithoutOpenAPIAnalyzers",
TargetFrameworks = ToolsetInfo.CurrentTargetFramework,
ProjectSdk = "Microsoft.NET.Sdk.Web"
};

var testAsset = _testAssetsManager.CreateTestProject(testProject);

var buildCommand = new BuildCommand(testAsset);
buildCommand
.Execute()
.Should()
.Pass()
.And
.NotHaveStdOutContaining("ASPDEPR007")
.And
.NotHaveStdOutContaining("IncludeOpenAPIAnalyzers");
}

[Fact]
public void It_does_not_show_deprecation_warning_when_IncludeOpenAPIAnalyzers_is_false()
{
var testProject = new TestProject()
{
Name = "WebAppWithOpenAPIAnalyzersFalse",
TargetFrameworks = ToolsetInfo.CurrentTargetFramework,
ProjectSdk = "Microsoft.NET.Sdk.Web"
};

testProject.AdditionalProperties["IncludeOpenAPIAnalyzers"] = "false";

var testAsset = _testAssetsManager.CreateTestProject(testProject);

var buildCommand = new BuildCommand(testAsset);
buildCommand
.Execute()
.Should()
.Pass()
.And
.NotHaveStdOutContaining("ASPDEPR007");
}

[Theory]
[InlineData(ToolsetInfo.CurrentTargetFramework)]
[InlineData("net8.0")]
[InlineData("net9.0")]
public void It_shows_deprecation_warning_across_target_frameworks(string targetFramework)
{
var testProject = new TestProject()
{
Name = $"WebApp_{targetFramework.Replace(".", "_")}",
TargetFrameworks = targetFramework,
ProjectSdk = "Microsoft.NET.Sdk.Web"
};

testProject.AdditionalProperties["IncludeOpenAPIAnalyzers"] = "true";

var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: targetFramework);

var buildCommand = new BuildCommand(testAsset);
buildCommand
.Execute()
.Should()
.Pass()
.And
.HaveStdOutContaining("ASPDEPR007");
}
}
Loading