diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 256b9cf..c10f068 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -68,7 +68,7 @@ jobs: - name: Pack if: success() && matrix.os == 'ubuntu-latest' - run: dotnet pack --no-restore --no-build --include-symbols -p:SymbolPackageFormat=snupkg -o $GITHUB_WORKSPACE/packages + run: dotnet pack --no-restore --no-build --configuration Debug --include-symbols -p:SymbolPackageFormat=snupkg -o $GITHUB_WORKSPACE/packages - uses: actions/upload-artifact@v3 name: 'Upload Packages' @@ -82,4 +82,4 @@ jobs: if: success() && matrix.os == 'ubuntu-latest' with: name: artifacts - path: src/dotnet-affected/bin/Debug/net7.0/ + path: src/dotnet-affected/bin/Debug/net8.0/ diff --git a/Directory.Build.props b/Directory.Build.props index d85648f..52a7e1e 100755 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@  - net7.0;net6.0;netcoreapp3.1 + net6.0;net7.0;net8.0 9.0 diff --git a/Directory.Packages.props b/Directory.Packages.props index 1674e21..0f856cb 100755 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -16,14 +16,6 @@ - - - - - - - - @@ -40,4 +32,12 @@ + + + + + + + + diff --git a/eng/install-sdk.ps1 b/eng/install-sdk.ps1 index 0df33b8..83570f2 100644 --- a/eng/install-sdk.ps1 +++ b/eng/install-sdk.ps1 @@ -10,5 +10,5 @@ $globalJsonFile = "$PSScriptRoot\..\global.json" $dotnetInstallDir = "$PSScriptRoot\.dotnet" . $installScript -InstallDir $dotnetInstallDir -JSonFile $globalJsonFile +. $installScript -InstallDir $dotnetInstallDir -Channel 7.0 . $installScript -InstallDir $dotnetInstallDir -Channel 6.0 -. $installScript -InstallDir $dotnetInstallDir -Channel 3.1 diff --git a/eng/install-sdk.sh b/eng/install-sdk.sh index 53fac60..29e5589 100755 --- a/eng/install-sdk.sh +++ b/eng/install-sdk.sh @@ -14,5 +14,5 @@ global_json_file="$(dirname "$0")/../global.json" dotnet_install_dir="$(dirname "$0")/.dotnet" "$install_script" --install-dir "$dotnet_install_dir" --jsonfile "$global_json_file" +"$install_script" --install-dir "$dotnet_install_dir" --channel 7.0 "$install_script" --install-dir "$dotnet_install_dir" --channel 6.0 -"$install_script" --install-dir "$dotnet_install_dir" --channel 3.1 diff --git a/global.json b/global.json index 41b0c29..5e66865 100755 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "7.0.101", + "version": "8.0.100", "allowPrerelease": true } } diff --git a/src/DotnetAffected.Core/AffectedExecutor.cs b/src/DotnetAffected.Core/AffectedExecutor.cs index f7d68ef..9fc0050 100644 --- a/src/DotnetAffected.Core/AffectedExecutor.cs +++ b/src/DotnetAffected.Core/AffectedExecutor.cs @@ -38,8 +38,6 @@ public AffectedExecutor( } /// - public AffectedSummary Execute() => GitChangesProvider.MsBuildFileSystemSupported - ? new AffectedProcessor().Process(_context) - : new AffectedProcessorLegacy().Process(_context); + public AffectedSummary Execute() => new AffectedProcessor().Process(_context); } } diff --git a/src/DotnetAffected.Core/GitChangesProvider.cs b/src/DotnetAffected.Core/GitChangesProvider.cs index c134089..e36277f 100644 --- a/src/DotnetAffected.Core/GitChangesProvider.cs +++ b/src/DotnetAffected.Core/GitChangesProvider.cs @@ -1,16 +1,11 @@ using DotnetAffected.Abstractions; using DotnetAffected.Core.FileSystem; using LibGit2Sharp; -using Microsoft.Build.Construction; -using Microsoft.Build.Definition; using Microsoft.Build.Evaluation; using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; -using System.Text; -using System.Xml; namespace DotnetAffected.Core { @@ -21,22 +16,6 @@ public class GitChangesProvider : IChangesProvider { internal static readonly bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); - private static readonly Lazy ResolveMsBuildFileSystemSupported = new Lazy(() => - { - var versionInfo = FileVersionInfo.GetVersionInfo(typeof(Project).Assembly.Location); - if (versionInfo.FileMajorPart > 16) - return true; - if (versionInfo.FileMajorPart < 16) - return false; - return versionInfo.FileMinorPart >= 10; - }); - - /// - /// When true, the build system supports virtual filesystem which means nested Directory.Packages.props files - /// are supported in central package management. - /// - public static bool MsBuildFileSystemSupported => ResolveMsBuildFileSystemSupported.Value; - /// public IEnumerable GetChangedFiles(string directory, string from, string to) { @@ -52,7 +31,7 @@ public IEnumerable GetChangedFiles(string directory, string from, string bool fallbackToHead) { var project = LoadProject(directory, pathToFile, commitRef, fallbackToHead); - if (project is null && MsBuildFileSystemSupported) + if (project is null) { var fi = new FileInfo(pathToFile); var parent = fi.Directory?.Parent?.FullName; @@ -67,9 +46,7 @@ public IEnumerable GetChangedFiles(string directory, string from, string /// public Project? LoadProject(string directory, string pathToFile, string? commitRef, bool fallbackToHead) { - return MsBuildFileSystemSupported - ? LoadProjectCore(directory, pathToFile, commitRef, fallbackToHead) - : LoadProjectLegacy(directory, pathToFile, commitRef, fallbackToHead); + return LoadProjectCore(directory, pathToFile, commitRef, fallbackToHead); } private Project? LoadProjectCore(string directory, string pathToFile, string? commitRef, bool fallbackToHead) @@ -96,64 +73,6 @@ public IEnumerable GetChangedFiles(string directory, string from, string return fs.FileExists(pathToFile) ? fs.CreateProjectAndEagerLoadChildren(pathToFile) : null; } - private Project? LoadProjectLegacy(string directory, string pathToFile, string? commitRef, bool fallbackToHead) - { - Commit? commit; - - using var repository = new Repository(directory); - - if (string.IsNullOrWhiteSpace(commitRef)) - commit = fallbackToHead ? repository.Head.Tip : null; - else - commit = GetCommitOrThrow(repository, commitRef); - - Stream GenerateStreamFromString(string s) - { - var stream = new MemoryStream(); - var writer = new StreamWriter(stream); - writer.Write(s); - writer.Flush(); - stream.Position = 0; - return stream; - } - - var projectCollection = new ProjectCollection(); - - if (commit is null) - { - var path = Path.Combine(directory, pathToFile); - if (!File.Exists(path)) return null; - - using var reader = new XmlTextReader(GenerateStreamFromString(File.ReadAllText(path))); - var projectRootElement = ProjectRootElement.Create(reader); - projectRootElement.FullPath = pathToFile; - return Project.FromProjectRootElement(projectRootElement, new ProjectOptions - { - LoadSettings = ProjectLoadSettings.Default, ProjectCollection = projectCollection, - }); - } - else - { - var path = IsWindows - ? Path.GetRelativePath(directory, pathToFile) - .Replace('\\', '/') - : Path.GetRelativePath(directory, pathToFile); - var treeEntry = commit[path]; - if (treeEntry == null) return null; - - var blob = (Blob)treeEntry.Target; - - using var content = new StreamReader(blob.GetContentStream(), Encoding.UTF8); - using var reader = new XmlTextReader(GenerateStreamFromString(content.ReadToEnd())); - var projectRootElement = ProjectRootElement.Create(reader); - projectRootElement.FullPath = pathToFile; - return Project.FromProjectRootElement(projectRootElement, new ProjectOptions - { - LoadSettings = ProjectLoadSettings.Default, ProjectCollection = projectCollection, - }); - } - } - private static (Commit? From, Commit To) ParseRevisionRanges( Repository repository, string from, diff --git a/src/DotnetAffected.Core/Processor/AffectedProcessorLegacy.cs b/src/DotnetAffected.Core/Processor/AffectedProcessorLegacy.cs deleted file mode 100644 index 03dadb6..0000000 --- a/src/DotnetAffected.Core/Processor/AffectedProcessorLegacy.cs +++ /dev/null @@ -1,80 +0,0 @@ -using DotnetAffected.Abstractions; -using Microsoft.Build.Graph; -using System.Collections.Generic; -using System.Linq; - -namespace DotnetAffected.Core.Processor -{ - /// - /// - /// Discovery is implemented using a custom, limited, project evaluation strategy.
- /// Based on files changed, specific logic is applied, on limited known files, to discover change metadata such as - /// packages changed. - /// - /// The legacy processor compliments where netcore 3.1 is used as - /// does not support it. - ///
- internal class AffectedProcessorLegacy : AffectedProcessorBase - { - - /// - protected override PackageChange[] DiscoverPackageChanges(AffectedProcessorContext context) - { - return FindChangedNugetPackages(context).ToArray(); - } - - /// - protected override ProjectGraphNode[] DiscoverAffectedProjects(AffectedProcessorContext context) - { - return DetermineAffectedProjectsLegacy(context).ToArray(); - } - - private ProjectGraphNode[] DetermineAffectedProjectsLegacy(AffectedProcessorContext context) - { - // Find projects referencing NuGet packages that changed - var changedPackageNames = context.ChangedPackages.Select(p => p.Name); - var projectsAffectedByNugetPackages = context.Graph - .FindNodesReferencingNuGetPackages(changedPackageNames) - .ToList(); - - // Combine changed projects with projects affected by nuget changes - var changedAndNugetAffected = context.ChangedProjects - .Concat(projectsAffectedByNugetPackages) - .Deduplicate(); - - // Find projects that depend on the changed projects + projects affected by nuget - var output = changedAndNugetAffected - .FindReferencingProjects() - .Concat(projectsAffectedByNugetPackages) - .Deduplicate() - .ToArray(); - - return output; - } - - private IEnumerable FindChangedNugetPackages(AffectedProcessorContext context) { - // Try to find a Directory.Packages.props file in the list of changed files - // We try to take the deepest file, assuming they import up - var packagePropsPath = context.ChangedFiles - .Where(f => f.EndsWith("Directory.Packages.props")) - .OrderByDescending(p => p.Length) - .Take(1) - .FirstOrDefault(); - - if (packagePropsPath is null) - return Enumerable.Empty(); - - var fromFile = context.ChangesProvider.LoadDirectoryPackagePropsProject(context.RepositoryPath, packagePropsPath, context.FromRef, false); - var toFile = context.ChangesProvider.LoadDirectoryPackagePropsProject(context.RepositoryPath, packagePropsPath, context.ToRef, true); - - // Parse props files into package and version dictionary - var fromPackages = NugetHelper.ParseDirectoryPackageProps(fromFile); - var toPackages = NugetHelper.ParseDirectoryPackageProps(toFile); - - // Compare both dictionaries - return NugetHelper.TryFindDiffPackageDictionaries(fromPackages, toPackages, out var packageChanges) - ? packageChanges - : Enumerable.Empty(); - } - } -} diff --git a/src/DotnetAffected.Core/ProjectFactory.cs b/src/DotnetAffected.Core/ProjectFactory.cs index b61ffd2..71b84ef 100644 --- a/src/DotnetAffected.Core/ProjectFactory.cs +++ b/src/DotnetAffected.Core/ProjectFactory.cs @@ -42,7 +42,7 @@ public Project CreateProject(string projectRootElementFilePath) var loaded = ProjectCollection.GetLoadedProjects(projectRootElementFilePath); if (loaded.Any()) return loaded.Single(); - + var projectRootElement = CreateProjectRootElement(projectRootElementFilePath); return Project .FromProjectRootElement(projectRootElement, new ProjectOptions diff --git a/src/DotnetAffected.Tasks/README.md b/src/DotnetAffected.Tasks/README.md index ae73039..d1c443b 100644 --- a/src/DotnetAffected.Tasks/README.md +++ b/src/DotnetAffected.Tasks/README.md @@ -254,7 +254,7 @@ as they don't actually build projects, they just delegate the build to a differe own configuration. However, `DotnetAffected.Tasks` itself contains code to execute in build time, which -support TFMs `netcore3.1`, `net6.0` and `net7.0`. +support TFMs `net6.0`, `net7.0` and `net8.0`. The TFM must be known so the proper TFM facing assembly is used. @@ -265,6 +265,7 @@ In most cases it is automatically resolved using the following logic: - If >= `17.0.0` it will resolve to `net6.0` - Else if >= `16.11.0` it will resolve to `net5.0` - Else it will resolve to `netcoreapp3.1` + - TODO If you have issues, you can override the logic by specifically setting the ``. @@ -278,5 +279,5 @@ If you have issues, you can override the logic by specifically setting the ` `DotnetAffected.Tasks` provides MSBuild integration using `DotnetAffected.Core` under the hood. -`DotnetAffected.Core` support TFMs `netcore3.1`, `net6.0` and `net7.0`. +`DotnetAffected.Core` support TFMs `net6.0`, `net7.0` and `net8.0`. diff --git a/src/DotnetAffected.Tasks/Sdk/Sdk.props b/src/DotnetAffected.Tasks/Sdk/Sdk.props index 05fefe3..a7dab5f 100644 --- a/src/DotnetAffected.Tasks/Sdk/Sdk.props +++ b/src/DotnetAffected.Tasks/Sdk/Sdk.props @@ -7,10 +7,10 @@ @@ -19,7 +19,6 @@ <_DotnetAffectedTargetFramework Condition="'$(_DotnetAffectedTargetFramework)' == ''">$(MicrosoftNETBuildTasksTFM) <_DotnetAffectedTargetFramework Condition="'$(_DotnetAffectedTargetFramework)' == '' And $([MSBuild]::VersionGreaterThanOrEquals('$(MSBuildVersion)', '17.0.0'))">net6.0 <_DotnetAffectedTargetFramework Condition="'$(_DotnetAffectedTargetFramework)' == '' And $([MSBuild]::VersionGreaterThanOrEquals('$(MSBuildVersion)', '16.11.0'))">net5.0 - <_DotnetAffectedTargetFramework Condition="'$(_DotnetAffectedTargetFramework)' == ''">netcoreapp3.1 $(_DotnetAffectedTargetFramework) diff --git a/src/dotnet-affected/dotnet-affected.csproj b/src/dotnet-affected/dotnet-affected.csproj index 475e114..4180d7f 100755 --- a/src/dotnet-affected/dotnet-affected.csproj +++ b/src/dotnet-affected/dotnet-affected.csproj @@ -13,7 +13,6 @@ - diff --git a/test/DotnetAffected.Core.Tests/CentralPackageManagementDetectionNestedTests.cs b/test/DotnetAffected.Core.Tests/CentralPackageManagementDetectionNestedTests.cs index 70bcd26..afb9c8e 100644 --- a/test/DotnetAffected.Core.Tests/CentralPackageManagementDetectionNestedTests.cs +++ b/test/DotnetAffected.Core.Tests/CentralPackageManagementDetectionNestedTests.cs @@ -93,23 +93,13 @@ public void When_directory_packages_props_updates_dependant_projects_should_be_a var someLibChanges = AffectedSummary.ChangedPackages.Single(c => c.Name == packageName); var otherLibChanges = AffectedSummary.ChangedPackages.Single(c => c.Name == otherPackageName); -#if (NET5_0_OR_GREATER) Assert.Equal("3.0.0", someLibChanges.OldVersions.Single()); Assert.Equal("2.5.0", otherLibChanges.OldVersions.Single()); Assert.Equal("2.0.0", someLibChanges.NewVersions.Single()); Assert.Equal("3.5.0", otherLibChanges.NewVersions.Single()); -#else - Assert.Equal("3.0.0", someLibChanges.OldVersions.Single()); - Assert.Empty(otherLibChanges.OldVersions); - - Assert.Equal("2.0.0", someLibChanges.NewVersions.Single()); - Assert.Equal("3.5.0", otherLibChanges.NewVersions.Single()); -#endif } -#if (NET5_0_OR_GREATER) - [Fact] public void When_directory_packages_props_changes_without_dependant_projects_nothing_should_be_affected() { @@ -306,7 +296,5 @@ public void With_nested_conditional_props_file_projects_should_still_be_affected Assert.Equal("1.0.0", changedPackage.OldVersions.Single()); Assert.Equal("1.1.0", changedPackage.NewVersions.Single()); } - -#endif // NET5_0_OR_GREATER } } diff --git a/test/DotnetAffected.Tasks.Tests/Extensions/TemporaryRepositoryExtensions.cs b/test/DotnetAffected.Tasks.Tests/Extensions/TemporaryRepositoryExtensions.cs index 345d692..e9272c2 100644 --- a/test/DotnetAffected.Tasks.Tests/Extensions/TemporaryRepositoryExtensions.cs +++ b/test/DotnetAffected.Tasks.Tests/Extensions/TemporaryRepositoryExtensions.cs @@ -15,23 +15,8 @@ public static async Task PrepareTaskInfra(this TemporaryRepository repo, string await repo.CreateTextFileAsync("ci.props", TestProjectScenarios.CiProps); var hasImportResource = !string.IsNullOrWhiteSpace(importResource); - var isNetCoreApp31 = Utils.TargetFramework == "netcoreapp3.1"; - if (!hasImportResource && !isNetCoreApp31) - return; - var ciProps = ProjectRootElement.Open(Path.Combine(repo.Path, "ci.props"))!; - if (isNetCoreApp31) - { - // "ci.props" imports DotnetAffected.Tasks as an Sdk - // - // - // When we execute the build within the test we provide the property "DotnetAffectedNugetDir" with the lib's location - // For some reason it's not working in 3.1 so we override - foreach (var importElement in ciProps.Imports) - importElement.Sdk = Utils.DotnetAffectedNugetDir; - } - if (hasImportResource) { var fileName = $"./{Guid.NewGuid().ToString()}.props"; diff --git a/test/DotnetAffected.Tasks.Tests/Utils.cs b/test/DotnetAffected.Tasks.Tests/Utils.cs index 658ae97..a1d8b25 100644 --- a/test/DotnetAffected.Tasks.Tests/Utils.cs +++ b/test/DotnetAffected.Tasks.Tests/Utils.cs @@ -28,8 +28,6 @@ public static class Utils switch (majorVersion) { - case 3: - return "netcoreapp3.1"; case >= 5: return $"net{majorVersion}.0"; default: diff --git a/test/DotnetAffected.Testing.Utils/DotnetAffected.Testing.Utils.csproj b/test/DotnetAffected.Testing.Utils/DotnetAffected.Testing.Utils.csproj index e4db26c..7ef5773 100644 --- a/test/DotnetAffected.Testing.Utils/DotnetAffected.Testing.Utils.csproj +++ b/test/DotnetAffected.Testing.Utils/DotnetAffected.Testing.Utils.csproj @@ -5,7 +5,6 @@ - diff --git a/test/DotnetAffected.Testing.Utils/Repository/TemporaryRepositoryExtensions.cs b/test/DotnetAffected.Testing.Utils/Repository/TemporaryRepositoryExtensions.cs index cf29515..fdf10fe 100644 --- a/test/DotnetAffected.Testing.Utils/Repository/TemporaryRepositoryExtensions.cs +++ b/test/DotnetAffected.Testing.Utils/Repository/TemporaryRepositoryExtensions.cs @@ -49,6 +49,8 @@ public static ProjectRootElement CreateMsBuildProject( // REMARKS: Required for test cases using // Directory.Build.Props / Directory.Packages.props project.Sdk = "Microsoft.NET.Sdk"; + // Required for net8.0 MSBuild Project Creation + project.AddProperty("TargetFrameworks", "net6.0,net8.0"); customizer?.Invoke(project); project.Save();