neovolve - Neovolve.CodeAnalysis.ChangeTracking 3.1.0-90-renamedtype0001

This library provides Semantic Versioning impact analysis between two versions of c# code.

PM> Install-Package Neovolve.CodeAnalysis.ChangeTracking -Version 3.1.0-90-renamedtype0001 -Source https://www.myget.org/F/neovolve/api/v3/index.json

Copy to clipboard

> nuget.exe install Neovolve.CodeAnalysis.ChangeTracking -Version 3.1.0-90-renamedtype0001 -Source https://www.myget.org/F/neovolve/api/v3/index.json

Copy to clipboard

> dotnet add package Neovolve.CodeAnalysis.ChangeTracking --version 3.1.0-90-renamedtype0001 --source https://www.myget.org/F/neovolve/api/v3/index.json

Copy to clipboard
<PackageReference Include="Neovolve.CodeAnalysis.ChangeTracking" Version="3.1.0-90-renamedtype0001" />
Copy to clipboard
source https://www.myget.org/F/neovolve/api/v3/index.json

nuget Neovolve.CodeAnalysis.ChangeTracking  ~> 3.1.0-90-renamedtype0001
Copy to clipboard

> choco install Neovolve.CodeAnalysis.ChangeTracking --version 3.1.0-90-renamedtype0001 --source https://www.myget.org/F/neovolve/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "neovolve" -SourceLocation "https://www.myget.org/F/neovolve/api/v2"
Install-Module -Name "Neovolve.CodeAnalysis.ChangeTracking" -RequiredVersion "3.1.0-90-renamedtype0001" -Repository "neovolve" -AllowPreRelease
Copy to clipboard

Neovolve.CodeAnalysis.ChangeTracking

C# code analysis tool for evaluating changes to contracts

GitHub license Nuget Nuget Actions Status

Introduction

Neovolve.CodeAnalysis.ChangeTracking is a package that calculates changes between two versions of C# code to identify what has changed in regard to Semantic Versioning. The outcome will be an overall Semantic Version change result (None, Feature, Breaking) as well as a collection of changes. Each change in the collection identifies the source and target change along with a message indicating the change and the SemVer impact of that change.

Installation

Production and beta versions are available on NuGet.

Install-Package Neovolve.CodeAnalysis.ChangeTracking

Continous Integration builds are available on MyGet.

Install-Package Neovolve.CodeAnalysis.ChangeTracking -Source https://www.myget.org/F/neovolve/api/v3/index.json

Features

This library will determine whether C# code has changed in a way that introduces a new feature or a breaking change.

Changes are evaluated for:

  • Classes
  • Interfaces
  • Structs
  • Properties
  • Fields
  • Methods
  • Attributes

The types of changes evaluated are:

  • Items removed
  • Items added
  • Items renamed
  • Changes to namespace (moved types, renamed namespace)
  • Changes of types
  • Changes to access modifiers
  • Changes to modifiers
  • Changes to generic type parameters
  • Changes to generic type constraints

Changes not currently evaluated are:

  • net5.0 record types
  • net5.0 init properties

Usage

