Incorrect src attribute in nuspec file causing file not found exception
yll690 opened this issue · comments
Type (choose one):
- Bug
NPE version: (e.g. 5.x) (see Help -> about)
NuGet Package Explorer - Zip - X64 - (6.0.92+c06b7b6e25)
OS version: (Windows 7, 10 - 1803/17134, etc)
Windows11 22621.2715
Installed from: Microsoft Store / Chocolatey.org / Zip on GitHub / CI channel
Zip on GitHub and source code
Open a nuspec file saved by this tool failed. A message box says "Could not find a path" or "File not found" is shown. Here are the steps to reproduce:
- Create a package
- Add an existing file
- Save the metadata to a nuspec file (must in a different folder from the existing file)
- Open the nuspec file
The problem is the src
attribute of file does not be set correctly. The src
has the same value with target
rather than the relative or absolutive path on disk. So it can not be found.
<files>
<file src="lib\net45\zh-CN\DeviceState.resources.dll" target="lib\net45\zh-CN\DeviceState.resources.dll" />
<file src="lib\net45\AlarmLevel.cfg" target="lib\net45\AlarmLevel.cfg" />
<file src="lib\net45\DeviceNameOverride.cfg" target="lib\net45\DeviceNameOverride.cfg" />
<file src="lib\net45\DeviceState.dll" target="lib\net45\DeviceState.dll" />
<file src="lib\net45\DeviceState.pdb" target="lib\net45\DeviceState.pdb" />
</files>
I debug for a while and find the bug in PackageViewModel.ExportManifest
method. The OriginalPath
method wants to convert PackageFile
to PackageFileBase
to get the OriginalPath
but failed because PackageFile
does not derive from PackageFileBase
and has its own OriginalPath
property. So changing the OriginalPath
method to
public static string? OriginalPath(this IPackageFile? packageFile)
{
if (packageFile is PackageFileBase packageFileBase)
return packageFileBase.OriginalPath;
else if (packageFile is PhysicalPackageFile physicalPackageFile)
return physicalPackageFile.SourcePath;
else if (packageFile is IPackageContent packageContent)
return packageContent.OriginalPath;
return null;
}
seems solving the issue. Could someone have a look?