@@ -47,43 +47,15 @@ Task IAsyncLifetime.DisposeAsync()
47
47
48
48
async Task CreateTestAppAsync ( )
49
49
{
50
+ // It might be tempting to do pack -> restore -> build --no-restore -> publish --no-build (and parallelize over publish modes)
51
+ // But this would fail because of https://github.com/dotnet/sdk/issues/17526 and probably because of other unforeseen bugs
52
+ // preventing from running multiple `dotnet publish` commands with different parameters.
53
+
50
54
await PackAsync ( ) ;
51
55
await RestoreAsync ( ) ;
52
-
53
- var publishDirectory = _workingDirectory . SubDirectory ( "publish" ) ;
54
- var fodyWeaversXml = _workingDirectory . File ( "FodyWeavers.xml" ) ;
55
-
56
56
foreach ( var publishMode in GetPublishModes ( ) )
57
57
{
58
- var outputDirectory = publishDirectory . SubDirectory ( publishMode . ToString ( ) ) ;
59
-
60
- File . WriteAllText ( fodyWeaversXml . FullName , publishMode == PublishMode . SingleFile && IsDesktop ? "<Weavers><Costura/></Weavers>" : "<Weavers/>" ) ;
61
-
62
- var publishArgs = new [ ] {
63
- "publish" ,
64
- "--no-restore" ,
65
- "--configuration" , "Release" ,
66
- "--output" , outputDirectory . FullName ,
67
- $ "-p:TargetFramework={ TargetFramework } "
68
- } ;
69
- var publishSingleFile = $ "-p:PublishSingleFile={ publishMode is PublishMode . SingleFile or PublishMode . SelfContained } ";
70
- var selfContained = $ "-p:SelfContained={ publishMode is PublishMode . SelfContained } ";
71
- await RunDotnetAsync ( _workingDirectory , IsDesktop ? publishArgs : publishArgs . Append ( publishSingleFile ) . Append ( selfContained ) . ToArray ( ) ) ;
72
-
73
- var executableFileName = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ? "TestApp.exe" : "TestApp" ;
74
- var executableFile = new FileInfo ( Path . Combine ( outputDirectory . FullName , executableFileName ) ) ;
75
- executableFile . Exists . Should ( ) . BeTrue ( ) ;
76
- var dlls = executableFile . Directory ! . EnumerateFiles ( "*.dll" ) ;
77
- if ( publishMode == PublishMode . Standard )
78
- {
79
- dlls . Should ( ) . NotBeEmpty ( because : $ "the test app was _not_ published as single-file ({ publishMode } )") ;
80
- }
81
- else
82
- {
83
- dlls . Should ( ) . BeEmpty ( because : $ "the test app was published as single-file ({ publishMode } )") ;
84
- executableFile . Directory . EnumerateFiles ( ) . Should ( ) . ContainSingle ( ) . Which . FullName . Should ( ) . Be ( executableFile . FullName ) ;
85
- }
86
- _executables [ publishMode ] = executableFile ;
58
+ await PublishAsync ( publishMode ) ;
87
59
}
88
60
}
89
61
@@ -112,6 +84,43 @@ async Task RestoreAsync()
112
84
await RunDotnetAsync ( _workingDirectory , restoreArgs ) ;
113
85
}
114
86
87
+ async Task PublishAsync ( PublishMode publishMode )
88
+ {
89
+ var publishDirectory = _workingDirectory . SubDirectory ( "publish" ) ;
90
+ var fodyWeaversXml = _workingDirectory . File ( "FodyWeavers.xml" ) ;
91
+
92
+ var outputDirectory = publishDirectory . SubDirectory ( publishMode . ToString ( ) ) ;
93
+
94
+ File . WriteAllText ( fodyWeaversXml . FullName , publishMode == PublishMode . SingleFile && IsDesktop ? "<Weavers><Costura/></Weavers>" : "<Weavers/>" ) ;
95
+
96
+ var publishArgs = new [ ] {
97
+ "publish" ,
98
+ "--no-restore" ,
99
+ "--configuration" , "Release" ,
100
+ "--output" , outputDirectory . FullName ,
101
+ $ "-p:TargetFramework={ TargetFramework } "
102
+ } ;
103
+ var publishSingleFile = $ "-p:PublishSingleFile={ publishMode is PublishMode . SingleFile or PublishMode . SelfContained } ";
104
+ var selfContained = $ "-p:SelfContained={ publishMode is PublishMode . SelfContained } ";
105
+ await RunDotnetAsync ( _workingDirectory , IsDesktop ? publishArgs : publishArgs . Append ( publishSingleFile ) . Append ( selfContained ) . ToArray ( ) ) ;
106
+
107
+ var executableFileName = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ? "TestApp.exe" : "TestApp" ;
108
+ var executableFile = new FileInfo ( Path . Combine ( outputDirectory . FullName , executableFileName ) ) ;
109
+ executableFile . Exists . Should ( ) . BeTrue ( ) ;
110
+ var dlls = executableFile . Directory ! . EnumerateFiles ( "*.dll" ) ;
111
+ if ( publishMode == PublishMode . Standard )
112
+ {
113
+ dlls . Should ( ) . NotBeEmpty ( because : $ "the test app was _not_ published as single-file ({ publishMode } )") ;
114
+ }
115
+ else
116
+ {
117
+ dlls . Should ( ) . BeEmpty ( because : $ "the test app was published as single-file ({ publishMode } )") ;
118
+ executableFile . Directory . EnumerateFiles ( ) . Should ( ) . ContainSingle ( ) . Which . FullName . Should ( ) . Be ( executableFile . FullName ) ;
119
+ }
120
+
121
+ _executables [ publishMode ] = executableFile ;
122
+ }
123
+
115
124
async Task RunDotnetAsync ( DirectoryInfo workingDirectory , params string [ ] arguments )
116
125
{
117
126
_messageSink . OnMessage ( new DiagnosticMessage ( $ "cd { workingDirectory } ") ) ;
0 commit comments