-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Adding Microsoft.AspNetCore.EnsureJsonTrimmability host configuration #29719
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
Merged
brunolins16
merged 16 commits into
dotnet:main
from
brunolins16:brunolins16/web/aot/json
Jan 10, 2023
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7a88240
Adding EnsureJsonTrimmability
brunolins16 1e3b0e9
Fixing propertyGroup & unit tests
brunolins16 894ff8e
Fix tests name
brunolins16 6ae97d2
Merge branch 'dotnet:main' into brunolins16/web/aot/json
brunolins16 7526423
Merge remote-tracking branch 'upstream/main' into brunolins16/web/aot…
brunolins16 d466423
Merge branch 'brunolins16/web/aot/json' of https://github.com/brunoli…
brunolins16 3085295
Remove unneeded change
brunolins16 1c7722f
Update launchSettings.json
brunolins16 c7b63b4
Delete sdk.txt
brunolins16 2855b80
Adding project to sln
brunolins16 240286f
Update PublishTests.cs
brunolins16 8004b94
Review feedback
brunolins16 3fd57ae
Merge branch 'brunolins16/web/aot/json' of https://github.com/brunoli…
brunolins16 64e53f2
Merge remote-tracking branch 'upstream/main' into brunolins16/web/aot…
brunolins16 21d34e0
Removing msbuild version constraint
brunolins16 28c4a7f
Review feedback
brunolins16 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/Tests/Microsoft.NET.Sdk.Web.Tests/Microsoft.NET.Sdk.Web.Tests.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<EnableDefaultItems>false</EnableDefaultItems> | ||
<OutDirName>Tests\$(MSBuildProjectName)</OutDirName> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>$(SdkTargetFramework)</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<PackageId>testSdkWeb</PackageId> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="**\*.cs" Exclude="$(GlobalExclude)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions.Json" Version="$(FluentAssertionsJsonVersion)" /> | ||
<PackageReference Include="System.Reflection.MetadataLoadContext" Version="$(SystemReflectionMetadataLoadContextVersion)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Microsoft.NET.TestFramework\Microsoft.NET.TestFramework.csproj" /> | ||
<ProjectReference Include="..\..\..\src\WebSdk\Web\Tasks\Microsoft.NET.Sdk.Web.Tasks.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text.Json.Nodes; | ||
using FluentAssertions; | ||
using Microsoft.NET.TestFramework; | ||
using Microsoft.NET.TestFramework.Assertions; | ||
using Microsoft.NET.TestFramework.Commands; | ||
using Microsoft.NET.TestFramework.ProjectConstruction; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.NET.Sdk.Web.Tests | ||
{ | ||
public class PublishTests : SdkTest | ||
{ | ||
public PublishTests(ITestOutputHelper log) : base(log) | ||
{ | ||
} | ||
|
||
[Theory()] | ||
[MemberData(nameof(SupportedTfms))] | ||
public void TrimmingOptions_Are_Defaulted_Correctly_On_Trimmed_Apps(string targetFramework) | ||
{ | ||
var projectName = "HelloWorld"; | ||
var rid = EnvironmentInfo.GetCompatibleRid(targetFramework); | ||
|
||
var testProject = CreateTestProjectForILLinkTesting(targetFramework, projectName); | ||
testProject.AdditionalProperties["PublishTrimmed"] = "true"; | ||
|
||
var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: projectName + targetFramework); | ||
|
||
var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); | ||
publishCommand.Execute($"/p:RuntimeIdentifier={rid}").Should().Pass(); | ||
|
||
string outputDirectory = publishCommand.GetOutputDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName; | ||
string runtimeConfigFile = Path.Combine(outputDirectory, $"{projectName}.runtimeconfig.json"); | ||
string runtimeConfigContents = File.ReadAllText(runtimeConfigFile); | ||
|
||
JsonNode runtimeConfig = JsonNode.Parse(runtimeConfigContents); | ||
JsonNode configProperties = runtimeConfig["runtimeOptions"]["configProperties"]; | ||
|
||
configProperties["Microsoft.AspNetCore.EnsureJsonTrimmability"].GetValue<bool>() | ||
.Should().BeTrue(); | ||
} | ||
|
||
[Theory()] | ||
[MemberData(nameof(SupportedTfms))] | ||
public void TrimmingOptions_Are_Defaulted_Correctly_On_Aot_Apps(string targetFramework) | ||
{ | ||
var projectName = "HelloWorld"; | ||
var rid = EnvironmentInfo.GetCompatibleRid(targetFramework); | ||
|
||
var testProject = CreateTestProjectForILLinkTesting(targetFramework, projectName); | ||
testProject.AdditionalProperties["PublishAOT"] = "true"; | ||
|
||
var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: projectName + targetFramework); | ||
var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); | ||
publishCommand.Execute($"/p:RuntimeIdentifier={rid}").Should().Pass(); | ||
|
||
string outputDirectory = publishCommand.GetIntermediateDirectory(targetFramework: targetFramework, runtimeIdentifier: rid).FullName; | ||
string responseFile = Path.Combine(outputDirectory, "native", $"{projectName}.ilc.rsp"); | ||
var responseFileContents = File.ReadLines(responseFile); | ||
|
||
responseFileContents.Should().Contain("--feature:Microsoft.AspNetCore.EnsureJsonTrimmability=true"); | ||
} | ||
|
||
public static IEnumerable<object[]> SupportedTfms { get; } = new List<object[]> | ||
{ | ||
#if NET8_0 | ||
new object[] { ToolsetInfo.CurrentTargetFramework } | ||
#else | ||
#error If building for a newer TFM, please update the values above | ||
#endif | ||
}; | ||
|
||
private TestProject CreateTestProjectForILLinkTesting( | ||
string targetFramework, | ||
string projectName) | ||
{ | ||
var testProject = new TestProject() | ||
{ | ||
Name = projectName, | ||
TargetFrameworks = targetFramework, | ||
IsExe = true, | ||
ProjectSdk = "Microsoft.NET.Sdk.Web" | ||
}; | ||
|
||
testProject.SourceFiles[$"Program.cs"] = """ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
var builder = WebApplication.CreateBuilder(); | ||
var app = builder.Build(); | ||
app.Start(); | ||
"""; | ||
|
||
return testProject; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.