@@ -487,7 +487,7 @@ private void UpdateAssemblyReference(AssemblyReference a, string targetFramework
487487
488488 private void UpdateFileReference ( BaseReference f , string targetFrameworkVersion )
489489 {
490- if ( String . IsNullOrEmpty ( f . ResolvedPath ) )
490+ if ( string . IsNullOrEmpty ( f . ResolvedPath ) )
491491 {
492492 throw new FileNotFoundException ( null , f . SourcePath ) ;
493493 }
@@ -506,22 +506,33 @@ private void UpdateFileReference(BaseReference f, string targetFrameworkVersion)
506506 f . Size = size ;
507507
508508 //
509- // .NETCore Launcher.exe based Deployment : If the filereference is for apphost.exe, we need to change
510- // the ResolvedPath and TargetPath to {assemblyname}.exe before we write the manifest, so that the
511- // manifest does not have a file reference to apphost.exe
509+ // .NET >= 5 ClickOnce : If the file reference is for apphost.exe, we need to change the filename
510+ // in ResolvedPath to TargetPath so we don't end up publishing the file as apphost.exe.
511+ // If the TargetPath is not present, we will fallback to AssemblyName.
512512 //
513513 string fileName = Path . GetFileName ( f . ResolvedPath ) ;
514514 if ( LauncherBasedDeployment &&
515- fileName . Equals ( Constants . AppHostExe , StringComparison . InvariantCultureIgnoreCase ) &&
516- ! String . IsNullOrEmpty ( AssemblyName ) )
515+ fileName . Equals ( Constants . AppHostExe , StringComparison . InvariantCultureIgnoreCase ) )
517516 {
518- f . ResolvedPath = Path . Combine ( Path . GetDirectoryName ( f . ResolvedPath ) , AssemblyName ) ;
519- f . TargetPath = BaseReference . GetDefaultTargetPath ( f . ResolvedPath ) ;
517+ if ( ! string . IsNullOrEmpty ( f . TargetPath ) )
518+ {
519+ f . ResolvedPath = Path . Combine ( Path . GetDirectoryName ( f . ResolvedPath ) , f . TargetPath ) ;
520+ }
521+ else if ( ! string . IsNullOrEmpty ( AssemblyName ) )
522+ {
523+ f . ResolvedPath = Path . Combine ( Path . GetDirectoryName ( f . ResolvedPath ) , AssemblyName ) ;
524+ f . TargetPath = BaseReference . GetDefaultTargetPath ( f . ResolvedPath ) ;
525+ }
526+ else
527+ {
528+ Debug . Assert ( false , "AssemblyName cannot be empty" ) ;
529+ OutputMessages . AddWarningMessage ( "GenerateManifest.InvalidValue" , "AssemblyName" ) ;
530+ }
520531 }
521532
522- if ( String . IsNullOrEmpty ( f . TargetPath ) )
533+ if ( string . IsNullOrEmpty ( f . TargetPath ) )
523534 {
524- if ( ! String . IsNullOrEmpty ( f . SourcePath ) )
535+ if ( ! string . IsNullOrEmpty ( f . SourcePath ) )
525536 {
526537 f . TargetPath = BaseReference . GetDefaultTargetPath ( f . SourcePath ) ;
527538 }
0 commit comments