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

net-daemon / netdaemon / 6368659139

01 Oct 2023 06:28AM UTC coverage: 81.178% (-0.9%) from 82.053%
6368659139

push

github

web-flow
Validate version of nugets and nd-codegen match (#945)

810 of 1148 branches covered (0.0%)

Branch coverage included in aggregate %.

29 of 29 new or added lines in 3 files covered. (100.0%)

2938 of 3469 relevant lines covered (84.69%)

50.74 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("JoySoftware.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

© 2025 Coveralls, Inc