• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

net-daemon / netdaemon / 8907002963

01 May 2024 08:06AM UTC coverage: 81.292% (-0.05%) from 81.342%
8907002963

push

github

web-flow
Fix the version comparation error for pre-releases in CodeGen tool (#1088)

832 of 1187 branches covered (70.09%)

Branch coverage included in aggregate %.

2 of 3 new or added lines in 1 file covered. (66.67%)

3 existing lines in 2 files now uncovered.

3144 of 3704 relevant lines covered (84.88%)

51.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

4.0
/src/HassModel/NetDaemon.HassModel.CodeGenerator/DependencyValidator.cs
1
using System.Diagnostics.CodeAnalysis;
2
using System.Xml;
3

4
namespace NetDaemon.HassModel.CodeGenerator;
5

6
public static class DependencyValidator
7
{
8
    /// <summary>
9
    /// Check if the PackageReferences for the NetDameon Nugets match the version of the nd-codegen tool
10
    /// </summary>
11
    [SuppressMessage("Design", "CA1031:Do not catch general exception types")]
12
    public static void ValidatePackageRefrences()
13
    {
14
        try
15
        {
16
            var packages = GetProjects().SelectMany(project => GetPackageReferences(project).Select(package => (project, package)));
×
17
            var mismatches = packages.Where(p => p.package.name.StartsWith("NetDaemon.", StringComparison.InvariantCulture) && p.package.version != VersionHelper.GeneratorVersion.ToString(3)).ToList();
×
18
            if (mismatches.Any())
×
19
            {
20
                Console.ForegroundColor = ConsoleColor.Yellow;
×
21
                Console.WriteLine($"Warning: NetDaemon PackageReferences were found that do not match the version of nd-codegen ({VersionHelper.GeneratorVersion}) " + Environment.NewLine +
×
22
                                  "It is advised to keep the ND-codegen tool in sync with the installed versions of the nuget packages");
×
23
                Console.ResetColor();
×
24

25
                foreach (var (project, (packagename, packgeversion)) in mismatches)
×
26
                {
27
                    Console.WriteLine($"    Project: {project}, Package: {packagename}:{packgeversion}");
×
28
                }
29
            }
30
        }
×
31
        catch (Exception ex)
32
        {
33
            // ignored, we do not want to fail in case something goes wrong in eg. parsing the project files
34
            Console.WriteLine("Unable to validate PackageReferences");
×
35
            Console.WriteLine(ex);
×
36
        }
×
37
    }
×
38

39
    public static IEnumerable<string> GetProjects() => Directory.GetFiles(".", "*.csproj", SearchOption.AllDirectories);
×
40

41
    /// <summary>
42
    /// Trims the pre-release information from a version string
43
    /// </summary>
44
    internal static string TrimPreReleaseVersion(string version)
45
    {
46
        var parts = version.Split('-');
3✔
47
        return parts[0];
3✔
48
    }
49

50
    private static IEnumerable<(string name, string version)>GetPackageReferences(string projectFilePath)
51
    {
52
        var csproj = new XmlDocument();
×
53
        csproj.Load(projectFilePath);
×
54
        var nodes = csproj.SelectNodes("//PackageReference[@Include and @Version]");
×
55
        if (nodes is null) yield break;
×
56

57
        foreach (XmlNode packageReference in nodes)
×
58
        {
59
            var packageName = packageReference.Attributes?["Include"]?.Value;
×
60
            var version = packageReference.Attributes?["Version"]?.Value;
×
61
            if (packageName is not null && version is not null)
×
62
            {
NEW
63
                packageName = TrimPreReleaseVersion(packageName);
×
UNCOV
64
                yield return (packageName, version);
×
65
            }
66
        }
67
    }
×
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc