Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for EnableRequestDelegateGenerator flag #29982

Merged
merged 13 commits into from
Jan 19, 2023
Merged
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"tools": {
"dotnet": "8.0.100-alpha.1.22579.5",
"dotnet": "8.0.100-alpha.1.23067.5",
"runtimes": {
"dotnet": [
"$(VSRedistCommonNetCoreSharedFrameworkx6480PackageVersion)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ private void WriteETag(HttpContext context)
return string.Format(CultureInfo.InvariantCulture, "W/\"{0}{1}\"", EtagDiscriminator, Deltas[^1].SequenceId);
}

private void AppendDeltas(UpdateDelta[] updateDeltas)
private void AppendDeltas(UpdateDelta[]? updateDeltas)
{
if (updateDeltas.Length == 0)
if (updateDeltas == null || updateDeltas.Length == 0)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Intentionally pinned. This feature is supported in projects targeting 3.1 or newer.-->
<TargetFramework>netcoreapp3.1</TargetFramework>
<!-- Intentionally pinned. This feature is supported in projects targeting 6.0 or newer.-->
<TargetFramework>net6.0</TargetFramework>
<StrongNameKeyId>MicrosoftAspNetCore</StrongNameKeyId>

<IsPackable>false</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(ResolverTargetFramework);net472;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>$(ResolverTargetFramework);net472</TargetFrameworks>
<TargetFrameworks Condition=" '$([MSBuild]::IsOSPlatform(`Windows`))' == 'false' ">$(ResolverTargetFramework)</TargetFrameworks>

<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down
4 changes: 2 additions & 2 deletions src/Tests/HelixTasks/HelixTasks.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net472</TargetFrameworks>
<TargetFrameworks Condition=" '$([MSBuild]::IsOSPlatform(`Windows`))' == 'false' ">netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net6.0;net472</TargetFrameworks>
<TargetFrameworks Condition=" '$([MSBuild]::IsOSPlatform(`Windows`))' == 'false' ">net6.0</TargetFrameworks>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<RootNamespace>Microsoft.DotNet.SDK.Build.Helix</RootNamespace>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,37 @@ public GivenThatWeWantToUseAnalyzers(ITestOutputHelper log) : base(log)
{
}

[Theory]
[InlineData("WebApp", "EnableRequestDelegateGenerator", false)]
[InlineData("WebApp", "EnableRequestDelegateGenerator", true)]
public void It_resolves_requestdelegategenerator_correctly(string testAssetName, string property, bool isEnabled)
captainsafia marked this conversation as resolved.
Show resolved Hide resolved
{
var asset = _testAssetsManager
.CopyTestAsset(testAssetName, identifier: "C#")
captainsafia marked this conversation as resolved.
Show resolved Hide resolved
.WithSource()
.WithProjectChanges(project =>
{
var ns = project.Root.Name.Namespace;
project.Root.Add(new XElement(ns + "PropertyGroup", new XElement(property, isEnabled)));
captainsafia marked this conversation as resolved.
Show resolved Hide resolved
});

var command = new GetValuesCommand(
Log,
asset.Path,
ToolsetInfo.CurrentTargetFramework,
"Analyzer",
GetValuesCommand.ValueType.Item);

command
.WithWorkingDirectory(asset.Path)
.Execute("/bl")
captainsafia marked this conversation as resolved.
Show resolved Hide resolved
.Should().Pass();

var analyzers = command.GetValues();

Assert.Equal(isEnabled, analyzers.Any(analyzer => analyzer.Contains("Microsoft.AspNetCore.Http.Generators.dll")));
}

[Theory]
[InlineData("C#", "AppWithLibrary")]
[InlineData("VB", "AppWithLibraryVB")]
Expand Down
13 changes: 13 additions & 0 deletions src/WebSdk/Web/Sdk/Sdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ Copyright (c) .NET Foundation. All rights reserved.
IsImplicitlyDefined="true" />
</ItemGroup>

<!-- The RequestDelegateGenerator is bundled into the Microsoft.AspNetCore.App ref pack.-->
<!-- We want this generator to be disabled by default so we remove it from the list of-->
<!-- analyzers here. Since this depends on the analyzer having already been added to the-->
<!-- `Analyzer` item group by previous tasks in the build, we must wrap this work in a-->
<!-- target that executes right before the compilation loop.-->
<Target Name="RemoveRequestDelegateGenerator" BeforeTargets="CoreCompile">
<ItemGroup>
<Analyzer
Remove="@(Analyzer->HasMetadata('FileName')->WithMetadataValue('FileName', 'Microsoft.AspNetCore.Http.Generators'))"
Condition="'$(Language)'=='C#' AND '$(EnableRequestDelegateGenerator)' != 'true'"/>
</ItemGroup>
</Target>

<ItemGroup Condition="'$(Language)' == 'C#' AND ('$(ImplicitUsings)' == 'true' or '$(ImplicitUsings)' == 'enable')">
<Using Include="System.Net.Http.Json" />
<Using Include="Microsoft.AspNetCore.Builder" />
Expand Down