diff --git a/.gitignore b/.gitignore index ec2c6cdd8..8b459c6eb 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ benchmarks/data/results/*.md _ReSharper.Caches/ .idea .logs +.packages diff --git a/Directory.Build.props b/Directory.Build.props index 3101e6b82..85e1601a4 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -16,11 +16,16 @@ Coding in a pure DI paradigm without frameworks! $(BasePackageId) Copyright (C) $([System.DateTime]::Now.Year) Nikolay Pianikov - 4.3 - 4.3.1 - obj\roslyn$(AnalyzerRoslynVersion) - bin\roslyn$(AnalyzerRoslynVersion) true + + + + 4.8 + 4.8.0 + + ROSLYN4_8_OR_GREATER;ROSLYN4_3_OR_GREATER + $(DefineConstants);$(RolsynVersions) diff --git a/Pure.DI.sln.DotSettings b/Pure.DI.sln.DotSettings index b26dd8e11..d5059bcb0 100644 --- a/Pure.DI.sln.DotSettings +++ b/Pure.DI.sln.DotSettings @@ -291,6 +291,7 @@ True True True + True True True True diff --git a/build/GeneratorTarget.cs b/build/GeneratorTarget.cs index a0cdfda5b..8be5c26b8 100644 --- a/build/GeneratorTarget.cs +++ b/build/GeneratorTarget.cs @@ -8,13 +8,16 @@ namespace Build; using System.IO.Compression; -using NuGet.Versioning; internal class GeneratorTarget( Settings settings, Commands commands) : IInitializable, ITarget { + private const string PackagesDir = ".packages"; + + private string PackageName => $"Pure.DI.{settings.Version}.nupkg"; + public Task InitializeAsync() => commands.Register( this, "Builds and tests generator", @@ -27,26 +30,34 @@ public Task RunAsync(CancellationToken cancellationToken) // Generator package var generatorProjectDirectory = Path.Combine("src", "Pure.DI"); var generatorPackages = settings.CodeAnalysis - .Select(codeAnalysis => CreateGeneratorPackage(settings.Version, codeAnalysis, generatorProjectDirectory)); + .Select(codeAnalysis => CreateGeneratorPackage(codeAnalysis, generatorProjectDirectory)) + .ToList(); return Task.FromResult( new Package( - Path.GetFullPath(MergeGeneratorPackages(settings.Version, generatorPackages, generatorProjectDirectory)), + Path.GetFullPath(MergeGeneratorPackages(generatorPackages, generatorProjectDirectory)), true)); } - private string CreateGeneratorPackage(NuGetVersion packageVersion, CodeAnalysis codeAnalysis, string projectDirectory) + private string CreateGeneratorPackage(CodeAnalysis codeAnalysis, string projectDirectory) { var analyzerRoslynPackageVersion = codeAnalysis.AnalyzerRoslynPackageVersion; var analyzerRoslynVersion = new Version(analyzerRoslynPackageVersion.Major, analyzerRoslynPackageVersion.Minor); Info($"Build package for Roslyn {analyzerRoslynVersion}."); + var rolsynVersions = string.Join( + ';', + settings.CodeAnalysis + .Where(i => i.AnalyzerRoslynPackageVersion <= codeAnalysis.AnalyzerRoslynPackageVersion) + .Select(i => $"ROSLYN{i.AnalyzerRoslynPackageVersion.Major}_{i.AnalyzerRoslynPackageVersion.Minor}_OR_GREATER")); + List<(string, string)> props = [ ("configuration", settings.Configuration), - ("version", packageVersion.ToString()), + ("version", settings.Version.ToString()), ("AnalyzerRoslynVersion", analyzerRoslynVersion.ToString()), - ("AnalyzerRoslynPackageVersion", analyzerRoslynPackageVersion.ToString()) + ("AnalyzerRoslynPackageVersion", analyzerRoslynPackageVersion.ToString()), + ("RolsynVersions", $"\"{rolsynVersions}\""), ]; if (settings.BuildServer) @@ -54,10 +65,20 @@ private string CreateGeneratorPackage(NuGetVersion packageVersion, CodeAnalysis props.Add(("CI", "true")); } - new MSBuild() + var bin = Path.Combine(projectDirectory, "bin"); + if (Directory.Exists(bin)) + { + Directory.Delete(bin, true); + } + + var obj = Path.Combine(projectDirectory, "obj"); + if (Directory.Exists(obj)) + { + Directory.Delete(obj, true); + } + + new DotNetBuild() .WithShortName($"Building {codeAnalysis.AnalyzerRoslynPackageVersion}") - .WithTarget("clean;rebuild") - .WithRestore(true) .WithProps(props) .Build() .Succeed(); @@ -73,6 +94,8 @@ private string CreateGeneratorPackage(NuGetVersion packageVersion, CodeAnalysis WriteLine(testResult.ToString(), Color.Details); testResult.Succeed(); + var packagePath = Path.Combine(PackagesDir, analyzerRoslynVersion.ToString()); + new DotNetPack() .WithShortName($"Packing {codeAnalysis.AnalyzerRoslynPackageVersion}") .WithProps(props) @@ -80,20 +103,16 @@ private string CreateGeneratorPackage(NuGetVersion packageVersion, CodeAnalysis .WithNoBuild(true) .WithNoLogo(true) .WithProject(Path.Combine(projectDirectory, "Pure.DI.csproj")) + .WithOutput(Path.Combine(projectDirectory, packagePath)) .Build() .Succeed(); - return Path.Combine( - projectDirectory, - "bin", - $"roslyn{analyzerRoslynVersion}", - settings.Configuration, - $"Pure.DI.{packageVersion.ToString()}.nupkg"); + return Path.Combine(projectDirectory, packagePath, PackageName); } - private string MergeGeneratorPackages(NuGetVersion packageVersion, IEnumerable mergingPackages, string projectDirectory) + private string MergeGeneratorPackages(IEnumerable mergingPackages, string projectDirectory) { - var targetPackage = Path.GetFullPath(Path.Combine(projectDirectory, "bin", settings.Configuration, $"Pure.DI.{packageVersion}.nupkg")); + var targetPackage = Path.GetFullPath(Path.Combine(projectDirectory, PackagesDir, PackageName)); Info($"Creating NuGet package {targetPackage}"); var targetDir = Path.GetDirectoryName(targetPackage); if (!string.IsNullOrWhiteSpace(targetDir)) diff --git a/build/Settings.cs b/build/Settings.cs index 93d53825b..0a5d86544 100644 --- a/build/Settings.cs +++ b/build/Settings.cs @@ -25,6 +25,7 @@ internal class Settings( public ImmutableArray CodeAnalysis { get; } = [ + new CodeAnalysis(new Version(4, 8, 0)), new CodeAnalysis(new Version(4, 3, 1)) ];