var oldCode = new List<CodeSource>
{
    new CodeSource(@"
        public class Test
        {
            public string Value;
        }", "Test.cs")
};
var newCode = new List<CodeSource>
{
    new CodeSource(@"
        public class Test
        {
            public bool Value;
        }", "Test.cs")
};

var calculator = ChangeCalculatorFactory.BuildCalculator();

var result = await calculator.CalculateChange(oldCode, newCode).ConfigureAwait(false);

if (result.ChangeType == ChangeType.None) 
{
    // Looks like there is no change in the members
}
else if (result.ChangeType == ChangeType.Feature)
{
    // Looks like members have been added to the code
}
else if (result.ChangeType == ChangeType.Breaking)
{
    // Looks like members have been removed or changed
}

Limitations

The library evaluates code changes by parsing the code text. The advantage of this method is that the code does not need to be compiled, dependencies do not need to be resolved and any C# project usage is supported. In fact the csproj itself is not even supported as the library only parses cs files. The disadvantage is that evaluating code changes can produce false positivies because all differences are evaluated as string values.

For example, the following two code blocks when evaluated will indicate a breaking change. In reality, it is likely that the code will compile to the same outcome.

public MyNamespace
{
    public class MyClass
    {
        public System.DateTime MyValue { get; set; }
    }
}
using System;

public MyNamespace
{
    public class MyClass
    {
        public DateTime MyValue { get; set; }
    }
}

Frequently asked questions

Why does SemVerChangeType define None instead of Patch?

This package attempts to calculate the Semantic Version impact on a C# binary based on changes to the public API surface (see attribute comparison below). Adding new signatures would be calculated as a feature and removing or modifying signatures would result in a breaking change.

There are only two other scenarios that could occur between two sets of C# code. There is either no change or there is a change to internal logic where there is no impact on the public API surface. No change should not even be identified as a patch change while changes to internal logic should be a patch change. As the library does not look at internal code, it can't actually determine the difference between these two scenarios so it does not attempt to identify a patch change as this may be misleading.

Why do attribute changes identify a feature or breaking change when the public API signature hasn't changed?

There is an edge case to the idea that the library only compares the public API surface between two versions of C# code. The library also evaluates changes to attributes based on the ComparerOptions class in order to determine a Semantic Version impact of attributes.

What this means is that the C# signatures could be the same, but attribute changes regarding XML and JSON serialization could cause a potential breaking change to consumers of the library. So signatures compiled into the binary are the same, but the attributes are telling the runtime to handle serialization differently.

For example, consider this change. Here is the old code.

using System;

public MyNamespace
{
    public class MyClass
    {
        public DateTime MyValue { get; set; }
    }
}

Here is the new code.

using System;
using System.Text.Json.Serialization;

public MyNamespace
{
    [JsonPropertyName("otherValue")]
    public class MyClass
    {
        public DateTime MyValue { get; set; }
    }
}

This is a breaking change to consumers because the json serialization of this class has changed the name of the property from MyValue to otherValue.

Resources

Combinations of data sets (combinations of access modifiers for example) were calculated using https://www.mathsisfun.com/combinatorics/combinations-permutations-calculator.html.

This project is supported by JetBrains

  • .NETFramework 5.0
    • Microsoft.CodeAnalysis.CSharp (>= 3.11.0)
    • Microsoft.Extensions.Logging.Abstractions (>= 3.1.9)
  • .NETStandard 2.1
    • Microsoft.CodeAnalysis.CSharp (>= 3.11.0)
    • Microsoft.Extensions.Logging.Abstractions (>= 3.1.9)
  • .NETFramework 5.0: 5.0.0.0
  • .NETStandard 2.1: 2.1.0.0

Owners

rprimrose

Authors

rprimrose

Project URL

https://github.com/roryprimrose/Neovolve.CodeAnalysis.ChangeTracking

License

Unknown

Tags

Analysis SemVer Semantic Versioning C# Code Analysis

Info

0 total downloads
0 downloads for version 3.1.0-90-renamedtype0001
Download (172.55 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
3.1.0-90-renamedtype0001 172.55 KB Wed, 29 Dec 2021 05:37:20 GMT 0
3.0.0 166.78 KB Sat, 06 Nov 2021 06:33:23 GMT 0
3.0.0-securityworkflow0013 165.52 KB Sat, 09 Oct 2021 04:48:56 GMT 0
3.0.0-securityworkflow0012 165.52 KB Sat, 09 Oct 2021 04:42:21 GMT 0
3.0.0-securityworkflow0007 165.5 KB Mon, 04 Oct 2021 05:20:54 GMT 0
3.0.0-documentation0015 166.85 KB Sat, 16 Oct 2021 05:02:54 GMT 0
3.0.0-beta0034 166.8 KB Sun, 17 Oct 2021 05:49:49 GMT 0
3.0.0-beta0033 166.8 KB Sat, 16 Oct 2021 05:05:03 GMT 0
3.0.0-beta0032 166.91 KB Sun, 10 Oct 2021 05:32:19 GMT 0
3.0.0-beta0031 165.44 KB Sat, 09 Oct 2021 04:56:34 GMT 0
3.0.0-beta0030 165.42 KB Mon, 04 Oct 2021 05:28:39 GMT 0
2.0.1 235.73 KB Sun, 29 Aug 2021 12:32:24 GMT 0
2.0.0 235.42 KB Sun, 29 Aug 2021 02:32:56 GMT 0
1.0.0 43.83 KB Sat, 08 Aug 2020 06:23:45 GMT 0