@@ -17,13 +17,12 @@ public class MSBuildTests
17
17
public void EnsureWarningsAreEmittedWhenProjectReferencingLibraries ( )
18
18
{
19
19
var repoRoot = MSBuildUtils . GetRepoRoot ( ) ;
20
- var tempDirectory = Directory . CreateTempSubdirectory ( "AspireHostingTests" ) ;
21
- try
22
- {
23
- var libraryDirectory = Path . Combine ( tempDirectory . FullName , "Library" ) ;
24
- Directory . CreateDirectory ( libraryDirectory ) ;
20
+ using var tempDirectory = new TempDirectory ( ) ;
21
+
22
+ var libraryDirectory = Path . Combine ( tempDirectory . Path , "Library" ) ;
23
+ Directory . CreateDirectory ( libraryDirectory ) ;
25
24
26
- File . WriteAllText ( Path . Combine ( libraryDirectory , "Library.csproj" ) , """
25
+ File . WriteAllText ( Path . Combine ( libraryDirectory , "Library.csproj" ) , """
27
26
<Project Sdk="Microsoft.NET.Sdk">
28
27
29
28
<PropertyGroup>
@@ -34,18 +33,18 @@ public void EnsureWarningsAreEmittedWhenProjectReferencingLibraries()
34
33
35
34
</Project>
36
35
""" ) ;
37
- File . WriteAllText ( Path . Combine ( libraryDirectory , "Class1.cs" ) , """
36
+ File . WriteAllText ( Path . Combine ( libraryDirectory , "Class1.cs" ) , """
38
37
namespace Library;
39
38
40
39
public class Class1
41
40
{
42
41
}
43
42
""" ) ;
44
43
45
- var appHostDirectory = Path . Combine ( tempDirectory . FullName , "AppHost" ) ;
46
- Directory . CreateDirectory ( appHostDirectory ) ;
44
+ var appHostDirectory = Path . Combine ( tempDirectory . Path , "AppHost" ) ;
45
+ Directory . CreateDirectory ( appHostDirectory ) ;
47
46
48
- File . WriteAllText ( Path . Combine ( appHostDirectory , "AppHost.csproj" ) , $ """
47
+ File . WriteAllText ( Path . Combine ( appHostDirectory , "AppHost.csproj" ) , $ """
49
48
<Project Sdk="Microsoft.NET.Sdk">
50
49
51
50
<PropertyGroup>
@@ -71,12 +70,12 @@ the Aspire.AppHost.SDK targets that will automatically add these references to p
71
70
72
71
</Project>
73
72
""" ) ;
74
- File . WriteAllText ( Path . Combine ( appHostDirectory , "AppHost.cs" ) , """
73
+ File . WriteAllText ( Path . Combine ( appHostDirectory , "AppHost.cs" ) , """
75
74
var builder = DistributedApplication.CreateBuilder();
76
75
builder.Build().Run();
77
76
""" ) ;
78
77
79
- File . WriteAllText ( Path . Combine ( appHostDirectory , "Directory.Build.props" ) , $ """
78
+ File . WriteAllText ( Path . Combine ( appHostDirectory , "Directory.Build.props" ) , $ """
80
79
<Project>
81
80
<PropertyGroup>
82
81
<SkipAspireWorkloadManifest>true</SkipAspireWorkloadManifest>
@@ -85,49 +84,44 @@ the Aspire.AppHost.SDK targets that will automatically add these references to p
85
84
<Import Project="{ repoRoot } \src\Aspire.Hosting.AppHost\build\Aspire.Hosting.AppHost.props" />
86
85
</Project>
87
86
""" ) ;
88
- File . WriteAllText ( Path . Combine ( appHostDirectory , "Directory.Build.targets" ) , $ """
87
+ File . WriteAllText ( Path . Combine ( appHostDirectory , "Directory.Build.targets" ) , $ """
89
88
<Project>
90
89
<Import Project="{ repoRoot } \src\Aspire.Hosting.AppHost\build\Aspire.Hosting.AppHost.in.targets" />
91
90
<Import Project="{ repoRoot } \src\Aspire.AppHost.Sdk\SDK\Sdk.in.targets" />
92
91
</Project>
93
92
""" ) ;
94
93
95
- var output = new StringBuilder ( ) ;
96
- var outputDone = new ManualResetEvent ( false ) ;
97
- using var process = new Process ( ) ;
98
- // set '-nodereuse:false -p:UseSharedCompilation=false' so the MSBuild and Roslyn server processes don't hang around, which may hang the test in CI
99
- process . StartInfo = new ProcessStartInfo ( "dotnet" , $ "build -nodereuse:false -p:UseSharedCompilation=false")
94
+ var output = new StringBuilder ( ) ;
95
+ var outputDone = new ManualResetEvent ( false ) ;
96
+ using var process = new Process ( ) ;
97
+ // set '-nodereuse:false -p:UseSharedCompilation=false' so the MSBuild and Roslyn server processes don't hang around, which may hang the test in CI
98
+ process . StartInfo = new ProcessStartInfo ( "dotnet" , $ "build -nodereuse:false -p:UseSharedCompilation=false")
99
+ {
100
+ RedirectStandardOutput = true ,
101
+ UseShellExecute = false ,
102
+ CreateNoWindow = true ,
103
+ WorkingDirectory = appHostDirectory
104
+ } ;
105
+ process . OutputDataReceived += ( sender , e ) =>
106
+ {
107
+ if ( e . Data == null )
100
108
{
101
- RedirectStandardOutput = true ,
102
- UseShellExecute = false ,
103
- CreateNoWindow = true ,
104
- WorkingDirectory = appHostDirectory
105
- } ;
106
- process . OutputDataReceived += ( sender , e ) =>
109
+ outputDone . Set ( ) ;
110
+ }
111
+ else
107
112
{
108
- if ( e . Data == null )
109
- {
110
- outputDone . Set ( ) ;
111
- }
112
- else
113
- {
114
- output . AppendLine ( e . Data ) ;
115
- }
116
- } ;
117
- process . Start ( ) ;
118
- process . BeginOutputReadLine ( ) ;
119
-
120
- Assert . True ( process . WaitForExit ( milliseconds : 180_000 ) , "dotnet build command timed out after 3 minutes." ) ;
121
- Assert . True ( process . ExitCode == 0 , $ "Build failed: { Environment . NewLine } { output } ") ;
122
-
123
- Assert . True ( outputDone . WaitOne ( millisecondsTimeout : 60_000 ) , "Timed out waiting for output to complete." ) ;
124
-
125
- // Ensure a warning is emitted when an AppHost references a Library project
126
- Assert . Contains ( "warning ASPIRE004" , output . ToString ( ) ) ;
127
- }
128
- finally
129
- {
130
- tempDirectory . Delete ( true ) ;
131
- }
113
+ output . AppendLine ( e . Data ) ;
114
+ }
115
+ } ;
116
+ process . Start ( ) ;
117
+ process . BeginOutputReadLine ( ) ;
118
+
119
+ Assert . True ( process . WaitForExit ( milliseconds : 180_000 ) , "dotnet build command timed out after 3 minutes." ) ;
120
+ Assert . True ( process . ExitCode == 0 , $ "Build failed: { Environment . NewLine } { output } ") ;
121
+
122
+ Assert . True ( outputDone . WaitOne ( millisecondsTimeout : 60_000 ) , "Timed out waiting for output to complete." ) ;
123
+
124
+ // Ensure a warning is emitted when an AppHost references a Library project
125
+ Assert . Contains ( "warning ASPIRE004" , output . ToString ( ) ) ;
132
126
}
133
127
}
0 commit comments