Skip to content

Commit

Permalink
Upgrade to .NET 8 (#214)
Browse files Browse the repository at this point in the history
This change upgrades the project to use the .NET 8 SDK and adds the
`net8.0` target to all projects. I've also removed support for .NET 7
and updated the version to 2.0. It also addresses the new analyzer
warnings introduced as well as conforms to new C# 12 feature
recommendations imposed by the new analyzers. Using the new artifacts
support for output.
  • Loading branch information
craigktreasure authored Nov 14, 2023
1 parent 4b4358a commit 4095f5b
Show file tree
Hide file tree
Showing 29 changed files with 74 additions and 70 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ csharp_style_expression_bodied_operators = when_on_single_line
# IDE0090: Use 'new(...)'
csharp_style_implicit_object_creation_when_type_is_apparent = true

# IDE0290: Use Primary Constructors
csharp_style_prefer_primary_constructors = false

csharp_indent_labels = one_less_than_current
csharp_space_around_binary_operators = before_and_after
csharp_using_directive_placement = inside_namespace
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/install-tools/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ runs:
with:
dotnet-version: |
6.x
7.x
8.x
- name: Install .NET tools
shell: pwsh
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/workflow_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ jobs:
uses: codecov/codecov-action@v3
with:
name: codecov
directory: __test-results
directory: __artifacts/test-results
fail_ci_if_error: true
verbose: true

- name: Upload output artifact
uses: actions/upload-artifact@v3
with:
name: output_${{ inputs.platform }}
path: __output
path: __artifacts/bin

- name: Upload package artifact
uses: actions/upload-artifact@v3
with:
name: packages_${{ inputs.platform }}
path: __packages
path: __artifacts/package
4 changes: 2 additions & 2 deletions .github/workflows/workflow_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/download-artifact@v3
with:
name: packages_ubuntu
path: __packages
path: __artifacts/package

- name: Push ${{ inputs.package-version }} to NuGet.org
run: nuget push __packages/NuGet/Release/SlnUp.*.nupkg -ApiKey ${{ secrets.NUGET_API_KEY }} -Source https://api.nuget.org/v3/index.json
run: nuget push __artifacts/package/release/SlnUp.*.nupkg -ApiKey ${{ secrets.NUGET_API_KEY }} -Source https://api.nuget.org/v3/index.json
6 changes: 2 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<RepoRootPath>$(MSBuildThisFileDirectory)</RepoRootPath>
<CentralBuildOutputPath>$(RepoRootPath)</CentralBuildOutputPath>
<UseArtifactsOutput>true</UseArtifactsOutput>
<ArtifactsPath>$(RepoRootPath)__artifacts</ArtifactsPath>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)\eng\Defaults.props" />

<!-- Import the CentralBuildOutput SDK. -->
<Sdk Name="Treasure.Build.CentralBuildOutput" />
</Project>
2 changes: 1 addition & 1 deletion eng/DotNetAnalyzers.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<AnalysisLevel>7.0</AnalysisLevel>
<AnalysisLevel>8.0</AnalysisLevel>
</PropertyGroup>

</Project>
10 changes: 9 additions & 1 deletion eng/DotNetDefaults.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<!-- Sets the C# language version:
https://docs.microsoft.com/dotnet/csharp/language-reference/configure-language-version#c-language-version-reference
-->
<LangVersion>11.0</LangVersion>
<LangVersion>latest</LangVersion>

<!-- Enable implicit usings:
https://docs.microsoft.com/dotnet/core/project-sdk/overview#implicit-using-directives
Expand Down Expand Up @@ -48,4 +48,12 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup>
<!-- Configure test and code coverage output. -->
<BaseTestResultsOutputPath>$(ArtifactsPath)/test-results/</BaseTestResultsOutputPath>
<BaseProjectTestResultsOutputPath>$(BaseTestResultsOutputPath)$(MSBuildProjectName)/</BaseProjectTestResultsOutputPath>
<VSTestResultsDirectory>$(BaseProjectTestResultsOutputPath)</VSTestResultsDirectory>
<CoverletOutput>$(BaseProjectTestResultsOutputPath)</CoverletOutput>
</PropertyGroup>

