diff --git a/eng/Versions.props b/eng/Versions.props index 6c0a14f7560..c11746584e4 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -2,7 +2,7 @@ - 17.9.1 + 17.9.2 release 17.8.3 15.1.0.0 diff --git a/src/Tasks/ManifestUtil/Manifest.cs b/src/Tasks/ManifestUtil/Manifest.cs index 938c839fd47..d8e5b2a8fdd 100644 --- a/src/Tasks/ManifestUtil/Manifest.cs +++ b/src/Tasks/ManifestUtil/Manifest.cs @@ -487,7 +487,7 @@ private void UpdateAssemblyReference(AssemblyReference a, string targetFramework private void UpdateFileReference(BaseReference f, string targetFrameworkVersion) { - if (String.IsNullOrEmpty(f.ResolvedPath)) + if (string.IsNullOrEmpty(f.ResolvedPath)) { throw new FileNotFoundException(null, f.SourcePath); } @@ -506,22 +506,33 @@ private void UpdateFileReference(BaseReference f, string targetFrameworkVersion) f.Size = size; // - // .NETCore Launcher.exe based Deployment: If the filereference is for apphost.exe, we need to change - // the ResolvedPath and TargetPath to {assemblyname}.exe before we write the manifest, so that the - // manifest does not have a file reference to apphost.exe + // .NET >= 5 ClickOnce: If the file reference is for apphost.exe, we need to change the filename + // in ResolvedPath to TargetPath so we don't end up publishing the file as apphost.exe. + // If the TargetPath is not present, we will fallback to AssemblyName. // string fileName = Path.GetFileName(f.ResolvedPath); if (LauncherBasedDeployment && - fileName.Equals(Constants.AppHostExe, StringComparison.InvariantCultureIgnoreCase) && - !String.IsNullOrEmpty(AssemblyName)) + fileName.Equals(Constants.AppHostExe, StringComparison.InvariantCultureIgnoreCase)) { - f.ResolvedPath = Path.Combine(Path.GetDirectoryName(f.ResolvedPath), AssemblyName); - f.TargetPath = BaseReference.GetDefaultTargetPath(f.ResolvedPath); + if (!string.IsNullOrEmpty(f.TargetPath)) + { + f.ResolvedPath = Path.Combine(Path.GetDirectoryName(f.ResolvedPath), f.TargetPath); + } + else if (!string.IsNullOrEmpty(AssemblyName)) + { + f.ResolvedPath = Path.Combine(Path.GetDirectoryName(f.ResolvedPath), AssemblyName); + f.TargetPath = BaseReference.GetDefaultTargetPath(f.ResolvedPath); + } + else + { + Debug.Assert(false, "AssemblyName cannot be empty"); + OutputMessages.AddWarningMessage("GenerateManifest.InvalidValue", "AssemblyName"); + } } - if (String.IsNullOrEmpty(f.TargetPath)) + if (string.IsNullOrEmpty(f.TargetPath)) { - if (!String.IsNullOrEmpty(f.SourcePath)) + if (!string.IsNullOrEmpty(f.SourcePath)) { f.TargetPath = BaseReference.GetDefaultTargetPath(f.SourcePath); } diff --git a/src/Tasks/ResolveManifestFiles.cs b/src/Tasks/ResolveManifestFiles.cs index 9b98bcf97a8..9a78f010f16 100644 --- a/src/Tasks/ResolveManifestFiles.cs +++ b/src/Tasks/ResolveManifestFiles.cs @@ -285,14 +285,17 @@ private ITaskItem CreateFileItem(ITaskItem item, string group, string targetPath { targetPath = Path.GetFileName(item.ItemSpec); // - // .NETCore Launcher.exe based deployment: If the file is apphost.exe, we need to set 'TargetPath' metadata - // to {assemblyname}.exe so that the file gets published as {assemblyname}.exe and not apphost.exe. + // .NET >= 5 ClickOnce: If TargetPath metadata is not present in apphost.exe's metadata, we'll fallback to using AssemblyName // if (LauncherBasedDeployment && targetPath.Equals(Constants.AppHostExe, StringComparison.InvariantCultureIgnoreCase) && !String.IsNullOrEmpty(AssemblyName)) { - targetPath = AssemblyName; + targetPath = item.GetMetadata(ItemMetadataNames.targetPath); + if (String.IsNullOrEmpty(targetPath)) + { + targetPath = AssemblyName; + } } else {