From 907bd55ed12abf6324fd075955168c3f38a20667 Mon Sep 17 00:00:00 2001 From: Andreas Gullberg Larsen Date: Sat, 1 Oct 2022 23:32:19 +0200 Subject: [PATCH] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Upgrade=20tests=20and=20sa?= =?UTF-8?q?mple=20app=20to=20net6.0,=20upgrade=20all=20nugets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AssignAll.Test/AssignAll.Test.csproj | 15 +++-- AssignAll/AssignAll/AssignAll.csproj | 6 +- RoslynAnalyzers.sln | 12 ++-- SampleConsoleApp/.gitattributes | 4 -- SampleConsoleApp/App.config | 7 --- SampleConsoleApp/Program.cs | 32 ----------- SampleConsoleApp/Properties/AssemblyInfo.cs | 39 ------------- SampleConsoleApp/SampleConsoleApp.csproj | 55 ------------------- SampleConsoleApp/SampleConsoleApp.sln | 30 ---------- .../.editorconfig | 0 .../Example001_TopLevelStatements.Program.cs | 32 +++++++++++ .../Example002_FileScopedNamespace.cs | 25 +++++++++ .../Example003_RegularNamespaceDeclaration.cs | 26 +++++++++ Samples.ConsoleNet6/Foo.cs | 10 ++++ Samples.ConsoleNet6/GlobalUsings.cs | 3 + .../Samples.ConsoleNet6.csproj | 18 ++++++ 16 files changed, 132 insertions(+), 182 deletions(-) delete mode 100644 SampleConsoleApp/.gitattributes delete mode 100644 SampleConsoleApp/App.config delete mode 100644 SampleConsoleApp/Program.cs delete mode 100644 SampleConsoleApp/Properties/AssemblyInfo.cs delete mode 100644 SampleConsoleApp/SampleConsoleApp.csproj delete mode 100644 SampleConsoleApp/SampleConsoleApp.sln rename {SampleConsoleApp => Samples.ConsoleNet6}/.editorconfig (100%) create mode 100644 Samples.ConsoleNet6/Example001_TopLevelStatements.Program.cs create mode 100644 Samples.ConsoleNet6/Example002_FileScopedNamespace.cs create mode 100644 Samples.ConsoleNet6/Example003_RegularNamespaceDeclaration.cs create mode 100644 Samples.ConsoleNet6/Foo.cs create mode 100644 Samples.ConsoleNet6/GlobalUsings.cs create mode 100644 Samples.ConsoleNet6/Samples.ConsoleNet6.csproj diff --git a/AssignAll/AssignAll.Test/AssignAll.Test.csproj b/AssignAll/AssignAll.Test/AssignAll.Test.csproj index a29adf6..fad8b64 100644 --- a/AssignAll/AssignAll.Test/AssignAll.Test.csproj +++ b/AssignAll/AssignAll.Test/AssignAll.Test.csproj @@ -1,18 +1,21 @@  - netcoreapp2.1 + net6.0 - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - diff --git a/AssignAll/AssignAll/AssignAll.csproj b/AssignAll/AssignAll/AssignAll.csproj index aadc022..8b4eb9f 100644 --- a/AssignAll/AssignAll/AssignAll.csproj +++ b/AssignAll/AssignAll/AssignAll.csproj @@ -26,12 +26,12 @@ - + - - + + diff --git a/RoslynAnalyzers.sln b/RoslynAnalyzers.sln index c93d344..3e4d490 100644 --- a/RoslynAnalyzers.sln +++ b/RoslynAnalyzers.sln @@ -9,14 +9,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssignAll.Test", "AssignAll EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssignAll.Vsix", "AssignAll\AssignAll.Vsix\AssignAll.Vsix.csproj", "{B176E12E-F1EB-4776-9D13-3F4E9064E08D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleConsoleApp", "SampleConsoleApp\SampleConsoleApp.csproj", "{50FFCAEA-07D5-493E-8904-DEE6A7D9BE0D}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Files", "Files", "{D4A0A564-543B-4220-8194-F1E7447A4E2D}" ProjectSection(SolutionItems) = preProject appveyor.yml = appveyor.yml README.md = README.md EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.ConsoleNet6", "Samples.ConsoleNet6\Samples.ConsoleNet6.csproj", "{4A5DE914-8128-4CA6-87CE-0B9A9F2B91FE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -35,10 +35,10 @@ Global {B176E12E-F1EB-4776-9D13-3F4E9064E08D}.Debug|Any CPU.Build.0 = Debug|Any CPU {B176E12E-F1EB-4776-9D13-3F4E9064E08D}.Release|Any CPU.ActiveCfg = Release|Any CPU {B176E12E-F1EB-4776-9D13-3F4E9064E08D}.Release|Any CPU.Build.0 = Release|Any CPU - {50FFCAEA-07D5-493E-8904-DEE6A7D9BE0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {50FFCAEA-07D5-493E-8904-DEE6A7D9BE0D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {50FFCAEA-07D5-493E-8904-DEE6A7D9BE0D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {50FFCAEA-07D5-493E-8904-DEE6A7D9BE0D}.Release|Any CPU.Build.0 = Release|Any CPU + {4A5DE914-8128-4CA6-87CE-0B9A9F2B91FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4A5DE914-8128-4CA6-87CE-0B9A9F2B91FE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4A5DE914-8128-4CA6-87CE-0B9A9F2B91FE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4A5DE914-8128-4CA6-87CE-0B9A9F2B91FE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SampleConsoleApp/.gitattributes b/SampleConsoleApp/.gitattributes deleted file mode 100644 index 6a13d61..0000000 --- a/SampleConsoleApp/.gitattributes +++ /dev/null @@ -1,4 +0,0 @@ -# Sample code needs to be in CRLF, because Roslyn code fix honors .editorconfig that is also set to CRLF. -# Otherwise we could get a mix of LF and CRLF and the code fix tests can fail when checking out with gitconfig core.autocrlf = input, -# which is exactly what AppVeyor build server uses. -* text eol=crlf \ No newline at end of file diff --git a/SampleConsoleApp/App.config b/SampleConsoleApp/App.config deleted file mode 100644 index 8609e96..0000000 --- a/SampleConsoleApp/App.config +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/SampleConsoleApp/Program.cs b/SampleConsoleApp/Program.cs deleted file mode 100644 index 4684024..0000000 --- a/SampleConsoleApp/Program.cs +++ /dev/null @@ -1,32 +0,0 @@ -// ReSharper disable All -namespace SampleConsoleApp -{ - internal static class Program - { - private static void Main() - { - // AssignAll enable - var foo = new Foo - { - // Commented assignments after opening brace. - // PropCommented1 = 1, - - // Assigned property, OK'ed by analyzer - PropAssigned = 1, - - // Commented assignments just before closing brace - //PropCommented2 = , - // PropCommented3=, - }; - } - - private class Foo - { - public int PropAssigned { get; set; } - public int PropCommented1 { get; set; } - public int PropCommented2 { get; set; } - public int PropCommented3 { get; set; } - public int PropUnassigned { get; set; } - } - } -} \ No newline at end of file diff --git a/SampleConsoleApp/Properties/AssemblyInfo.cs b/SampleConsoleApp/Properties/AssemblyInfo.cs deleted file mode 100644 index 28534bb..0000000 --- a/SampleConsoleApp/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. - -[assembly: AssemblyTitle("SampleConsoleApp")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("SampleConsoleApp")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. - -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM - -[assembly: Guid("50ffcaea-07d5-493e-8904-dee6a7d9be0d")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] - -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/SampleConsoleApp/SampleConsoleApp.csproj b/SampleConsoleApp/SampleConsoleApp.csproj deleted file mode 100644 index f15d281..0000000 --- a/SampleConsoleApp/SampleConsoleApp.csproj +++ /dev/null @@ -1,55 +0,0 @@ - - - - - Debug - AnyCPU - {50FFCAEA-07D5-493E-8904-DEE6A7D9BE0D} - Exe - SampleConsoleApp - SampleConsoleApp - v4.6.2 - 512 - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/SampleConsoleApp/SampleConsoleApp.sln b/SampleConsoleApp/SampleConsoleApp.sln deleted file mode 100644 index 99d52f8..0000000 --- a/SampleConsoleApp/SampleConsoleApp.sln +++ /dev/null @@ -1,30 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29613.14 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleConsoleApp", "SampleConsoleApp.csproj", "{50FFCAEA-07D5-493E-8904-DEE6A7D9BE0D}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8239EDD0-A275-439D-A397-766646674A36}" - ProjectSection(SolutionItems) = preProject - .editorconfig = .editorconfig - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {50FFCAEA-07D5-493E-8904-DEE6A7D9BE0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {50FFCAEA-07D5-493E-8904-DEE6A7D9BE0D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {50FFCAEA-07D5-493E-8904-DEE6A7D9BE0D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {50FFCAEA-07D5-493E-8904-DEE6A7D9BE0D}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {5573E1D8-3018-4243-AF62-4B07A6226905} - EndGlobalSection -EndGlobal diff --git a/SampleConsoleApp/.editorconfig b/Samples.ConsoleNet6/.editorconfig similarity index 100% rename from SampleConsoleApp/.editorconfig rename to Samples.ConsoleNet6/.editorconfig diff --git a/Samples.ConsoleNet6/Example001_TopLevelStatements.Program.cs b/Samples.ConsoleNet6/Example001_TopLevelStatements.Program.cs new file mode 100644 index 0000000..bac6d09 --- /dev/null +++ b/Samples.ConsoleNet6/Example001_TopLevelStatements.Program.cs @@ -0,0 +1,32 @@ +// AssignAll enable + +// EXAMPLE 001 - Top level statements in the single main file, typically Program.cs. +// https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/top-level-statements +// +// This should give analyzer error: +// Missing member assignments in object initializer for type 'Foo'. Properties: PropUnassigned +var foo = new Foo +{ + // Commented assignments after opening brace. OK by analyzer. + // PropCommented1 = 1, + + // Assigned property. OK by analyzer + PropAssigned = 1, + + // Commented assignments just before closing brace. OK by analyzer. + //PropCommented2 = , + // PropCommented3=, +}; + +Console.WriteLine($"Hello, {foo}!"); + +// Add methods and nested types available to top level statements via a partial Program class. +// ReSharper disable once UnusedType.Global +public static partial class Program +{ + private class Foo2 + { + public int PropInt { get; set; } + public string PropString { get; set; } + } +} diff --git a/Samples.ConsoleNet6/Example002_FileScopedNamespace.cs b/Samples.ConsoleNet6/Example002_FileScopedNamespace.cs new file mode 100644 index 0000000..fa6a0ba --- /dev/null +++ b/Samples.ConsoleNet6/Example002_FileScopedNamespace.cs @@ -0,0 +1,25 @@ +// AssignAll enable +// EXAMPLE 002 - File-scoped namespaces. +// https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/file-scoped-namespaces +namespace Samples.ConsoleNet6; + +public static class Example002_FileScopedNamespace +{ + public static void Irrelevant() + { + // This should give analyzer error: + // Missing member assignments in object initializer for type 'Foo'. Properties: PropUnassigned + var foo = new Foo + { + // Commented assignments after opening brace. + // PropCommented1 = 1, + + // Assigned property, OK by analyzer + PropAssigned = 1, + + // Commented assignments just before closing brace + //PropCommented2 = , + // PropCommented3=, + }; + } +} diff --git a/Samples.ConsoleNet6/Example003_RegularNamespaceDeclaration.cs b/Samples.ConsoleNet6/Example003_RegularNamespaceDeclaration.cs new file mode 100644 index 0000000..afd3f35 --- /dev/null +++ b/Samples.ConsoleNet6/Example003_RegularNamespaceDeclaration.cs @@ -0,0 +1,26 @@ +// AssignAll enable +// EXAMPLE 003 - Regular namespace declarations with a body. +// https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/file-scoped-namespaces +namespace Samples.ConsoleNet6 +{ + public static class Example003_RegularNamespaceDeclaration + { + public static void Irrelevant() + { + // This should give analyzer error: + // Missing member assignments in object initializer for type 'Foo'. Properties: PropUnassigned + var foo = new Foo + { + // Commented assignments after opening brace. + // PropCommented1 = 1, + + // Assigned property, OK by analyzer + PropAssigned = 1, + + // Commented assignments just before closing brace + //PropCommented2 = , + // PropCommented3=, + }; + } + } +} diff --git a/Samples.ConsoleNet6/Foo.cs b/Samples.ConsoleNet6/Foo.cs new file mode 100644 index 0000000..1caa540 --- /dev/null +++ b/Samples.ConsoleNet6/Foo.cs @@ -0,0 +1,10 @@ +namespace Samples.ConsoleNet6; + +internal class Foo +{ + public int PropAssigned { get; set; } + public int PropCommented1 { get; set; } + public int PropCommented2 { get; set; } + public int PropCommented3 { get; set; } + public int PropUnassigned { get; set; } +} \ No newline at end of file diff --git a/Samples.ConsoleNet6/GlobalUsings.cs b/Samples.ConsoleNet6/GlobalUsings.cs new file mode 100644 index 0000000..0caaa3d --- /dev/null +++ b/Samples.ConsoleNet6/GlobalUsings.cs @@ -0,0 +1,3 @@ +// Global using directives + +global using Samples.ConsoleNet6; \ No newline at end of file diff --git a/Samples.ConsoleNet6/Samples.ConsoleNet6.csproj b/Samples.ConsoleNet6/Samples.ConsoleNet6.csproj new file mode 100644 index 0000000..2f22772 --- /dev/null +++ b/Samples.ConsoleNet6/Samples.ConsoleNet6.csproj @@ -0,0 +1,18 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + + + +