@@ -200,14 +200,14 @@ private async Task BuildProjectContainerImageAsync(IResource resource, IPublishi
200200                    throw  new  DistributedApplicationException ( $ "The resource '{ projectMetadata } ' does not have a project metadata annotation.") ; 
201201                } 
202202
203-                 var  arguments  =  $ "publish { projectMetadata . ProjectPath }  --configuration Release /t:PublishContainer /p:ContainerRepository={ resource . Name } "; 
203+                 var  arguments  =  $ "publish \" { projectMetadata . ProjectPath } \"  --configuration Release /t:PublishContainer /p:ContainerRepository=\" { resource . Name } \" "; 
204204
205205                // Add additional arguments based on options 
206206                if  ( options  is  not null ) 
207207                { 
208208                    if  ( ! string . IsNullOrEmpty ( options . OutputPath ) ) 
209209                    { 
210-                         arguments  +=  $ " /p:ContainerArchiveOutputPath={ options . OutputPath } "; 
210+                         arguments  +=  $ " /p:ContainerArchiveOutputPath=\" { options . OutputPath } \" "; 
211211                    } 
212212
213213                    if  ( options . ImageFormat . HasValue ) 
@@ -219,12 +219,12 @@ private async Task BuildProjectContainerImageAsync(IResource resource, IPublishi
219219                            ContainerImageFormat . DockerTar  =>  "DockerTar" , 
220220                            _ =>  throw  new  ArgumentOutOfRangeException ( nameof ( options ) ,  options . ImageFormat ,  "Invalid container image format" ) 
221221                        } ; 
222-                         arguments  +=  $ " /p:ContainerImageFormat={ format } "; 
222+                         arguments  +=  $ " /p:ContainerImageFormat=\" { format } \" "; 
223223                    } 
224224
225225                    if  ( ! string . IsNullOrEmpty ( options . TargetPlatform ) ) 
226226                    { 
227-                         arguments  +=  $ " /p:ContainerRuntimeIdentifier={ options . TargetPlatform } "; 
227+                         arguments  +=  $ " /p:ContainerRuntimeIdentifier=\" { options . TargetPlatform } \" "; 
228228                    } 
229229                } 
230230
@@ -272,6 +272,82 @@ private async Task BuildProjectContainerImageAsync(IResource resource, IPublishi
272272                } 
273273            } 
274274        } 
275+         else 
276+         { 
277+             // Handle case when publishingTask is null (no step provided) 
278+             // This is a resource project so we'll use the .NET SDK to build the container image. 
279+             if  ( ! resource . TryGetLastAnnotation < IProjectMetadata > ( out  var  projectMetadata ) ) 
280+             { 
281+                 throw  new  DistributedApplicationException ( $ "The resource '{ projectMetadata } ' does not have a project metadata annotation.") ; 
282+             } 
283+ 
284+             var  arguments  =  $ "publish \" { projectMetadata . ProjectPath } \"  --configuration Release /t:PublishContainer /p:ContainerRepository=\" { resource . Name } \" "; 
285+ 
286+             // Add additional arguments based on options 
287+             if  ( options  is  not null ) 
288+             { 
289+                 if  ( ! string . IsNullOrEmpty ( options . OutputPath ) ) 
290+                 { 
291+                     arguments  +=  $ " /p:ContainerArchiveOutputPath=\" { options . OutputPath } \" "; 
292+                 } 
293+ 
294+                 if  ( options . ImageFormat . HasValue ) 
295+                 { 
296+                     var  format  =  options . ImageFormat . Value  switch 
297+                     { 
298+                         ContainerImageFormat . Docker  =>  "Docker" , 
299+                         ContainerImageFormat . OciTar  =>  "OciTar" , 
300+                         ContainerImageFormat . DockerTar  =>  "DockerTar" , 
301+                         _ =>  throw  new  ArgumentOutOfRangeException ( nameof ( options ) ,  options . ImageFormat ,  "Invalid container image format" ) 
302+                     } ; 
303+                     arguments  +=  $ " /p:ContainerImageFormat=\" { format } \" "; 
304+                 } 
305+ 
306+                 if  ( ! string . IsNullOrEmpty ( options . TargetPlatform ) ) 
307+                 { 
308+                     arguments  +=  $ " /p:ContainerRuntimeIdentifier=\" { options . TargetPlatform } \" "; 
309+                 } 
310+             } 
311+ 
312+             var  spec  =  new  ProcessSpec ( "dotnet" ) 
313+             { 
314+                 Arguments  =  arguments , 
315+                 OnOutputData  =  output => 
316+                 { 
317+                     logger . LogInformation ( "dotnet publish {ProjectPath} (stdout): {Output}" ,  projectMetadata . ProjectPath ,  output ) ; 
318+                 } , 
319+                 OnErrorData  =  error => 
320+                 { 
321+                     logger . LogError ( "dotnet publish {ProjectPath} (stderr): {Error}" ,  projectMetadata . ProjectPath ,  error ) ; 
322+                 } 
323+             } ; 
324+ 
325+             logger . LogInformation ( 
326+                 "Starting .NET CLI with arguments: {Arguments}" , 
327+                 string . Join ( " " ,  spec . Arguments ) 
328+                 ) ; 
329+ 
330+             var  ( pendingProcessResult ,  processDisposable )  =  ProcessUtil . Run ( spec ) ; 
331+ 
332+             await  using  ( processDisposable ) 
333+             { 
334+                 var  processResult  =  await  pendingProcessResult 
335+                     . WaitAsync ( cancellationToken ) 
336+                     . ConfigureAwait ( false ) ; 
337+ 
338+                 if  ( processResult . ExitCode  !=  0 ) 
339+                 { 
340+                     logger . LogError ( "dotnet publish for project {ProjectPath} failed with exit code {ExitCode}." ,  projectMetadata . ProjectPath ,  processResult . ExitCode ) ; 
341+                     throw  new  DistributedApplicationException ( $ "Failed to build container image.") ; 
342+                 } 
343+                 else 
344+                 { 
345+                     logger . LogDebug ( 
346+                         ".NET CLI completed with exit code: {ExitCode}" , 
347+                         processResult . ExitCode ) ; 
348+                 } 
349+             } 
350+         } 
275351    } 
276352
277353    private  async  Task  BuildContainerImageFromDockerfileAsync ( string  resourceName ,  string  contextPath ,  string  dockerfilePath ,  string  imageName ,  IPublishingStep ?  step ,  ContainerBuildOptions ?  options ,  CancellationToken  cancellationToken ) 
0 commit comments