Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions src/Tasks/ManifestUtil/Manifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
9 changes: 6 additions & 3 deletions src/Tasks/ResolveManifestFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down