Zeugwerk / Twinpack

Twinpack is a package manager for TwinCAT libraries with integration into the TwinCAT IDE. It enables the TwinCAT community to share their libraries and simplifies the continous integration of third-party components into TwinCAT projects.
https://twinpack.dev
GNU General Public License v3.0
52 stars 3 forks source link

Unable to list packages on Azure Artifacts server #137

Closed dfreiberger closed 3 months ago

dfreiberger commented 3 months ago

After publishing a nuget package with the below nuspec file to an azure feed, and successfully connecting and logging into the feed with Twinpack, I was not able to list the packages including this one.

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
  <metadata>
    <id>Core</id>
    <version>1.2.3.6</version>
    <title>MyCompany Library Core</title>
    <authors>MyCompany Corporation</authors>
    <!-- <owners></owners> -->
    <!-- <licenseUrl></licenseUrl> -->
    <projectUrl>https://link.to.repo</projectUrl>
    <!-- <iconUrl></iconUrl> -->
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>MyCompany Library Core version 1.2.3.6</description>
    <!-- <summary> </summary> -->
    <!-- <releaseNotes></releaseNotes> -->
    <copyright>MyCompany</copyright>
    <tags>Beckhoff TwinCAT XAE PLC Library Core</tags>
    <!-- <bugTrackerUrl></bugTrackerUrl> -->
    <!-- <docsUrl></docsUrl> -->
    <!-- <mailingListUrl></mailingListUrl> -->
    <!-- <packageSourceUrl></packageSourceUrl> -->
  </metadata>
  <files>
    <file src="Core.library" target="" />
  </files>
</package>

After troubleshooting, I found that the "Publish" field is null, which causes this section https://github.com/Zeugwerk/Twinpack/blob/0d136edcee7792de649ca0c80049246c7a0ed9f9/TwinpackShared/Protocol/Nuget/NugetServer.cs#L132 to throw a silent error and return no results.

The issue could be resolved by changing the code as follows:

new Tuple<IEnumerable<CatalogItemGetResponse>, bool>(
results.Select(x =>
    new CatalogItemGetResponse()
    {
        PackageId = null,
        Name = x.Identity.Id,
        DistributorName = x.Authors,
        // Description = x.Description, Beckhoff's descriptions are meh
        IconUrl = x.IconUrl?.ToString() ?? IconUrl,
        RuntimeLicense = 1,
        DisplayName = x.Identity.Id,
        Downloads = x.DownloadCount.HasValue ? (int)x.DownloadCount.Value : 0,  // Added null check
        Created = x.Published?.ToString() ?? "Unknown",  // Added null check
        Modified = x.Published?.ToString() ?? "Unknown"  // Added null check
    }).ToList(),
results.Any());                     
iadonkey commented 3 months ago

Thanks for this finding, isn't it only the download count though, which causes the issue? The other fields already had null checks

Will fix it and make a patch release 1.0.8 for the null checks

In your nuspec, you can also write a real description if you want. Will uncomment this line as well. You don’t need the tags “Beckhoff TwinCAT XAE PLC” btw and in title you don’t need “MyCompany Library”

Just fyi: having this “Library” followed by the name of the library in tags is only a temporary thing. For Beckhoff’s packages we didn’t find any other way as we can’t read the library title from their compiled-library files, we only have an implementation that can read it from normal library files (which we currently don’t do, but will in the future)