Skip to content

Commit

Permalink
Change supported target frameworks
Browse files Browse the repository at this point in the history
* upgrade from net461 to net462
* drop support for net40, net45
* drop support for < netstandard2.0
* drop netcoreapp2.1, netcoreapp3.1 and net5.0
* upgrade NUKE
* switch back to using windows-latest GH Actions image which now has NET 6 support
  • Loading branch information
lahma committed Sep 27, 2023
1 parent 06f635a commit 8d08ff7
Show file tree
Hide file tree
Showing 47 changed files with 133 additions and 382 deletions.
18 changes: 7 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ on:
- '!**/*.md'

jobs:
windows-2022:
name: windows-2022
runs-on: windows-2022
windows-latest:
name: windows-latest
runs-on: windows-latest
steps:
- name: 'Allow long file path'
run: git config --system core.longpaths true
Expand All @@ -40,27 +40,23 @@ jobs:
run: |
echo "Adding GNU tar to PATH"
echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%"
- uses: actions/setup-dotnet@v3
with:
dotnet-version: |
2.1.*
5.0.*
- uses: actions/checkout@v3
- name: Cache .nuke/temp, ~/.nuget/packages
- name: 'Cache: .nuke/temp, ~/.nuget/packages'
uses: actions/cache@v3
with:
path: |
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('global.json', 'src/**/*.csproj', 'src/**/package.json') }}
- name: Run './build.cmd InstallDependencies Compile Test Pack Publish'
- name: 'Run: InstallDependencies, Compile, Test, Pack, Publish'
run: ./build.cmd InstallDependencies Compile Test Pack Publish
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
MYGET_API_KEY: ${{ secrets.MYGET_API_KEY }}
CHOCO_API_KEY: ${{ secrets.CHOCO_API_KEY }}
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
- uses: actions/upload-artifact@v3
- name: 'Publish: artifacts'
uses: actions/upload-artifact@v3
with:
name: artifacts
path: artifacts
15 changes: 5 additions & 10 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ on:
- '!**/*.md'

jobs:
windows-2022:
name: windows-2022
runs-on: windows-2022
windows-latest:
name: windows-latest
runs-on: windows-latest
steps:
- name: 'Allow long file path'
run: git config --system core.longpaths true
Expand All @@ -38,18 +38,13 @@ jobs:
run: |
echo "Adding GNU tar to PATH"
echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%"
- uses: actions/setup-dotnet@v3
with:
dotnet-version: |
2.1.*
5.0.*
- uses: actions/checkout@v3
- name: Cache .nuke/temp, ~/.nuget/packages
- name: 'Cache: .nuke/temp, ~/.nuget/packages'
uses: actions/cache@v3
with:
path: |
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('global.json', 'src/**/*.csproj', 'src/**/package.json') }}
- name: Run './build.cmd InstallDependencies Compile Test Pack'
- name: 'Run: InstallDependencies, Compile, Test, Pack'
run: ./build.cmd InstallDependencies Compile Test Pack
4 changes: 2 additions & 2 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Build Schema",
"$ref": "#/definitions/build",
"title": "Build Schema",
"definitions": {
"build": {
"type": "object",
Expand Down Expand Up @@ -131,4 +131,4 @@
}
}
}
}
}
7 changes: 6 additions & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $TempDirectory = "$PSScriptRoot\\.nuke\temp"

$DotNetGlobalFile = "$PSScriptRoot\\global.json"
$DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1"
$DotNetChannel = "Current"
$DotNetChannel = "STS"

$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
Expand Down Expand Up @@ -65,5 +65,10 @@ else {

Write-Output "Microsoft (R) .NET SDK version $(& $env:DOTNET_EXE --version)"

if (Test-Path env:NUKE_ENTERPRISE_TOKEN) {
& $env:DOTNET_EXE nuget remove source "nuke-enterprise" > $null
& $env:DOTNET_EXE nuget add source "https://f.feedz.io/nuke/enterprise/nuget" --name "nuke-enterprise" --username "PAT" --password $env:NUKE_ENTERPRISE_TOKEN > $null
}

ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet }
ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile --no-build -- $BuildArguments }
7 changes: 6 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TEMP_DIRECTORY="$SCRIPT_DIR//.nuke/temp"

DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json"
DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh"
DOTNET_CHANNEL="Current"
DOTNET_CHANNEL="STS"

export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
Expand Down Expand Up @@ -58,5 +58,10 @@ fi

echo "Microsoft (R) .NET SDK version $("$DOTNET_EXE" --version)"

if [[ ! -z ${NUKE_ENTERPRISE_TOKEN+x} && "$NUKE_ENTERPRISE_TOKEN" != "" ]]; then
"$DOTNET_EXE" nuget remove source "nuke-enterprise" &>/dev/null || true
"$DOTNET_EXE" nuget add source "https://f.feedz.io/nuke/enterprise/nuget" --name "nuke-enterprise" --username "PAT" --password "$NUKE_ENTERPRISE_TOKEN" --store-password-in-clear-text &>/dev/null || true
fi

"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet
"$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@"
12 changes: 2 additions & 10 deletions build/Build.CI.GitHubActions.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System.Collections.Generic;
using System.Linq;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.CI.GitHubActions.Configuration;
using Nuke.Common.Execution;
using Nuke.Common.Utilities;

[CustomGitHubActions(
"pr",
GitHubActionsImage.WindowsServer2022,
GitHubActionsImage.WindowsLatest,
// GitHubActionsImage.UbuntuLatest,
// GitHubActionsImage.MacOsLatest,
OnPullRequestBranches = new[] { "master", "main" },
Expand All @@ -19,7 +18,7 @@
]
[CustomGitHubActions(
"build",
GitHubActionsImage.WindowsServer2022,
GitHubActionsImage.WindowsLatest,
// GitHubActionsImage.UbuntuLatest,
// GitHubActionsImage.MacOsLatest,
OnPushBranches = new[] { "master", "main" },
Expand Down Expand Up @@ -47,13 +46,6 @@ protected override GitHubActionsJob GetJobs(GitHubActionsImage image, IReadOnlyC

var newSteps = new List<GitHubActionsStep>(job.Steps);

// only need to list the ones that are missing from default image
newSteps.Insert(0, new GitHubActionsSetupDotNetStep(new[]
{
"2.1.*",
"5.0.*"
}));

newSteps.Insert(0, new GitHubActionsUseGnuTarStep());
newSteps.Insert(0, new GitHubActionsConfigureLongPathsStep());

Expand Down
18 changes: 9 additions & 9 deletions build/Build.Pack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public partial class Build
nugetVersion += "-" + VersionSuffix;
}
EnsureCleanDirectory(ArtifactsDirectory);
ArtifactsDirectory.CreateOrCleanDirectory();
// it seems to cause some headache with publishing, so let's dotnet pack only files we know are suitable
var projects = SourceDirectory.GlobFiles("**/*.csproj")
Expand Down Expand Up @@ -70,10 +70,10 @@ public partial class Build
Serilog.Log.Information("Build WiX installer");
EnsureCleanDirectory(SourceDirectory / "NSwagStudio.Installer" / "bin");
(SourceDirectory / "NSwagStudio.Installer" / "bin").CreateOrCleanDirectory();
MSBuild(x => x
.SetTargetPath(Solution.GetProject("NSwagStudio.Installer"))
.SetTargetPath(GetProject("NSwagStudio.Installer"))
.SetTargets("Rebuild")
.SetAssemblyVersion(VersionPrefix)
.SetFileVersion(VersionPrefix)
Expand All @@ -90,9 +90,9 @@ public partial class Build
Serilog.Log.Information("Package nuspecs");
var apiDescriptionClientNuSpec = SourceDirectory / "NSwag.ApiDescription.Client" / "NSwag.ApiDescription.Client.nuspec";
var content = TextTasks.ReadAllText(apiDescriptionClientNuSpec);
content = content.Replace("<dependency id=\"NSwag.MSBuild\" version=\"1.0.0\" />", "<dependency id=\"NSwag.MSBuild\" version=\"" + nugetVersion + "\" />");
TextTasks.WriteAllText(apiDescriptionClientNuSpec, content);
var content = apiDescriptionClientNuSpec.ReadAllText();
content = content.Replace("<dependency id=\"NSwag.MSBuild\" version=\"1.0.0\" />", "<dependency id=\"NSwag.MSBuild\" version=\"" + VersionPrefix + "\" />");
apiDescriptionClientNuSpec.WriteAllText(content);
var nuspecs = new[]
{
Expand Down Expand Up @@ -122,9 +122,9 @@ public partial class Build
// patch npm version
var npmPackagesFile = SourceDirectory / "NSwag.Npm" / "package.json";
content = TextTasks.ReadAllText(npmPackagesFile);
content = Regex.Replace(content, @"""version"": "".*""", @"""version"": """ + nugetVersion + @"""");
TextTasks.WriteAllText(npmPackagesFile, content);
content = npmPackagesFile.ReadAllText();
content = Regex.Replace(content, @"""version"": "".*""", @"""version"": """ + VersionPrefix + @"""");
npmPackagesFile.WriteAllText(content);
// ZIP directories
ZipFile.CreateFromDirectory(NSwagNpmBinaries, ArtifactsDirectory / "NSwag.Npm.zip");
Expand Down
31 changes: 15 additions & 16 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.MSBuild;
using Nuke.Common.Tools.Npm;
using Nuke.Common.Tools.VSTest;
using Nuke.Common.Utilities.Collections;

using static Nuke.Common.IO.FileSystemTasks;
Expand Down Expand Up @@ -76,7 +75,7 @@ string DetermineVersionPrefix()
}
else
{
var propsDocument = XDocument.Parse(TextTasks.ReadAllText(SourceDirectory / "Directory.Build.props"));
var propsDocument = XDocument.Parse((SourceDirectory / "Directory.Build.props").ReadAllText());
versionPrefix = propsDocument.Element("Project").Element("PropertyGroup").Element("VersionPrefix").Value;
Serilog.Log.Information("Version prefix {VersionPrefix} read from Directory.Build.props", versionPrefix);
}
Expand Down Expand Up @@ -117,19 +116,15 @@ protected override void OnBuildInitialized()
.Before(Restore)
.Executes(() =>
{
SourceDirectory.GlobDirectories("**/bin", "**/obj").ForEach(DeleteDirectory);
EnsureCleanDirectory(ArtifactsDirectory);
SourceDirectory.GlobDirectories("**/bin", "**/obj").ForEach(x => x.DeleteDirectory());
ArtifactsDirectory.CreateOrCleanDirectory();
});


Target InstallDependencies => _ => _
.Before(Restore, Compile)
.Executes(() =>
{
Chocolatey("install wixtoolset -y");
Chocolatey("install dotnetcore-3.1-sdk -y");
Chocolatey("install netfx-4.6.2-devpack -y");
Chocolatey("install dotnet-7.0-sdk -y");
NpmInstall(x => x
.EnableGlobal()
.AddPackages("dotnettools")
Expand Down Expand Up @@ -157,18 +152,19 @@ protected override void OnBuildInitialized()
);
});

// logic from 01_Build.bat
Target Compile => _ => _
.DependsOn(Restore)
.Executes(() =>
{
EnsureCleanDirectory(SourceDirectory / "NSwag.Npm" / "bin" / "binaries");
EnsureCleanDirectory(NSwagStudioBinaries);
(SourceDirectory / "NSwag.Npm" / "bin" / "binaries").CreateOrCleanDirectory();
NSwagStudioBinaries.CreateOrCleanDirectory();
Serilog.Log.Information("Build and copy full .NET command line with configuration {Configuration}", Configuration);
// TODO: Fix build here
MSBuild(x => x
.SetProjectFile(Solution.GetProject("NSwagStudio"))
.SetProjectFile(GetProject("NSwagStudio"))
.SetTargets("Build")
.SetAssemblyVersion(VersionPrefix)
.SetFileVersion(VersionPrefix)
Expand Down Expand Up @@ -215,9 +211,9 @@ protected override void OnBuildInitialized()

void PublishAndCopyConsoleProjects()
{
var consoleCoreProject = Solution.GetProject("NSwag.ConsoleCore");
var consoleX86Project = Solution.GetProject("NSwag.Console.x86");
var consoleProject = Solution.GetProject("NSwag.Console");
var consoleCoreProject = GetProject("NSwag.ConsoleCore");
var consoleX86Project = GetProject("NSwag.Console.x86");
var consoleProject = GetProject("NSwag.Console");

Serilog.Log.Information("Publish command line projects");

Expand All @@ -240,7 +236,7 @@ void PublishConsoleProject(Project project, string[] targetFrameworks)

PublishConsoleProject(consoleX86Project, new[] { "net462" });
PublishConsoleProject(consoleProject, new[] { "net462" });
PublishConsoleProject(consoleCoreProject, new[] { "netcoreapp3.1", "net6.0", "net7.0" });
PublishConsoleProject(consoleCoreProject, new[] { "net6.0", "net7.0" });

void CopyConsoleBinaries(AbsolutePath target)
{
Expand All @@ -252,7 +248,6 @@ void CopyConsoleBinaries(AbsolutePath target)
CopyDirectoryRecursively(consoleProject.Directory / "bin" / Configuration / "net462" / "publish", target / "Win", DirectoryExistsPolicy.Merge);

var consoleCoreDirectory = consoleCoreProject.Directory / "bin" / Configuration;
CopyDirectoryRecursively(consoleCoreDirectory / "netcoreapp3.1" / "publish", target / "NetCore31");
CopyDirectoryRecursively(consoleCoreDirectory / "net6.0" / "publish", target / "Net60");
CopyDirectoryRecursively(consoleCoreDirectory / "net7.0" / "publish", target / "Net70");
}
Expand All @@ -276,4 +271,8 @@ DotNetBuildSettings BuildDefaults(DotNetBuildSettings s)
.SetDeterministic(IsServerBuild)
.SetContinuousIntegrationBuild(IsServerBuild);
}

// Solution.GetProject only returns solution's direct descendants since NUKE 7.0.1
private Project GetProject(string projectName) =>
Solution.AllProjects.FirstOrDefault(x => x.Name == projectName) ?? throw new ArgumentException($"Could not find project {projectName} from solution");
}
2 changes: 1 addition & 1 deletion build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nuke.Common" Version="6.3.0" />
<PackageReference Include="Nuke.Common" Version="7.0.6" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 2 additions & 6 deletions src/NSwag.Annotations/NSwag.Annotations.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
<TargetFrameworks>net462;netstandard2.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
</Project>
21 changes: 5 additions & 16 deletions src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net462</TargetFramework>
</PropertyGroup>

<PropertyGroup>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
<DefineConstants>$(DefineConstants);AspNetOwin</DefineConstants>
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="ReDoc\index.html" />
<EmbeddedResource Include="SwaggerUi\**\*" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
Expand All @@ -19,15 +17,7 @@
<EmbeddedResource Include="SwaggerUi3\swagger-ui.css" />
<EmbeddedResource Include="SwaggerUi3\swagger-ui.js" />
</ItemGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net462|AnyCPU'">
<DefineConstants>TRACE;DEBUG;AspNetOwin</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net462|AnyCPU'">
<DefineConstants>TRACE;RELEASE;AspNetOwin</DefineConstants>
</PropertyGroup>


<ItemGroup>
<Compile Include="..\NSwag.AspNetCore\HttpRequestExtension.cs" Link="HttpRequestExtension.cs" />
<Compile Include="..\NSwag.AspNetCore\OAuth2ClientSettings.cs" Link="OAuth2ClientSettings.cs" />
Expand All @@ -37,14 +27,13 @@
<Compile Include="..\NSwag.AspNetCore\SwaggerUiSettings.cs" Link="SwaggerUiSettings.cs" />
<Compile Include="..\NSwag.AspNetCore\SwaggerUiSettingsBase.cs" Link="SwaggerUiSettingsBase.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Owin" Version="3.0.1" />
<PackageReference Include="Microsoft.Owin.StaticFiles" Version="3.0.1" />
<PackageReference Include="NJsonSchema" Version="11.0.0-preview003" />
<PackageReference Include="Owin" Version="1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NSwag.Core\NSwag.Core.csproj" />
<ProjectReference Include="..\NSwag.Generation.WebApi\NSwag.Generation.WebApi.csproj" />
Expand Down
Loading

0 comments on commit 8d08ff7

Please sign in to comment.