From 60ed34059219820d01ddb42a96954ee96b999593 Mon Sep 17 00:00:00 2001 From: Erwin de Haan Date: Mon, 8 Jun 2020 23:31:41 +0200 Subject: [PATCH] Adjust help text, LICENSE and NOTICE, move to nuget packages and cleanup old stuff. --- .gitignore | 1 + .../CompatibilityChecker.Libary.Tests.csproj | 24 ++ .../TestAssemblyAnalysis.cs | 109 +++++++++ .../TestTypeAnalysis.cs | 190 ++++++++++++++++ .../TestUtility.cs | 65 ++++++ .../CompatibilityChecker.Library.csproj | 10 +- CompatibilityChecker.sln | 13 +- .../CompatibilityChecker.csproj | 14 +- CompatibilityChecker/Program.cs | 4 +- .../Properties/launchSettings.json | 3 +- LICENSE | 209 +++++++++++++++++- NOTICE | 5 + README.md | 21 ++ build-release-package-for-ci.bat | 13 -- pack.bat | 5 + 15 files changed, 647 insertions(+), 39 deletions(-) create mode 100644 CompatibilityChecker.Libary.Tests/CompatibilityChecker.Libary.Tests.csproj create mode 100644 CompatibilityChecker.Libary.Tests/TestAssemblyAnalysis.cs create mode 100644 CompatibilityChecker.Libary.Tests/TestTypeAnalysis.cs create mode 100644 CompatibilityChecker.Libary.Tests/TestUtility.cs create mode 100644 NOTICE delete mode 100644 build-release-package-for-ci.bat create mode 100644 pack.bat diff --git a/.gitignore b/.gitignore index 3a9234e..7d23ba4 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ MigrationBackup/ # MacOS .DS_Store +packed/ diff --git a/CompatibilityChecker.Libary.Tests/CompatibilityChecker.Libary.Tests.csproj b/CompatibilityChecker.Libary.Tests/CompatibilityChecker.Libary.Tests.csproj new file mode 100644 index 0000000..d3e0303 --- /dev/null +++ b/CompatibilityChecker.Libary.Tests/CompatibilityChecker.Libary.Tests.csproj @@ -0,0 +1,24 @@ + + + + netcoreapp3.1 + + false + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/CompatibilityChecker.Libary.Tests/TestAssemblyAnalysis.cs b/CompatibilityChecker.Libary.Tests/TestAssemblyAnalysis.cs new file mode 100644 index 0000000..c6e9ce1 --- /dev/null +++ b/CompatibilityChecker.Libary.Tests/TestAssemblyAnalysis.cs @@ -0,0 +1,109 @@ +namespace CompatibilityCheckerTests +{ + using System.Collections.ObjectModel; + using System.Reflection; + using System.Reflection.Emit; + using CompatibilityChecker.Library; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class TestAssemblyAnalysis + { + [TestMethod] + public void TestAssemblyNameMustNotBeChanged_Pass() + { + AssemblyName referenceName = new AssemblyName("Test.Assembly"); + AssemblyBuilder referenceAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(referenceName, AssemblyBuilderAccess.ReflectionOnly); + referenceAssemblyBuilder.Save("Test.Assembly.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + AssemblyName newAssemblyName = new AssemblyName("Test.Assembly"); + AssemblyBuilder newAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(newAssemblyName, AssemblyBuilderAccess.ReflectionOnly); + newAssemblyBuilder.Save("Test.Assembly.V2.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + ReadOnlyCollection messages = TestUtility.AnalyzeAssemblies("Test.Assembly.dll", "Test.Assembly.V2.dll"); + Assert.AreEqual(0, messages.Count); + } + + [TestMethod] + public void TestAssemblyNameMustNotBeChanged_Fail() + { + AssemblyName referenceName = new AssemblyName("Test.Assembly"); + AssemblyBuilder referenceAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(referenceName, AssemblyBuilderAccess.ReflectionOnly); + referenceAssemblyBuilder.Save("Test.Assembly.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + AssemblyName newAssemblyName = new AssemblyName("Test.Assembly.V2"); + AssemblyBuilder newAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(newAssemblyName, AssemblyBuilderAccess.ReflectionOnly); + newAssemblyBuilder.Save("Test.Assembly.V2.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + ReadOnlyCollection messages = TestUtility.AnalyzeAssemblies("Test.Assembly.dll", "Test.Assembly.V2.dll"); + Assert.AreEqual(1, messages.Count); + Assert.AreEqual("Error AssemblyNameMustNotBeChanged: The simple name of an assembly cannot change for 'Test.Assembly'.", messages[0].ToString()); + } + + [TestMethod] + public void TestPublicKeyMustNotBeChanged_PassMissing() + { + AssemblyName referenceName = new AssemblyName("Test.Assembly"); + AssemblyBuilder referenceAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(referenceName, AssemblyBuilderAccess.ReflectionOnly); + referenceAssemblyBuilder.Save("Test.Assembly.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + AssemblyName newAssemblyName = new AssemblyName("Test.Assembly"); + AssemblyBuilder newAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(newAssemblyName, AssemblyBuilderAccess.ReflectionOnly); + newAssemblyBuilder.Save("Test.Assembly.V2.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + ReadOnlyCollection messages = TestUtility.AnalyzeAssemblies("Test.Assembly.dll", "Test.Assembly.V2.dll"); + Assert.AreEqual(0, messages.Count); + } + + [TestMethod] + public void TestPublicKeyMustNotBeChanged_PassUnchanged() + { + AssemblyName referenceName = new AssemblyName("Test.Assembly"); + referenceName.KeyPair = TestUtility.GenerateStrongNameKeyPair(); + AssemblyBuilder referenceAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(referenceName, AssemblyBuilderAccess.ReflectionOnly); + referenceAssemblyBuilder.Save("Test.Assembly.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + AssemblyName newAssemblyName = new AssemblyName("Test.Assembly"); + newAssemblyName.KeyPair = referenceName.KeyPair; + AssemblyBuilder newAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(newAssemblyName, AssemblyBuilderAccess.ReflectionOnly); + newAssemblyBuilder.Save("Test.Assembly.V2.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + ReadOnlyCollection messages = TestUtility.AnalyzeAssemblies("Test.Assembly.dll", "Test.Assembly.V2.dll"); + Assert.AreEqual(0, messages.Count); + } + + [TestMethod] + public void TestPublicKeyMustNotBeChanged_PassAdded() + { + AssemblyName referenceName = new AssemblyName("Test.Assembly"); + AssemblyBuilder referenceAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(referenceName, AssemblyBuilderAccess.ReflectionOnly); + referenceAssemblyBuilder.Save("Test.Assembly.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + AssemblyName newAssemblyName = new AssemblyName("Test.Assembly"); + newAssemblyName.KeyPair = TestUtility.GenerateStrongNameKeyPair(); + AssemblyBuilder newAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(newAssemblyName, AssemblyBuilderAccess.ReflectionOnly); + newAssemblyBuilder.Save("Test.Assembly.V2.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + ReadOnlyCollection messages = TestUtility.AnalyzeAssemblies("Test.Assembly.dll", "Test.Assembly.V2.dll"); + Assert.AreEqual(0, messages.Count); + } + + [TestMethod] + public void TestPublicKeyMustNotBeChanged_Fail() + { + AssemblyName referenceName = new AssemblyName("Test.Assembly"); + referenceName.KeyPair = TestUtility.GenerateStrongNameKeyPair(); + AssemblyBuilder referenceAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(referenceName, AssemblyBuilderAccess.ReflectionOnly); + referenceAssemblyBuilder.Save("Test.Assembly.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + AssemblyName newAssemblyName = new AssemblyName("Test.Assembly"); + newAssemblyName.KeyPair = TestUtility.GenerateStrongNameKeyPair(); + AssemblyBuilder newAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(newAssemblyName, AssemblyBuilderAccess.ReflectionOnly); + newAssemblyBuilder.Save("Test.Assembly.V2.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + ReadOnlyCollection messages = TestUtility.AnalyzeAssemblies("Test.Assembly.dll", "Test.Assembly.V2.dll"); + Assert.AreEqual(1, messages.Count); + Assert.AreEqual("Error PublicKeyMustNotBeChanged: The public key of a strong-named assembly 'Test.Assembly' cannot change.", messages[0].ToString()); + } + } +} diff --git a/CompatibilityChecker.Libary.Tests/TestTypeAnalysis.cs b/CompatibilityChecker.Libary.Tests/TestTypeAnalysis.cs new file mode 100644 index 0000000..e4ac3fc --- /dev/null +++ b/CompatibilityChecker.Libary.Tests/TestTypeAnalysis.cs @@ -0,0 +1,190 @@ +namespace CompatibilityCheckerTests +{ + using System.Collections.ObjectModel; + using System.Reflection; + using System.Reflection.Emit; + using CompatibilityChecker.Library; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class TestTypeAnalysis + { + [TestMethod] + public void TestAbstractMustNotBeAddedToType_PassUnchanged() + { + AssemblyName assemblyName = new AssemblyName("Test.Assembly"); + AssemblyBuilder referenceAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save); + ModuleBuilder referenceModuleBuilder = referenceAssemblyBuilder.DefineDynamicModule(assemblyName.Name, "Test.Assembly.dll"); + TypeBuilder referenceTypeBuilder = referenceModuleBuilder.DefineType("MyType", TypeAttributes.Class | TypeAttributes.Public, typeof(object)); + referenceTypeBuilder.DefineDefaultConstructor(MethodAttributes.Family); + referenceTypeBuilder.CreateType(); + referenceAssemblyBuilder.Save("Test.Assembly.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + AssemblyBuilder newAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save); + ModuleBuilder newModuleBuilder = newAssemblyBuilder.DefineDynamicModule(assemblyName.Name, "Test.Assembly.V2.dll"); + TypeBuilder newTypeBuilder = newModuleBuilder.DefineType("MyType", TypeAttributes.Class | TypeAttributes.Public, typeof(object)); + newTypeBuilder.DefineDefaultConstructor(MethodAttributes.Family); + newTypeBuilder.CreateType(); + newAssemblyBuilder.Save("Test.Assembly.V2.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + ReadOnlyCollection messages = TestUtility.AnalyzeAssemblies("Test.Assembly.dll", "Test.Assembly.V2.dll"); + Assert.AreEqual(0, messages.Count); + } + + [TestMethod] + public void TestAbstractMustNotBeAddedToType_PassRemoved() + { + AssemblyName assemblyName = new AssemblyName("Test.Assembly"); + AssemblyBuilder referenceAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save); + ModuleBuilder referenceModuleBuilder = referenceAssemblyBuilder.DefineDynamicModule(assemblyName.Name, "Test.Assembly.dll"); + TypeBuilder referenceTypeBuilder = referenceModuleBuilder.DefineType("MyType", TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Abstract, typeof(object)); + referenceTypeBuilder.DefineDefaultConstructor(MethodAttributes.Family); + referenceTypeBuilder.CreateType(); + referenceAssemblyBuilder.Save("Test.Assembly.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + AssemblyBuilder newAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save); + ModuleBuilder newModuleBuilder = newAssemblyBuilder.DefineDynamicModule(assemblyName.Name, "Test.Assembly.V2.dll"); + TypeBuilder newTypeBuilder = newModuleBuilder.DefineType("MyType", TypeAttributes.Class | TypeAttributes.Public, typeof(object)); + newTypeBuilder.DefineDefaultConstructor(MethodAttributes.Family); + newTypeBuilder.CreateType(); + newAssemblyBuilder.Save("Test.Assembly.V2.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + ReadOnlyCollection messages = TestUtility.AnalyzeAssemblies("Test.Assembly.dll", "Test.Assembly.V2.dll"); + Assert.AreEqual(0, messages.Count); + } + + [TestMethod] + public void TestAbstractMustNotBeAddedToType_PassNotPublic() + { + AssemblyName assemblyName = new AssemblyName("Test.Assembly"); + AssemblyBuilder referenceAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save); + ModuleBuilder referenceModuleBuilder = referenceAssemblyBuilder.DefineDynamicModule(assemblyName.Name, "Test.Assembly.dll"); + TypeBuilder referenceTypeBuilder = referenceModuleBuilder.DefineType("MyType", TypeAttributes.Class | TypeAttributes.NotPublic, typeof(object)); + referenceTypeBuilder.DefineDefaultConstructor(MethodAttributes.Family); + referenceTypeBuilder.CreateType(); + referenceAssemblyBuilder.Save("Test.Assembly.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + AssemblyBuilder newAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save); + ModuleBuilder newModuleBuilder = newAssemblyBuilder.DefineDynamicModule(assemblyName.Name, "Test.Assembly.V2.dll"); + TypeBuilder newTypeBuilder = newModuleBuilder.DefineType("MyType", TypeAttributes.Class | TypeAttributes.NotPublic | TypeAttributes.Abstract, typeof(object)); + newTypeBuilder.DefineDefaultConstructor(MethodAttributes.Family); + newTypeBuilder.CreateType(); + newAssemblyBuilder.Save("Test.Assembly.V2.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + ReadOnlyCollection messages = TestUtility.AnalyzeAssemblies("Test.Assembly.dll", "Test.Assembly.V2.dll"); + Assert.AreEqual(0, messages.Count); + } + + [TestMethod] + public void TestAbstractMustNotBeAddedToType_Fail() + { + AssemblyName assemblyName = new AssemblyName("Test.Assembly"); + AssemblyBuilder referenceAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save); + ModuleBuilder referenceModuleBuilder = referenceAssemblyBuilder.DefineDynamicModule(assemblyName.Name, "Test.Assembly.dll"); + TypeBuilder referenceTypeBuilder = referenceModuleBuilder.DefineType("MyType", TypeAttributes.Class | TypeAttributes.Public, typeof(object)); + referenceTypeBuilder.DefineDefaultConstructor(MethodAttributes.Family); + referenceTypeBuilder.CreateType(); + referenceAssemblyBuilder.Save("Test.Assembly.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + AssemblyBuilder newAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save); + ModuleBuilder newModuleBuilder = newAssemblyBuilder.DefineDynamicModule(assemblyName.Name, "Test.Assembly.V2.dll"); + TypeBuilder newTypeBuilder = newModuleBuilder.DefineType("MyType", TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Abstract, typeof(object)); + newTypeBuilder.DefineDefaultConstructor(MethodAttributes.Family); + newTypeBuilder.CreateType(); + newAssemblyBuilder.Save("Test.Assembly.V2.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + ReadOnlyCollection messages = TestUtility.AnalyzeAssemblies("Test.Assembly.dll", "Test.Assembly.V2.dll"); + Assert.AreEqual(1, messages.Count); + Assert.AreEqual("Error AbstractMustNotBeAddedToType: The 'abstract' modifier cannot be added to type '.MyType'.", messages[0].ToString()); + } + + [TestMethod] + public void TestSealedMustNotBeAddedToType_PassUnchanged() + { + AssemblyName assemblyName = new AssemblyName("Test.Assembly"); + AssemblyBuilder referenceAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save); + ModuleBuilder referenceModuleBuilder = referenceAssemblyBuilder.DefineDynamicModule(assemblyName.Name, "Test.Assembly.dll"); + TypeBuilder referenceTypeBuilder = referenceModuleBuilder.DefineType("MyType", TypeAttributes.Class | TypeAttributes.Public, typeof(object)); + referenceTypeBuilder.DefineDefaultConstructor(MethodAttributes.Public); + referenceTypeBuilder.CreateType(); + referenceAssemblyBuilder.Save("Test.Assembly.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + AssemblyBuilder newAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save); + ModuleBuilder newModuleBuilder = newAssemblyBuilder.DefineDynamicModule(assemblyName.Name, "Test.Assembly.V2.dll"); + TypeBuilder newTypeBuilder = newModuleBuilder.DefineType("MyType", TypeAttributes.Class | TypeAttributes.Public, typeof(object)); + newTypeBuilder.DefineDefaultConstructor(MethodAttributes.Public); + newTypeBuilder.CreateType(); + newAssemblyBuilder.Save("Test.Assembly.V2.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + ReadOnlyCollection messages = TestUtility.AnalyzeAssemblies("Test.Assembly.dll", "Test.Assembly.V2.dll"); + Assert.AreEqual(0, messages.Count); + } + + [TestMethod] + public void TestSealedMustNotBeAddedToType_PassRemoved() + { + AssemblyName assemblyName = new AssemblyName("Test.Assembly"); + AssemblyBuilder referenceAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save); + ModuleBuilder referenceModuleBuilder = referenceAssemblyBuilder.DefineDynamicModule(assemblyName.Name, "Test.Assembly.dll"); + TypeBuilder referenceTypeBuilder = referenceModuleBuilder.DefineType("MyType", TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed, typeof(object)); + referenceTypeBuilder.DefineDefaultConstructor(MethodAttributes.Public); + referenceTypeBuilder.CreateType(); + referenceAssemblyBuilder.Save("Test.Assembly.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + AssemblyBuilder newAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save); + ModuleBuilder newModuleBuilder = newAssemblyBuilder.DefineDynamicModule(assemblyName.Name, "Test.Assembly.V2.dll"); + TypeBuilder newTypeBuilder = newModuleBuilder.DefineType("MyType", TypeAttributes.Class | TypeAttributes.Public, typeof(object)); + newTypeBuilder.DefineDefaultConstructor(MethodAttributes.Public); + newTypeBuilder.CreateType(); + newAssemblyBuilder.Save("Test.Assembly.V2.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + ReadOnlyCollection messages = TestUtility.AnalyzeAssemblies("Test.Assembly.dll", "Test.Assembly.V2.dll"); + Assert.AreEqual(0, messages.Count); + } + + [TestMethod] + public void TestSealedMustNotBeAddedToType_PassNotPublic() + { + AssemblyName assemblyName = new AssemblyName("Test.Assembly"); + AssemblyBuilder referenceAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save); + ModuleBuilder referenceModuleBuilder = referenceAssemblyBuilder.DefineDynamicModule(assemblyName.Name, "Test.Assembly.dll"); + TypeBuilder referenceTypeBuilder = referenceModuleBuilder.DefineType("MyType", TypeAttributes.Class | TypeAttributes.NotPublic, typeof(object)); + referenceTypeBuilder.DefineDefaultConstructor(MethodAttributes.Public); + referenceTypeBuilder.CreateType(); + referenceAssemblyBuilder.Save("Test.Assembly.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + AssemblyBuilder newAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save); + ModuleBuilder newModuleBuilder = newAssemblyBuilder.DefineDynamicModule(assemblyName.Name, "Test.Assembly.V2.dll"); + TypeBuilder newTypeBuilder = newModuleBuilder.DefineType("MyType", TypeAttributes.Class | TypeAttributes.NotPublic | TypeAttributes.Sealed, typeof(object)); + newTypeBuilder.DefineDefaultConstructor(MethodAttributes.Public); + newTypeBuilder.CreateType(); + newAssemblyBuilder.Save("Test.Assembly.V2.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + ReadOnlyCollection messages = TestUtility.AnalyzeAssemblies("Test.Assembly.dll", "Test.Assembly.V2.dll"); + Assert.AreEqual(0, messages.Count); + } + + [TestMethod] + public void TestSealedMustNotBeAddedToType_Fail() + { + AssemblyName assemblyName = new AssemblyName("Test.Assembly"); + AssemblyBuilder referenceAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save); + ModuleBuilder referenceModuleBuilder = referenceAssemblyBuilder.DefineDynamicModule(assemblyName.Name, "Test.Assembly.dll"); + TypeBuilder referenceTypeBuilder = referenceModuleBuilder.DefineType("MyType", TypeAttributes.Class | TypeAttributes.Public, typeof(object)); + referenceTypeBuilder.DefineDefaultConstructor(MethodAttributes.Public); + referenceTypeBuilder.CreateType(); + referenceAssemblyBuilder.Save("Test.Assembly.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + AssemblyBuilder newAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save); + ModuleBuilder newModuleBuilder = newAssemblyBuilder.DefineDynamicModule(assemblyName.Name, "Test.Assembly.V2.dll"); + TypeBuilder newTypeBuilder = newModuleBuilder.DefineType("MyType", TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed, typeof(object)); + newTypeBuilder.DefineDefaultConstructor(MethodAttributes.Public); + newTypeBuilder.CreateType(); + newAssemblyBuilder.Save("Test.Assembly.V2.dll", PortableExecutableKinds.ILOnly, ImageFileMachine.AMD64); + + ReadOnlyCollection messages = TestUtility.AnalyzeAssemblies("Test.Assembly.dll", "Test.Assembly.V2.dll"); + Assert.AreEqual(1, messages.Count); + Assert.AreEqual("Error SealedMustNotBeAddedToType: The 'sealed' modifier cannot be added to type '.MyType'.", messages[0].ToString()); + } + } +} diff --git a/CompatibilityChecker.Libary.Tests/TestUtility.cs b/CompatibilityChecker.Libary.Tests/TestUtility.cs new file mode 100644 index 0000000..22928dd --- /dev/null +++ b/CompatibilityChecker.Libary.Tests/TestUtility.cs @@ -0,0 +1,65 @@ +namespace CompatibilityCheckerTests +{ + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Reflection; + using System.Reflection.PortableExecutable; + using System.Security.Cryptography; + using CompatibilityChecker.Library; + using File = System.IO.File; + + internal static class TestUtility + { + public static ReadOnlyCollection AnalyzeAssemblies(string referenceAssemblyFile, string newAssemblyFile) + { + using (PEReader referenceAssembly = new PEReader(File.OpenRead(referenceAssemblyFile))) + { + using (PEReader newAssembly = new PEReader(File.OpenRead(newAssemblyFile))) + { + TestMessageLogger logger = new TestMessageLogger(); + Analyzer analyzer = new Analyzer(referenceAssembly, newAssembly, logger); + analyzer.Run(); + + return logger.RawMessages; + } + } + } + + public static StrongNameKeyPair GenerateStrongNameKeyPair() + { + using (var provider = new RSACryptoServiceProvider(1024, new CspParameters { KeyNumber = 2 })) + { + byte[] keyPairArray = provider.ExportCspBlob(true); + return new StrongNameKeyPair(keyPairArray); + } + } + + internal class TestMessageLogger : IMessageLogger + { + private readonly List _rawMessages = new List(); + private readonly List _messages = new List(); + + public ReadOnlyCollection RawMessages + { + get + { + return _rawMessages.AsReadOnly(); + } + } + + public ReadOnlyCollection Messages + { + get + { + return _messages.AsReadOnly(); + } + } + + public void Report(Message message) + { + _rawMessages.Add(message); + _messages.Add(message.ToString()); + } + } + } +} diff --git a/CompatibilityChecker.Library/CompatibilityChecker.Library.csproj b/CompatibilityChecker.Library/CompatibilityChecker.Library.csproj index 22d5b29..cbdd46a 100644 --- a/CompatibilityChecker.Library/CompatibilityChecker.Library.csproj +++ b/CompatibilityChecker.Library/CompatibilityChecker.Library.csproj @@ -1,8 +1,16 @@  - netstandard2.1 + netstandard2.1 0.2.0 + This project implements a binary compatibility checker for .NET assemblies. The goal of this project is to automate the process of identifying binary- and source-breaking changes between releases of a .NET library. Libraries with string compatibility policies will eventually be able to incorporate this check in the unit tests for the library. The checker will download a declared previous release of the library from NuGet (or potentially from another source), and verify that the latest build of the library is compatible with the binary interfaces defined by the earlier release. + +This library may also feature support for higher levels of compatibility, such as warning users if new overloads of a method could result in an AmbiguousMatchException for users who didn't specify a complete signature when using reflection. + +Diagnostics produced by this checker will be categorized by their likely impact on consumers, and by whether the change constitutes a binary- or source-level breaking change. At this time, there are no plans to implement detection or reporting for changes in runtime semantics. + Apache-2.0 + https://github.com/EraYaN/dotnet-compatibility + tunnelvisionlabs; EraYaN diff --git a/CompatibilityChecker.sln b/CompatibilityChecker.sln index 041bacd..9334218 100644 --- a/CompatibilityChecker.sln +++ b/CompatibilityChecker.sln @@ -6,26 +6,23 @@ MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C355D891-5C1D-4794-9981-9077586D4D39}" ProjectSection(SolutionItems) = preProject LICENSE = LICENSE + NOTICE = NOTICE README.md = README.md RunSettings.runsettings = RunSettings.runsettings EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompatibilityCheckerTests", "CompatibilityCheckerTests\CompatibilityCheckerTests.csproj", "{44681692-0479-4C99-BF40-F310B78D87F0}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CompatibilityChecker.Library", "CompatibilityChecker.Library\CompatibilityChecker.Library.csproj", "{9A4BE2CE-277F-41C5-AB31-E5C6ECFD0EEB}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CompatibilityChecker", "CompatibilityChecker\CompatibilityChecker.csproj", "{F12B242C-9EC3-4ABC-BFC5-50156E4B5CB4}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompatibilityChecker.Libary.Tests", "CompatibilityChecker.Libary.Tests\CompatibilityChecker.Libary.Tests.csproj", "{F46154D5-0FC7-4C2A-AB50-B5D81F73E178}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {44681692-0479-4C99-BF40-F310B78D87F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {44681692-0479-4C99-BF40-F310B78D87F0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {44681692-0479-4C99-BF40-F310B78D87F0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {44681692-0479-4C99-BF40-F310B78D87F0}.Release|Any CPU.Build.0 = Release|Any CPU {9A4BE2CE-277F-41C5-AB31-E5C6ECFD0EEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9A4BE2CE-277F-41C5-AB31-E5C6ECFD0EEB}.Debug|Any CPU.Build.0 = Debug|Any CPU {9A4BE2CE-277F-41C5-AB31-E5C6ECFD0EEB}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -34,6 +31,10 @@ Global {F12B242C-9EC3-4ABC-BFC5-50156E4B5CB4}.Debug|Any CPU.Build.0 = Debug|Any CPU {F12B242C-9EC3-4ABC-BFC5-50156E4B5CB4}.Release|Any CPU.ActiveCfg = Release|Any CPU {F12B242C-9EC3-4ABC-BFC5-50156E4B5CB4}.Release|Any CPU.Build.0 = Release|Any CPU + {F46154D5-0FC7-4C2A-AB50-B5D81F73E178}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F46154D5-0FC7-4C2A-AB50-B5D81F73E178}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F46154D5-0FC7-4C2A-AB50-B5D81F73E178}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F46154D5-0FC7-4C2A-AB50-B5D81F73E178}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CompatibilityChecker/CompatibilityChecker.csproj b/CompatibilityChecker/CompatibilityChecker.csproj index b8bb59a..bbb6ea9 100644 --- a/CompatibilityChecker/CompatibilityChecker.csproj +++ b/CompatibilityChecker/CompatibilityChecker.csproj @@ -10,12 +10,17 @@ This library may also feature support for higher levels of compatibility, such as warning users if new overloads of a method could result in an AmbiguousMatchException for users who didn't specify a complete signature when using reflection. -Diagnostics produced by this checker will be categorized by their likely impact on consumers, and by whether the change constitutes a binary- or source-level breaking change. At this time, there are no plans to implement detection or reporting for changes in runtime semantics. +Diagnostics produced by this checker will be categorized by their likely impact on consumers, and by whether the change constitutes a binary- or source-level breaking change. At this time, there are no plans to implement detection or reporting for changes in runtime semantics. + + Usage: dotnet compat Reference.dll New.dll Apache-2.0 true true - compat-checker + dotnet-compat https://github.com/EraYaN/dotnet-compatibility + CompatibilityChecker + Rack Space Inc.,tunnelvisionlabs,EraYaN + @@ -26,10 +31,7 @@ Diagnostics produced by this checker will be categorized by their likely impact - - - - + diff --git a/CompatibilityChecker/Program.cs b/CompatibilityChecker/Program.cs index 609bdee..3e3a5ae 100644 --- a/CompatibilityChecker/Program.cs +++ b/CompatibilityChecker/Program.cs @@ -27,7 +27,7 @@ public class Options [Option('w', "warnings-only", Required = false, Default = false, HelpText = "Do not raise errors for Azure Pipelines, it also swallows the return code.")] public bool WarningsOnly { get; set; } - [Usage()] + [Usage(ApplicationAlias = "dotnet compat")] public static IEnumerable Examples { get { yield return new Example("Compare versions", new Options { ReferenceAssembly = "Assembly-1.0.0.dll", NewAssembly = "Assembly-1.0.1.dll" }); @@ -40,7 +40,7 @@ public static IEnumerable Examples { private static void Main(string[] args) { - Console.WriteLine("Running CompatibilityCheckerCLI v{0}...", Assembly.GetExecutingAssembly().GetName().Version); + Console.WriteLine("Running dotnet-compat v{0}...", Assembly.GetExecutingAssembly().GetName().Version); var result = CommandLine.Parser.Default.ParseArguments(args) .WithParsed(opts => RunWithOptions(opts)); #if DEBUG diff --git a/CompatibilityChecker/Properties/launchSettings.json b/CompatibilityChecker/Properties/launchSettings.json index fb7433f..8a3af5c 100644 --- a/CompatibilityChecker/Properties/launchSettings.json +++ b/CompatibilityChecker/Properties/launchSettings.json @@ -1,8 +1,7 @@ { "profiles": { "CompatibilityCheckerCoreExample": { - "commandName": "Project", - "commandLineArgs": "\"..\\..\\..\\..\\Emby.Naming_10.4.3.dll\" \"..\\..\\..\\..\\Emby.Naming_error.dll\" --azure-pipelines --warnings-only" + "commandName": "Project" } } } \ No newline at end of file diff --git a/LICENSE b/LICENSE index 3a3c723..6b0b127 100644 --- a/LICENSE +++ b/LICENSE @@ -1,12 +1,203 @@ -Copyright (c) Rackspace, US Inc. All rights reserved. -Licensed under the Apache License, Version 2.0 (the "License"); you may not use -these files except in compliance with the License. You may obtain a copy of the -License at + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ -http://www.apache.org/licenses/LICENSE-2.0 + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. -Unless required by applicable law or agreed to in writing, software distributed -under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -CONDITIONS OF ANY KIND, either express or implied. See the License for the -specific language governing permissions and limitations under the License. diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..4a6ecf2 --- /dev/null +++ b/NOTICE @@ -0,0 +1,5 @@ +dotnet-compatibility (CompatibilityChecker) + +Copyright (c) Rackspace, US Inc. +Copyright (c) tunnelvisionlabs +Copyright (c) 2020 Erwin de Haan diff --git a/README.md b/README.md index 4f36b58..b716bc7 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,27 @@ Diagnostics produced by this checker will be categorized by their likely impact constitutes a binary- or source-level breaking change. At this time, there are no plans to implement detection or reporting for changes in runtime semantics. +## Usage + +Compare versions: + `dotnet compat Assembly-1.0.0.dll Assembly-1.0.1.dll` +Compare versions in Azure Pipelines as CI: + `dotnet compat --azure-pipelines Assembly-1.0.0.dll Assembly-1.0.1.dll` +Compare versions in Azure Pipelines as CI without failing the CI job: + `dotnet compat --azure-pipelines --warnings-only Assembly-1.0.0.dll Assembly-1.0.1.dll` + + -a, --azure-pipelines (Default: false) Include the logging prefixes for Azure Pipelines. + + -w, --warnings-only (Default: false) Do not raise errors for Azure Pipelines, it also swallows the return code. + + --help Display this help screen. + + --version Display version information. + + reference assembly (pos. 0) Required. The reference assembly. + + new assembly (pos. 1) Required. The new assembly. + ## Definitions * **Reference assembly**: The "old" version of the assembly used for compatibility analysis. diff --git a/build-release-package-for-ci.bat b/build-release-package-for-ci.bat deleted file mode 100644 index c18d734..0000000 --- a/build-release-package-for-ci.bat +++ /dev/null @@ -1,13 +0,0 @@ -@ECHO OFF - -dotnet publish -c Release --framework netcoreapp3.1 --self-contained false -r linux-x64 -o CompatibilityCheckerCLI-ci CompatibilityCheckerCLI\CompatibilityCheckerCLI.csproj - -del /Q ".\CompatibilityCheckerCLI-ci.zip" - -pushd CompatibilityCheckerCLI-ci - -zip -r -p "..\CompatibilityCheckerCLI-ci.zip" ".\*" - -popd - -RMDIR /S /Q ".\CompatibilityCheckerCLI-ci" \ No newline at end of file diff --git a/pack.bat b/pack.bat new file mode 100644 index 0000000..335d609 --- /dev/null +++ b/pack.bat @@ -0,0 +1,5 @@ +@ECHO OFF + +dotnet pack -c Release -o ./packed CompatibilityChecker.Library/CompatibilityChecker.Library.csproj + +dotnet pack -c Release -o ./packed CompatibilityChecker/CompatibilityChecker.csproj \ No newline at end of file