@@ -33,8 +33,21 @@ public class LinkerTests
33
33
{
34
34
private static readonly TimeSpan Timeout = TimeSpan . FromSeconds ( 120 ) ;
35
35
36
+ #if NET8_0_OR_GREATER
36
37
[ Test ]
37
- public async Task RunWebsiteAndCallWithClient_Success ( )
38
+ public async Task RunWebsiteAndCallWithClient_Aot_Success ( )
39
+ {
40
+ await RunWebsiteAndCallWithClient ( publishAot : true ) ;
41
+ }
42
+ #endif
43
+
44
+ [ Test ]
45
+ public async Task RunWebsiteAndCallWithClient_Trimming_Success ( )
46
+ {
47
+ await RunWebsiteAndCallWithClient ( publishAot : false ) ;
48
+ }
49
+
50
+ private async Task RunWebsiteAndCallWithClient ( bool publishAot )
38
51
{
39
52
var projectDirectory = typeof ( LinkerTests ) . Assembly
40
53
. GetCustomAttributes < AssemblyMetadataAttribute > ( )
@@ -51,13 +64,11 @@ public async Task RunWebsiteAndCallWithClient_Success()
51
64
try
52
65
{
53
66
using var cts = new CancellationTokenSource ( ) ;
54
- using var websiteProcess = new WebsiteProcess ( ) ;
55
- using var clientProcess = new DotNetProcess ( ) ;
56
67
57
68
try
58
69
{
59
- var publishWebsiteTask = PublishAppAsync ( projectDirectory + @"\..\..\testassets\LinkerTestsWebsite\LinkerTestsWebsite.csproj" , linkerTestsWebsitePath , cts . Token ) ;
60
- var publishClientTask = PublishAppAsync ( projectDirectory + @"\..\..\testassets\LinkerTestsClient\LinkerTestsClient.csproj" , linkerTestsClientPath , cts . Token ) ;
70
+ var publishWebsiteTask = PublishAppAsync ( projectDirectory + @"\..\..\testassets\LinkerTestsWebsite\LinkerTestsWebsite.csproj" , linkerTestsWebsitePath , publishAot , cts . Token ) ;
71
+ var publishClientTask = PublishAppAsync ( projectDirectory + @"\..\..\testassets\LinkerTestsClient\LinkerTestsClient.csproj" , linkerTestsClientPath , publishAot , cts . Token ) ;
61
72
62
73
await Task . WhenAll ( publishWebsiteTask , publishClientTask ) . TimeoutAfter ( Timeout ) ;
63
74
Console . WriteLine ( "Successfully published app." ) ;
@@ -67,12 +78,15 @@ public async Task RunWebsiteAndCallWithClient_Success()
67
78
cts . Dispose ( ) ;
68
79
}
69
80
81
+ using var websiteProcess = new WebsiteProcess ( ) ;
82
+ using var clientProcess = new DotNetProcess ( ) ;
83
+
70
84
try
71
85
{
72
- websiteProcess . Start ( Path . Combine ( linkerTestsWebsitePath , "LinkerTestsWebsite.dll" ) ) ;
86
+ websiteProcess . Start ( BuildStartPath ( linkerTestsWebsitePath , "LinkerTestsWebsite" ) , arguments : null ) ;
73
87
await websiteProcess . WaitForReadyAsync ( ) . TimeoutAfter ( Timeout ) ;
74
88
75
- clientProcess . Start ( Path . Combine ( linkerTestsClientPath , $ "LinkerTestsClient.dll { websiteProcess . ServerPort } " ) ) ;
89
+ clientProcess . Start ( BuildStartPath ( linkerTestsClientPath , "LinkerTestsClient" ) , arguments : websiteProcess . ServerPort ! . ToString ( ) ) ;
76
90
await clientProcess . WaitForExitAsync ( ) . TimeoutAfter ( Timeout ) ;
77
91
}
78
92
finally
@@ -92,6 +106,15 @@ public async Task RunWebsiteAndCallWithClient_Success()
92
106
}
93
107
}
94
108
109
+ private static string BuildStartPath ( string path , string projectName )
110
+ {
111
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
112
+ {
113
+ projectName += ".exe" ;
114
+ }
115
+ return Path . Combine ( path , projectName ) ;
116
+ }
117
+
95
118
private static void EnsureDeleted ( string path )
96
119
{
97
120
if ( Directory . Exists ( path ) )
@@ -100,7 +123,7 @@ private static void EnsureDeleted(string path)
100
123
}
101
124
}
102
125
103
- private static async Task PublishAppAsync ( string path , string outputPath , CancellationToken cancellationToken )
126
+ private static async Task PublishAppAsync ( string path , string outputPath , bool publishAot , CancellationToken cancellationToken )
104
127
{
105
128
var resolvedPath = Path . GetFullPath ( path ) ;
106
129
Console . WriteLine ( $ "Publishing { resolvedPath } ") ;
@@ -110,7 +133,9 @@ private static async Task PublishAppAsync(string path, string outputPath, Cancel
110
133
111
134
try
112
135
{
113
- process . Start ( $ "publish { resolvedPath } -r { GetRuntimeIdentifier ( ) } -c Release -o { outputPath } --self-contained") ;
136
+ // The AppPublishAot parameter is used to tell the compiler to publish as AOT.
137
+ // AppPublishAot is used instead of PublishAot because dependency projects have non-AOT targets. Setting "PublishAot=true" causes build errors.
138
+ process . Start ( "dotnet" , $ "publish { resolvedPath } -r { GetRuntimeIdentifier ( ) } -c Release -o { outputPath } -p:AppPublishAot={ publishAot } --self-contained") ;
114
139
await process . WaitForExitAsync ( ) . TimeoutAfter ( Timeout ) ;
115
140
}
116
141
catch ( Exception ex )
0 commit comments