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

net-daemon / netdaemon / 6682312374

29 Oct 2023 08:42AM UTC coverage: 79.419% (-1.3%) from 80.706%
6682312374

Pull #958

github

web-flow
Refactors (#979)

* Primary ctrs and some warnings fixed

* Adding timeout
Pull Request #958: .NET 8 version 4 release

802 of 1143 branches covered (0.0%)

Branch coverage included in aggregate %.

108 of 108 new or added lines in 17 files covered. (100.0%)

2891 of 3507 relevant lines covered (82.44%)

50.41 hits per line

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

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

5
namespace NetDaemon.HassModel.CodeGenerator;
6

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

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

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

42
    private static IEnumerable<(string name, string version)>GetPackageReferences(string projectFilePath)
43
    {
44
        var csproj = new XmlDocument();
×
45
        csproj.Load(projectFilePath);
×
46
        var nodes = csproj.SelectNodes("//PackageReference[@Include and @Version]");
×
47
        if (nodes is null) yield break;
×
48

49
        foreach (XmlNode packageReference in nodes)
×
50
        {
51
            var packageName = packageReference.Attributes?["Include"]?.Value;
×
52
            var version = packageReference.Attributes?["Version"]?.Value;
×
53
            if (packageName is not null && version is not null)
×
54
            {
55
                yield return (packageName, version);
×
56
            }
57
        }
58
    }
×
59
}
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