Skip to content

Commit

Permalink
Build nuget package, support netstandard2.0 build
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Feb 18, 2024
1 parent e8cb3de commit c6d1fff
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 53 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ jobs:
- name: Run tests
run: xvfb-run ./build test+only --configuration=Release --where="Category!=FlakyNetwork"

- name: Publish ckan.dll to NuGet
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
if: env.NUGET_API_KEY
run: |
curl -o nuget.exe -L 'https://dist.nuget.org/win-x86-commandline/v5.6.0/nuget.exe'
mono nuget.exe push _build/out/CKAN/Release/bin/*.nupkg ${{ secrets.NUGET_API_KEY }} -Source https://api.nuget.org/v3/index.json -SkipDuplicate
- name: Build dmg
run: ./build osx --configuration=Release --exclusive
- name: Build deb
Expand Down
1 change: 1 addition & 0 deletions AutoUpdate/CKAN-autoupdate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<ApplicationIcon>..\assets\ckan.ico</ApplicationIcon>
<TargetFrameworks>net48;net7.0-windows</TargetFrameworks>
<UseWindowsForms Condition=" '$(TargetFramework)' == 'net7.0-windows' ">true</UseWindowsForms>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<FileAlignment>512</FileAlignment>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand Down
42 changes: 27 additions & 15 deletions Core/CKAN-core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,43 @@
<Prefer32Bit>false</Prefer32Bit>
<LangVersion>7.3</LangVersion>
<NoWarn>IDE1006</NoWarn>
<TargetFrameworks>net48;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net48;net7.0</TargetFrameworks>
<CoreCompileDependsOn>PrepareResources;$(CompileDependsOn)</CoreCompileDependsOn>
</PropertyGroup>
<PropertyGroup>
<PackageId>CKAN</PackageId>
<Title>Comprehensive Kerbal Archive Network</Title>
<Description>Manages mods for KSP1 and KPS2</Description>
<Version>$([System.Text.RegularExpressions.Regex]::Replace(
$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)\..\CHANGELOG.md")),
"^.*?##\s+v(\S+).*$", "$1",
System.Text.RegularExpressions.RegexOptions.Singleline))</Version>
<PackageVersion>$(Version)</PackageVersion>
<Authors>The CKAN Authors</Authors>
<Copyright>Copyright © CKAN Authors 2014–2024</Copyright>
<PackageTags>KerbalSpaceProgram Mods</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IsPackable>true</IsPackable>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageProjectUrl>https://github.com/KSP-CKAN/CKAN</PackageProjectUrl>
<RepositoryUrl>https://github.com/KSP-CKAN/CKAN</RepositoryUrl>
<RepositoryType>git</RepositoryType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
<PackageReference Include="System.Security.Permissions" Version="4.7.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="Autofac" Version="4.9.4" />
<PackageReference Include="SharpZipLib" Version="1.3.3" />
<PackageReference Include="TxFileManager.NETStandard" Version="2.0.0" />
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NJsonSchema" Version="10.9.0" />
<PackageReference Include="ValveKeyValue" Version="0.3.1.152" />
<PackageReference Include="Mono.Cecil" Version="0.11.5" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net48' ">
<PackageReference Include="ChinhDo.Transactions.FileManager" Version="1.2.0" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Transactions" />
<Reference Include="System.ComponentModel.DataAnnotations" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
<PackageReference Include="System.Security.Permissions" Version="4.7.0" />
<PackageReference Include="TxFileManager.NETStandard" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\_build\meta\GlobalAssemblyVersionInfo.cs">
<Link>Properties\GlobalAssemblyVersionInfo.cs</Link>
Expand All @@ -53,6 +64,7 @@
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="..\README.md" Pack="true" PackagePath="\"/>
<EmbeddedResource Include="builds-ksp.json" />
<EmbeddedResource Include="builds-ksp2.json" />
<EmbeddedResource Include="..\CKAN.schema">
Expand Down
37 changes: 32 additions & 5 deletions Core/Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,43 @@ public static ICollection<T> AsCollection<T>(this IEnumerable<T> source)
? throw new ArgumentNullException(nameof(source))
: source is ICollection<T> collection ? collection : source.ToArray();

#if NET45

public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source)
#if NET45 || NETSTANDARD2_0

#if NET45
public
#elif NETSTANDARD2_0
internal
#endif
static HashSet<T> ToHashSet<T>(this IEnumerable<T> source)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}

return new HashSet<T>(source);
}

#if NET45
public
#elif NETSTANDARD2_0
internal
#endif
static HashSet<T> ToHashSet<T>(this IEnumerable<T> source,
IEqualityComparer<T> comparer)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}

return new HashSet<T>(source, comparer);
}

#endif

#if NET45

public static IEnumerable<T> Append<T>(this IEnumerable<T> source, T next)
=> source.Concat(Enumerable.Repeat<T>(next, 1));

Expand Down Expand Up @@ -115,7 +142,7 @@ public static TimeSpan Sum(this IEnumerable<TimeSpan> source)
public static IEnumerable<V> ZipMany<T, U, V>(this IEnumerable<T> seq1, IEnumerable<U> seq2, Func<T, U, IEnumerable<V>> func)
=> seq1.Zip(seq2, func).SelectMany(seqs => seqs);

#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD2_0

/// <summary>
/// Eliminate duplicate elements based on the value returned by a callback
Expand All @@ -142,7 +169,7 @@ public static IEnumerable<T> TraverseNodes<T>(this T start, Func<T, T> getNext)
}
}

#if NETFRAMEWORK
#if NETFRAMEWORK || NETSTANDARD2_0

/// <summary>
/// Make pairs out of the elements of two sequences
Expand Down
3 changes: 3 additions & 0 deletions Core/Registry/IRegistryQuerier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

using CKAN.Versioning;
using CKAN.Games;
#if NETSTANDARD2_0
using CKAN.Extensions;
#endif

namespace CKAN
{
Expand Down
4 changes: 4 additions & 0 deletions Core/Relationships/SanityChecker.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;

using CKAN.Versioning;
#if NETSTANDARD2_0
using CKAN.Extensions;
#endif

namespace CKAN
{
Expand Down
3 changes: 3 additions & 0 deletions Core/Types/CkanModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

using CKAN.Versioning;
using CKAN.Games;
#if NETSTANDARD2_0
using CKAN.Extensions;
#endif

namespace CKAN
{
Expand Down
4 changes: 4 additions & 0 deletions Core/Types/License.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

using Newtonsoft.Json;

#if NETSTANDARD2_0
using CKAN.Extensions;
#endif

namespace CKAN
{
/// <summary>
Expand Down
1 change: 1 addition & 0 deletions GUI/CKAN-GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<TargetFrameworks>net48;net7.0-windows</TargetFrameworks>
<BaseTargetFramework>$(TargetFramework.Replace("-windows", ""))</BaseTargetFramework>
<UseWindowsForms Condition=" '$(TargetFramework)' == 'net7.0-windows' ">true</UseWindowsForms>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<FileAlignment>512</FileAlignment>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ It provides strong assurances that mods are installed in the way prescribed by t
for the correct version of Kerbal Space Program, alongside their dependencies, and without any conflicting mods.

CKAN is great for players _and_ for authors:

- players can find new content and install it with just a few clicks;
- modders don't have to worry about misinstall problems or outdated versions;

Expand Down
2 changes: 2 additions & 0 deletions Tests/Core/Registry/CompatibilitySorter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

using CKAN;
using CKAN.Versioning;
#if NET45
using CKAN.Extensions;
#endif

using Tests.Data;

Expand Down
55 changes: 22 additions & 33 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ var configuration = Argument<string>("configuration", "Debug");
var solution = Argument<string>("solution", "CKAN.sln");

var rootDirectory = Context.Environment.WorkingDirectory;
var coreProj = rootDirectory.Combine("Core")
.CombineWithFilePath("CKAN-core.csproj")
.FullPath;
var buildDirectory = rootDirectory.Combine("_build");
var nugetDirectory = buildDirectory.Combine("lib")
.Combine("nuget");
Expand Down Expand Up @@ -190,37 +193,11 @@ Task("Restore")
.Description("Intermediate - Download dependencies")
.Does(() =>
{
if (IsRunningOnWindows())
DotNetRestore(solution, new DotNetRestoreSettings
{
DotNetRestore(solution, new DotNetRestoreSettings
{
PackagesDirectory = nugetDirectory,
EnvironmentVariables = new Dictionary<string, string> { { "Configuration", configuration } },
});
}
else
{
// NuGet is confused by multi-targeting, and
// Mono has no idea what "net7.0" is. Only restore for buildNetFramework.
DotNetRestore(solution, new DotNetRestoreSettings
{
PackagesDirectory = nugetDirectory,
EnvironmentVariables = new Dictionary<string, string> { { "Configuration", configuration } },
MSBuildSettings = new DotNetMSBuildSettings()
.SetConfiguration(configuration)
.WithProperty("TargetFramework",
buildNetFramework),
});
DotNetRestore(solution, new DotNetRestoreSettings
{
PackagesDirectory = nugetDirectory,
EnvironmentVariables = new Dictionary<string, string> { { "Configuration", "NoGUI" } },
MSBuildSettings = new DotNetMSBuildSettings()
.SetConfiguration("NoGUI")
.WithProperty("TargetFramework",
"net7.0"),
});
}
PackagesDirectory = nugetDirectory,
EnvironmentVariables = new Dictionary<string, string> { { "Configuration", configuration } },
});
});

Task("Build")
Expand All @@ -241,15 +218,21 @@ Task("Build")
}
else
{
// Mono has no idea what "net7.0" is
// Use dotnet to build the Core DLL to get the nupkg
// (only created if all TargetFrameworks are built together)
DotNetBuild(coreProj, new DotNetBuildSettings
{
Configuration = configuration,
});
// Use Mono to build for net48 since dotnet can't use WinForms on Linux
MSBuild(solution,
settings => settings.SetConfiguration(configuration)
.WithProperty("TargetFramework",
buildNetFramework));
// Use dotnet to build the stuff Mono can't build
DotNetBuild(solution, new DotNetBuildSettings
{
Configuration = "NoGUI",
NoRestore = true,
Framework = "net7.0",
});
}
Expand Down Expand Up @@ -296,7 +279,7 @@ Task("Repack-Ckan")
.Combine(configuration)
.Combine("bin")
.Combine(buildNetFramework))));
// Need netstandard.dll facade to instantiate types from ValveKeyValue on Mono
// Need facade to instantiate types from netstandard2.0 DLLs on Mono
assemblyPaths.Add(FacadesDirectory().CombineWithFilePath("netstandard.dll"));
var ckanLogFile = repackDirectory.Combine(configuration)
.CombineWithFilePath($"ckan.log");
Expand Down Expand Up @@ -355,6 +338,8 @@ Task("Repack-Netkan")
var netkanLogFile = repackDirectory.Combine(configuration)
.CombineWithFilePath($"netkan.log");
var assemblyPaths = GetFiles(string.Format("{0}/*.dll", netkanBinDirectory));
// Need facade to instantiate types from netstandard2.0 DLLs on Mono
assemblyPaths.Add(FacadesDirectory().CombineWithFilePath("netstandard.dll"));
ReportRepacking(netkanFile, netkanLogFile);
ILRepack(
netkanFile,
Expand Down Expand Up @@ -446,6 +431,7 @@ Task("Test-UnitTests+Only")
{
Configuration = configuration,
NoBuild = true,
NoLogo = true,
Filter = where,
ResultsDirectory = nunitOutputDirectory,
Verbosity = DotNetVerbosity.Minimal,
Expand All @@ -456,7 +442,9 @@ Task("Test-UnitTests+Only")
DotNetTest(solution, new DotNetTestSettings
{
Configuration = "NoGUI",
Framework = "net7.0",
NoBuild = true,
NoLogo = true,
Filter = where,
ResultsDirectory = nunitOutputDirectory,
Verbosity = DotNetVerbosity.Minimal,
Expand All @@ -471,6 +459,7 @@ Task("Test-UnitTests+Only")
Configuration = configuration,
Where = where,
Work = nunitOutputDirectory,
NoHeader = true,
// Work around System.Runtime.Remoting.RemotingException : Tcp transport error.
Process = NUnit3ProcessOption.InProcess,
});
Expand Down

0 comments on commit c6d1fff

Please sign in to comment.