Skip to content

Commit

Permalink
BREAKING CHANGE: support .net 8 support. Remove support for netcoreap…
Browse files Browse the repository at this point in the history
…p3.1 (#89)

* add .net 8 support

* drop netcore3.1 support

* temp: notes

* chore: change eng scripts to install correct sdks

* chore: remove netcoreapp3 packages

* chore: removes netcoreapp3 condition

* fix: tests for net8.0

* fix: ci build by building in release

* ci: fix build

---------

Co-authored-by: Leonardo Chaia <[email protected]>
  • Loading branch information
tanordheim and leonardochaia authored Jan 13, 2024
1 parent 84c86fb commit f815198
Show file tree
Hide file tree
Showing 18 changed files with 25 additions and 217 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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/
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<TargetFrameworks>net7.0;net6.0;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>

<LangVersion>9.0</LangVersion>

Expand Down
16 changes: 8 additions & 8 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.0.0" Condition="'$(ContinuousIntegrationBuild)' == 'true'"/>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageVersion Include="Microsoft.Build" Version="16.9.0" />
<PackageVersion Include="Microsoft.Build.Framework" Version="16.9.0" />
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="16.9.0" />
<PackageVersion Include="Microsoft.Win32.Registry" Version="6.0.0-preview.5.21301.5" />
<PackageVersion Include="System.CodeDom" Version="6.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageVersion Include="Microsoft.Build" Version="17.3.2" />
<PackageVersion Include="Microsoft.Build.Framework" Version="17.3.2" />
Expand All @@ -40,4 +32,12 @@
<PackageVersion Include="System.CodeDom" Version="7.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageVersion Include="Microsoft.Build" Version="17.5.0" />
<PackageVersion Include="Microsoft.Build.Framework" Version="17.5.0" />
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="17.5.0" />
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
<PackageVersion Include="System.CodeDom" Version="8.0.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion eng/install-sdk.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion eng/install-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.101",
"version": "8.0.100",
"allowPrerelease": true
}
}
4 changes: 1 addition & 3 deletions src/DotnetAffected.Core/AffectedExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public AffectedExecutor(
}

/// <inheritdoc />
public AffectedSummary Execute() => GitChangesProvider.MsBuildFileSystemSupported
? new AffectedProcessor().Process(_context)
: new AffectedProcessorLegacy().Process(_context);
public AffectedSummary Execute() => new AffectedProcessor().Process(_context);
}
}
85 changes: 2 additions & 83 deletions src/DotnetAffected.Core/GitChangesProvider.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -21,22 +16,6 @@ public class GitChangesProvider : IChangesProvider
{
internal static readonly bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);

private static readonly Lazy<bool> ResolveMsBuildFileSystemSupported = new Lazy<bool>(() =>
{
var versionInfo = FileVersionInfo.GetVersionInfo(typeof(Project).Assembly.Location);
if (versionInfo.FileMajorPart > 16)
return true;
if (versionInfo.FileMajorPart < 16)
return false;
return versionInfo.FileMinorPart >= 10;
});

/// <summary>
/// When true, the build system supports virtual filesystem which means nested Directory.Packages.props files
/// are supported in central package management.
/// </summary>
public static bool MsBuildFileSystemSupported => ResolveMsBuildFileSystemSupported.Value;

/// <inheritdoc />
public IEnumerable<string> GetChangedFiles(string directory, string from, string to)
{
Expand All @@ -52,7 +31,7 @@ public IEnumerable<string> 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;
Expand All @@ -67,9 +46,7 @@ public IEnumerable<string> GetChangedFiles(string directory, string from, string
/// <inheritdoc />
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)
Expand All @@ -96,64 +73,6 @@ public IEnumerable<string> 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,
Expand Down
80 changes: 0 additions & 80 deletions src/DotnetAffected.Core/Processor/AffectedProcessorLegacy.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/DotnetAffected.Core/ProjectFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/DotnetAffected.Tasks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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 `<TargetFramework>`.

Expand All @@ -278,5 +279,5 @@ If you have issues, you can override the logic by specifically setting the `<Tar
```

> `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`.

5 changes: 2 additions & 3 deletions src/DotnetAffected.Tasks/Sdk/Sdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

<!-- TargetFramework is not set by default in all project styles, especially traversal like projects
However, we need it to properly load the assembly
We respect user input, if explicilty set in <TargetFramework>
If not, we auto-detect it and assign it to <TargetFramework>
Later in .targets, we _DotnetAffectedTargetFramework to load the assembly but if TargetFramework is not empty
we will use it, this is to allow late modification for TargetFramework down the pipe
-->
Expand All @@ -19,7 +19,6 @@
<_DotnetAffectedTargetFramework Condition="'$(_DotnetAffectedTargetFramework)' == ''">$(MicrosoftNETBuildTasksTFM)</_DotnetAffectedTargetFramework>
<_DotnetAffectedTargetFramework Condition="'$(_DotnetAffectedTargetFramework)' == '' And $([MSBuild]::VersionGreaterThanOrEquals('$(MSBuildVersion)', '17.0.0'))">net6.0</_DotnetAffectedTargetFramework>
<_DotnetAffectedTargetFramework Condition="'$(_DotnetAffectedTargetFramework)' == '' And $([MSBuild]::VersionGreaterThanOrEquals('$(MSBuildVersion)', '16.11.0'))">net5.0</_DotnetAffectedTargetFramework>
<_DotnetAffectedTargetFramework Condition="'$(_DotnetAffectedTargetFramework)' == ''">netcoreapp3.1</_DotnetAffectedTargetFramework>

<TargetFramework>$(_DotnetAffectedTargetFramework)</TargetFramework>
</PropertyGroup>
Expand Down
1 change: 0 additions & 1 deletion src/dotnet-affected/dotnet-affected.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<PackageReference Include="Microsoft.Build.Framework" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Utilities.Core" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Locator" />
<PackageReference Condition="'$(TargetFramework)' == 'netcoreapp3.1'" Include="Microsoft.Win32.Registry" />
<PackageReference Include="System.CommandLine" />
<PackageReference Include="System.CommandLine.Rendering" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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
}
}
Loading

0 comments on commit f815198

Please sign in to comment.