</Project>
5 changes: 1 addition & 4 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"sdk": {
"version": "7.0.100",
"version": "8.0.100",
"allowPrerelease": false,
"rollForward": "latestFeature"
},
"msbuild-sdks": {
"Treasure.Build.CentralBuildOutput" : "3.0.0"
}
}
2 changes: 1 addition & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageVersion Include="HtmlAgilityPack" Version="1.11.54" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.IO.Abstractions" Version="$(SystemIOAbstractionsVersion)" />
<PackageVersion Include="System.Text.Json" Version="7.0.3" />
<PackageVersion Include="System.Text.Json" Version="8.0.0" />
<PackageVersion Include="Treasure.Utils.Argument" Version="1.0.44" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/SlnUp.Core/SlnUp.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions src/SlnUp.Core/VersionManager.g.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool on 11/11/2023.
// This code was generated by a tool on 11/14/2023.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand All @@ -9,7 +9,7 @@

namespace SlnUp.Core;

[System.CodeDom.Compiler.GeneratedCodeAttribute("VisualStudio.VersionScraper", "1.4.0.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("VisualStudio.VersionScraper", "2.0.0.0")]
public partial class VersionManager
{
/// <summary>
Expand All @@ -30,6 +30,7 @@ public static IReadOnlyList<VisualStudioVersion> GetDefaultVersions()
{
return new []
{
new VisualStudioVersion(VisualStudioProduct.VisualStudio2022, Version.Parse("17.8.0"), Version.Parse("17.8.34309.116"), "LTSC 17.8", false),
new VisualStudioVersion(VisualStudioProduct.VisualStudio2022, Version.Parse("17.7.6"), Version.Parse("17.7.34221.43"), "Current", false),
new VisualStudioVersion(VisualStudioProduct.VisualStudio2022, Version.Parse("17.7.5"), Version.Parse("17.7.34202.233"), "Current", false),
new VisualStudioVersion(VisualStudioProduct.VisualStudio2022, Version.Parse("17.7.4"), Version.Parse("17.7.34031.279"), "Current", false),
Expand Down
2 changes: 1 addition & 1 deletion src/SlnUp.Json/SlnUp.Json.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 8 additions & 0 deletions src/SlnUp/CLI/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ internal static class ArgumentParser
{
private const string CannotParseArgumentOption = "Cannot parse argument '{0}' for option '{1}' as expected type '{2}'.";

#if NET8_0_OR_GREATER
private static readonly System.Text.CompositeFormat CannotParseArgumentOptionFormat = System.Text.CompositeFormat.Parse(CannotParseArgumentOption);
#endif

public static Version? ParseVersion(ArgumentResult result)
{
string tokenValue = result.Tokens.Single().Value;
Expand All @@ -17,7 +21,11 @@ internal static class ArgumentParser

result.ErrorMessage = string.Format(
CultureInfo.InvariantCulture,
#if NET8_0_OR_GREATER
CannotParseArgumentOptionFormat,
#else
CannotParseArgumentOption,
#endif
tokenValue,
result.Argument.Name,
result.Argument.ValueType);
Expand Down
2 changes: 1 addition & 1 deletion src/SlnUp/SlnUp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>

<PackAsTool>true</PackAsTool>
<ToolCommandName>slnup</ToolCommandName>
Expand Down
2 changes: 1 addition & 1 deletion src/SlnUp/SolutionFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ internal void UpdateFileHeader(SolutionFileHeader fileHeader)
};
}

List<string> lines = this.fileSystem.File.ReadAllLines(this.filePath).ToList();
List<string> lines = [.. this.fileSystem.File.ReadAllLines(this.filePath)];

if (this.FileHeader.LastVisualStudioMajorVersion is null)
{
Expand Down
12 changes: 0 additions & 12 deletions src/VisualStudio.VersionScraper/Extensions/SetExtensions.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
14 changes: 7 additions & 7 deletions src/VisualStudio.VersionScraper/VisualStudioVersionDocScraper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
using SlnUp.Core;
using SlnUp.Core.Extensions;

using VisualStudio.VersionScraper.Extensions;

internal sealed class VisualStudioVersionDocScraper
{
private const string buildNumberColumnName = "Build Number";
Expand Down Expand Up @@ -48,10 +46,12 @@ public VisualStudioVersionDocScraper(bool useCache = true)
/// <returns><see cref="IEnumerable{VisualStudioVersion}"/>.</returns>
public IEnumerable<VisualStudioVersion> ScrapeVisualStudioVersions()
{
HashSet<VisualStudioVersion> versions = new();
versions.AddRange(this.ScrapeVisualStudioVersions(vsCurrentVersionsDocUrl, "VSCurrentVersionCache"));
versions.AddRange(this.ScrapeVisualStudioVersions(vs2019VersionsDocUrl, "VS2019VersionCache"));
versions.AddRange(this.ScrapeVisualStudioVersions(vs2017VersionsDocUrl, "VS2017VersionCache"));
HashSet<VisualStudioVersion> versions =
[
.. this.ScrapeVisualStudioVersions(vsCurrentVersionsDocUrl, "VSCurrentVersionCache"),
.. this.ScrapeVisualStudioVersions(vs2019VersionsDocUrl, "VS2019VersionCache"),
.. this.ScrapeVisualStudioVersions(vs2017VersionsDocUrl, "VS2017VersionCache"),
];
return versions;
}

Expand Down Expand Up @@ -167,7 +167,7 @@ private static bool TryGetTableData(
return false;
}

List<RowData> data = new();
List<RowData> data = [];

foreach (HtmlNode row in rows)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace VisualStudio.VersionScraper.Writers.CSharp;

using System.Diagnostics.CodeAnalysis;
using System.IO.Abstractions;

using SlnUp.Core;
Expand All @@ -16,6 +15,7 @@ internal sealed class CSharpVersionWriter
private const string NamespaceName = "SlnUp.Core";

private readonly IFileSystem fileSystem;

public CSharpVersionWriter(IFileSystem fileSystem) => this.fileSystem = Argument.NotNull(fileSystem);

public void WriteClassToFile(IEnumerable<VisualStudioVersion> versions, string filePath)
Expand All @@ -41,7 +41,6 @@ private static void WriteClass(CodeWriter writer, IEnumerable<VisualStudioVersio
}
}

[SuppressMessage("Globalization", "CA1304:Specify CultureInfo")]
private static void WriteGetVersionsMethod(CodeWriter writer, IEnumerable<VisualStudioVersion> versions)
{
writer.WriteLines(@"
Expand Down
2 changes: 1 addition & 1 deletion tests/SlnUp.Core.Tests/SlnUp.Core.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion tests/SlnUp.Json.Tests/SlnUp.Json.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion tests/SlnUp.TestLibrary/SlnUp.TestLibrary.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>

<IsTestProject>false</IsTestProject>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions tests/SlnUp.Tests/CLI/ProgramOptionsBinderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public void GetBoundValue(string? version, string? expectedPath, string? expecte
Option<string?> pathOption = new("--path");
Argument<string?> versionArgument = new("version", getDefaultValue: () => ProgramOptions.DefaultVersionArgument);
Option<Version?> buildVersionOption = new("--build-version", parseArgument: ArgumentParser.ParseVersion);
RootCommand command = new()
{
RootCommand command =
[
pathOption,
versionArgument,
buildVersionOption,
};
];
ProgramOptionsBinder binder = new(pathOption, versionArgument, buildVersionOption);
StringBuilder argsBuilder = new(version);

Expand Down
12 changes: 6 additions & 6 deletions tests/SlnUp.Tests/CLI/ProgramOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ProgramOptionsTests
public void Configure(string version)
{
// Arrange
string[] args = new[] { version };
string[] args = [version];

// Act
ProgramOptions? result = this.ConfigureAndInvoke(args, out int exitCode);
Expand All @@ -36,7 +36,7 @@ public void Configure(string version)
public void Configure_NoParameters()
{
// Arrange
string[] args = Array.Empty<string>();
string[] args = [];

// Act
ProgramOptions? result = this.ConfigureAndInvoke(args, out int exitCode);
Expand Down Expand Up @@ -92,12 +92,12 @@ public void Configure_WithHelp(params string[] args)
public void Configure_WithInvalidBuildVersion()
{
// Arrange
string[] args = new[]
{
string[] args =
[
"2022",
"--build-version",
"invalid-version"
};
];

// Act
ProgramOptions? result = this.ConfigureAndInvoke(args, out int exitCode);
Expand Down Expand Up @@ -137,7 +137,7 @@ public void Configure_WithPath(params string[] args)
public void Configure_WithVersion()
{
// Arrange
string[] args = new[] { "--version" };
string[] args = ["--version"];

// Act
ProgramOptions? result = this.ConfigureAndInvoke(args, out int exitCode);
Expand Down
Loading

0 comments on commit 4095f5b

Please sign in to comment.