Skip to content

Commit db9e503

Browse files
committed
Keep release packaging out of trim analysis consumers
Fixes #457. Managed and NativeAOT CLI consumers cover inherited release packaging.
1 parent ef0de37 commit db9e503

3 files changed

Lines changed: 53 additions & 0 deletions

File tree

‎src/libs/AutoSDK.CLI/Commands/TrimCommand.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ internal static ProcessStartInfo CreatePublishStartInfo(
305305
};
306306
foreach (var argument in new[] { "publish", "TrimmingCheck.csproj", "-c", "Release", "--output", publishDirectory })
307307
startInfo.ArgumentList.Add(argument);
308+
// Analysis must not inherit SDK packaging from ancestor build props.
309+
startInfo.ArgumentList.Add("-p:GeneratePackageOnBuild=false");
308310
if (nativeAot)
309311
startInfo.ArgumentList.Add("-p:PublishAot=true");
310312
if (removeSymbols)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System.Text.Json;
2+
3+
namespace AutoSDK.IntegrationTests;
4+
5+
public partial class CliTests
6+
{
7+
[TestMethod]
8+
[DataRow(false)]
9+
[DataRow(true)]
10+
public async Task Trim_ReleasePackageGenerationDoesNotLeakIntoAnalysis(bool nativeAot)
11+
{
12+
const string spec = """
13+
openapi: 3.0.3
14+
info:
15+
title: Trim packaging policy
16+
version: 1.0.0
17+
paths: {}
18+
components:
19+
schemas:
20+
Payload:
21+
type: object
22+
properties:
23+
text:
24+
type: string
25+
""";
26+
await GenerateFromContentAsync("trim-package-policy.yaml", spec, targetFramework: "net10.0",
27+
assertBuiltOutput: async directory =>
28+
{
29+
await File.WriteAllTextAsync(Path.Combine(directory, "Directory.Build.props"), """
30+
<Project><PropertyGroup Condition="'$(Configuration)' == 'Release'">
31+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
32+
</PropertyGroup></Project>
33+
""");
34+
var report = Path.Combine(directory, "trim-report.json");
35+
var repository = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "../../../../../.."));
36+
var arguments = new List<string>
37+
{
38+
"run", "--disable-build-servers", "--no-launch-profile", "--project", "src/libs/AutoSDK.CLI",
39+
"trim", Path.Combine(directory, "Oag.csproj"), "--report-json", report,
40+
};
41+
if (nativeAot) arguments.Add("--aot");
42+
var result = await RunDotnetAsync(repository, arguments.ToArray());
43+
result.ExitCode.Should().Be(0, result.StandardOutput + result.StandardError);
44+
result.StandardOutput.Should().Contain("No trimming warnings found");
45+
using var json = JsonDocument.Parse(await File.ReadAllTextAsync(report));
46+
json.RootElement.GetProperty("schemaVersion").GetInt32().Should().Be(1);
47+
json.RootElement.GetProperty("appExecutableBytes").GetInt64().Should().BeGreaterThan(0);
48+
});
49+
}
50+
}

‎src/tests/AutoSDK.UnitTests/TrimReportTests.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public void DefaultPublication_InheritsSymbolPolicyAndUsesAtomicArguments()
7373
start.ArgumentList.Should().ContainInOrder("publish", "TrimmingCheck.csproj", "-c", "Release", "--output", "/work/publish directory");
7474
start.ArgumentList.Should().NotContain("-p:TrimmerRemoveSymbols=true");
7575
start.ArgumentList.Should().NotContain("-p:PublishAot=true");
76+
start.ArgumentList.Should().Contain("-p:GeneratePackageOnBuild=false");
7677
start.Arguments.Should().BeEmpty();
7778
}
7879

0 commit comments

Comments
 (0)