Skip to content

Commit 21a1e48

Browse files
authored
Merge pull request #9605 from dotnet-maestro-bot/merge/vs17.9-to-main
[automated] Merge branch 'vs17.9' => 'main'
2 parents 10f2f32 + 26b5d33 commit 21a1e48

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/Tasks/ManifestUtil/Manifest.cs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/Tasks/ResolveManifestFiles.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,14 +285,17 @@ private ITaskItem CreateFileItem(ITaskItem item, string group, string targetPath
285285
{
286286
targetPath = Path.GetFileName(item.ItemSpec);
287287
//
288-
// .NETCore Launcher.exe based deployment: If the file is apphost.exe, we need to set 'TargetPath' metadata
289-
// to {assemblyname}.exe so that the file gets published as {assemblyname}.exe and not apphost.exe.
288+
// .NET >= 5 ClickOnce: If TargetPath metadata is not present in apphost.exe's metadata, we'll fallback to using AssemblyName
290289
//
291290
if (LauncherBasedDeployment &&
292291
targetPath.Equals(Constants.AppHostExe, StringComparison.InvariantCultureIgnoreCase) &&
293292
!String.IsNullOrEmpty(AssemblyName))
294293
{
295-
targetPath = AssemblyName;
294+
targetPath = item.GetMetadata(ItemMetadataNames.targetPath);
295+
if (String.IsNullOrEmpty(targetPath))
296+
{
297+
targetPath = AssemblyName;
298+
}
296299
}
297300
else
298301
{

0 commit comments

Comments
 (0)