From e8bef8af6a16e6ec2b06af331e5f3e4a491e83e3 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Mon, 30 Dec 2019 23:05:29 -0700 Subject: [PATCH] Update SourceLink package/info and target .NET Core 3.1 with hactoolnet (#106) Make hactoolnet target the LTS .NET Core version. LibHac still targets .NET Core 3.0. --- DotnetCliVersion.txt | 2 +- build/Build.cs | 79 +++++++++++++++++++------- build/_build.csproj | 6 +- src/LibHac/LibHac.csproj | 19 ++++--- src/hactoolnet/hactoolnet.csproj | 4 +- tests/LibHac.Tests/LibHac.Tests.csproj | 2 +- 6 files changed, 75 insertions(+), 37 deletions(-) diff --git a/DotnetCliVersion.txt b/DotnetCliVersion.txt index d7fab98f..a43bc739 100644 --- a/DotnetCliVersion.txt +++ b/DotnetCliVersion.txt @@ -1 +1 @@ -3.0.100 \ No newline at end of file +3.1.100 \ No newline at end of file diff --git a/build/Build.cs b/build/Build.cs index 865b3bc7..3f6b73d2 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -35,15 +35,13 @@ namespace LibHacBuild public readonly bool Untrimmed; [Solution("LibHac.sln")] readonly Solution _solution; - [GitRepository] readonly GitRepository _gitRepository; - [GitVersion] readonly GitVersion _gitVersion; AbsolutePath SourceDirectory => RootDirectory / "src"; AbsolutePath TestsDirectory => RootDirectory / "tests"; AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts"; AbsolutePath SignedArtifactsDirectory => ArtifactsDirectory / "signed"; AbsolutePath TempDirectory => RootDirectory / ".tmp"; - AbsolutePath CliCoreDir => TempDirectory / "hactoolnet_netcoreapp3.0"; + AbsolutePath CliCoreDir => TempDirectory / "hactoolnet_netcoreapp3.1"; AbsolutePath CliNativeDir => TempDirectory / $"hactoolnet_{HostOsName}"; AbsolutePath CliNativeExe => CliNativeDir / $"hactoolnet_native{NativeProgramExtension}"; AbsolutePath CliCoreZip => ArtifactsDirectory / $"hactoolnet-{VersionString}-netcore.zip"; @@ -54,6 +52,8 @@ namespace LibHacBuild Project LibHacTestProject => _solution.GetProject("LibHac.Tests").NotNull(); Project HactoolnetProject => _solution.GetProject("hactoolnet").NotNull(); + private bool HasGitDir { get; set; } + private string NativeRuntime { get; set; } private string HostOsName { get; set; } private string NativeProgramExtension { get; set; } @@ -86,42 +86,76 @@ namespace LibHacBuild } } - private bool IsMasterBranch => _gitVersion?.BranchName.Equals("master") ?? false; - Target SetVersion => _ => _ - .OnlyWhenStatic(() => _gitRepository != null) .Executes(() => { - VersionString = $"{_gitVersion.MajorMinorPatch}"; - if (!string.IsNullOrWhiteSpace(_gitVersion.PreReleaseTag)) + GitRepository gitRepository = null; + GitVersion gitVersion = null; + + try { - VersionString += $"-{_gitVersion.PreReleaseTag}+{_gitVersion.Sha.Substring(0, 8)}"; + gitRepository = (GitRepository)new GitRepositoryAttribute().GetValue(null, null); + + gitVersion = GitVersionTasks.GitVersion(s => s + .SetFramework("netcoreapp3.1") + .DisableLogOutput()) + .Result; + } + catch (Exception e) + { + Logger.Error(e); } - string suffix = _gitVersion.PreReleaseTag; + if (gitRepository == null || gitVersion == null) + { + Logger.Normal("Unable to read Git version."); + return; + } + + HasGitDir = true; + + VersionString = $"{gitVersion.MajorMinorPatch}"; + if (!string.IsNullOrWhiteSpace(gitVersion.PreReleaseTag)) + { + VersionString += $"-{gitVersion.PreReleaseTag}+{gitVersion.Sha.Substring(0, 8)}"; + } + + string suffix = gitVersion.PreReleaseTag; if (!string.IsNullOrWhiteSpace(suffix)) { - if (!_gitRepository.IsOnMasterBranch()) + if (!gitRepository.IsOnMasterBranch()) { suffix = $"-{suffix}"; } - suffix += $"+{_gitVersion.Sha.Substring(0, 8)}"; + suffix += $"+{gitVersion.Sha.Substring(0, 8)}"; + } + + if (Host == HostType.AppVeyor) + { + // Workaround GitVersion issue by getting PR info manually https://github.com/GitTools/GitVersion/issues/1927 + string prNumber = Environment.GetEnvironmentVariable("APPVEYOR_PULL_REQUEST_NUMBER"); + string branchName = Environment.GetEnvironmentVariable("APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH"); + + if (int.TryParse(prNumber, out int prInt) && branchName != null) + { + string prString = $"PullRequest{prInt:D4}"; + + VersionString = VersionString.Replace(branchName, prString); + suffix = suffix.Replace(branchName, prString); + } + + SetAppVeyorVersion(VersionString); } VersionProps = new Dictionary { - ["VersionPrefix"] = _gitVersion.AssemblySemVer, + ["VersionPrefix"] = gitVersion.AssemblySemVer, ["VersionSuffix"] = suffix }; Logger.Normal($"Building version {VersionString}"); - - if (Host == HostType.AppVeyor) - { - SetAppVeyorVersion(VersionString); - } }); Target Clean => _ => _ @@ -159,7 +193,8 @@ namespace LibHacBuild .EnableNoRestore() .SetConfiguration(Configuration) .SetProperties(VersionProps) - .SetProperty("BuildType", "Release"); + .SetProperty("BuildType", "Release") + .SetProperty("HasGitDir", HasGitDir); DotNetBuild(s => buildSettings); @@ -169,7 +204,7 @@ namespace LibHacBuild DotNetPublish(s => publishSettings .SetProject(HactoolnetProject) - .SetFramework("netcoreapp3.0") + .SetFramework("netcoreapp3.1") .SetOutput(CliCoreDir) .SetNoBuild(true) .SetProperties(VersionProps)); @@ -221,7 +256,7 @@ namespace LibHacBuild .EnableNoBuild() .SetConfiguration(Configuration); - if (EnvironmentInfo.IsUnix) settings = settings.SetProperty("TargetFramework", "netcoreapp3.0"); + if (EnvironmentInfo.IsUnix) settings = settings.SetProperty("TargetFramework", "netcoreapp3.1"); DotNetTest(s => settings); }); @@ -335,7 +370,7 @@ namespace LibHacBuild DotNetPublishSettings publishSettings = new DotNetPublishSettings() .SetConfiguration(Configuration) .SetProject(nativeProject) - .SetFramework("netcoreapp3.0") + .SetFramework("netcoreapp3.1") .SetRuntime(NativeRuntime) .SetOutput(CliNativeDir) .SetProperties(VersionProps); diff --git a/build/_build.csproj b/build/_build.csproj index 77a0d806..fc171fc0 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.0 + netcoreapp3.1 false LibHacBuild False @@ -10,8 +10,8 @@ - - + + diff --git a/src/LibHac/LibHac.csproj b/src/LibHac/LibHac.csproj index ef1e3163..4f7b1741 100644 --- a/src/LibHac/LibHac.csproj +++ b/src/LibHac/LibHac.csproj @@ -2,8 +2,10 @@ Library + 0.8.0 netcoreapp3.0;netstandard2.1 8.0 + true @@ -13,17 +15,18 @@ Nintendo;Switch;nca;xci;savefile https://github.com/Thealexbarney/LibHac MIT - git - https://github.com/Thealexbarney/LibHac - 0.7.0 - $(MSBuildProjectDirectory)=C:/LibHac/ true snupkg - true - $(NoWarn);1591;NU5105 + true true - true + + + + $(MSBuildProjectDirectory)=C:/LibHac/ + true + + $(NoWarn);1591;NU5105 @@ -35,7 +38,7 @@ - + diff --git a/src/hactoolnet/hactoolnet.csproj b/src/hactoolnet/hactoolnet.csproj index 74ad0ced..c5e67e5a 100644 --- a/src/hactoolnet/hactoolnet.csproj +++ b/src/hactoolnet/hactoolnet.csproj @@ -2,12 +2,12 @@ Exe - netcoreapp3.0 + netcoreapp3.1 8.0 - 0.7.0 + 0.8.0 $(MSBuildProjectDirectory)=C:/hactoolnet/ diff --git a/tests/LibHac.Tests/LibHac.Tests.csproj b/tests/LibHac.Tests/LibHac.Tests.csproj index 27b72fc1..ee2c2200 100644 --- a/tests/LibHac.Tests/LibHac.Tests.csproj +++ b/tests/LibHac.Tests/LibHac.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp3.0 + netcoreapp3.1 false