@@ -792,6 +792,9 @@ private async Task WaitForConditionAsync(Func<Task<bool>> condition, string mess
792792
793793 private async Task RunSampleTestAsync ( string samplePath , Func < IReadOnlyList < OutputLog > , Task > testAction )
794794 {
795+ // Build the sample project first (it may not have been built as part of the solution)
796+ await this . BuildSampleAsync ( samplePath ) ;
797+
795798 // Start the Azure Functions app
796799 List < OutputLog > logsContainer = [ ] ;
797800 using Process funcProcess = this . StartFunctionApp ( samplePath , logsContainer ) ;
@@ -811,12 +814,39 @@ private async Task RunSampleTestAsync(string samplePath, Func<IReadOnlyList<Outp
811814
812815 private sealed record OutputLog ( DateTime Timestamp , LogLevel Level , string Message ) ;
813816
817+ private async Task BuildSampleAsync ( string samplePath )
818+ {
819+ this . _outputHelper . WriteLine ( $ "Building sample at { samplePath } ...") ;
820+
821+ ProcessStartInfo buildInfo = new ( )
822+ {
823+ FileName = "dotnet" ,
824+ Arguments = $ "build -f { s_dotnetTargetFramework } ",
825+ WorkingDirectory = samplePath ,
826+ UseShellExecute = false ,
827+ RedirectStandardOutput = true ,
828+ RedirectStandardError = true ,
829+ } ;
830+
831+ using Process buildProcess = new ( ) { StartInfo = buildInfo } ;
832+ buildProcess . Start ( ) ;
833+ await buildProcess . WaitForExitAsync ( ) ;
834+
835+ if ( buildProcess . ExitCode != 0 )
836+ {
837+ string stderr = await buildProcess . StandardError . ReadToEndAsync ( ) ;
838+ throw new InvalidOperationException ( $ "Failed to build sample at { samplePath } : { stderr } ") ;
839+ }
840+
841+ this . _outputHelper . WriteLine ( $ "Build completed for { samplePath } .") ;
842+ }
843+
814844 private Process StartFunctionApp ( string samplePath , List < OutputLog > logs )
815845 {
816846 ProcessStartInfo startInfo = new ( )
817847 {
818848 FileName = "dotnet" ,
819- Arguments = $ "run -f { s_dotnetTargetFramework } --port { AzureFunctionsPort } ",
849+ Arguments = $ "run --no-build - f { s_dotnetTargetFramework } --port { AzureFunctionsPort } ",
820850 WorkingDirectory = samplePath ,
821851 UseShellExecute = false ,
822852 RedirectStandardOutput = true ,
0 commit comments