Skip to content

Commit

Permalink
Merge pull request #18 from HebaruSan/feature/updates
Browse files Browse the repository at this point in the history
Multi-target net48 and net7.0, streamline Docker image
  • Loading branch information
HebaruSan authored Dec 19, 2023
2 parents 50522ae + fa867b0 commit 341469e
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 137 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ jobs:
with:
path: ~/.nuget/packages
key: nuget-packref-modules-${{ hashFiles('**/*.csproj') }}
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7'
- name: Restore, build, and test
run: msbuild -r -p:configuration=Debug
run: |
msbuild -r -p:configuration=Debug -p:TargetFramework=net48
dotnet build -f net7.0
- name: Smoke test the validator outside the build dir
run: |
cp _build/KSPMMCfgValidator/Debug/bin/net461/KSPMMCfgValidator.exe .
cp _build/KSPMMCfgValidator/Debug/bin/net48/Repack/KSPMMCfgValidator.exe .
chmod a+x KSPMMCfgValidator.exe
mono ./KSPMMCfgValidator.exe
Expand All @@ -42,6 +48,6 @@ jobs:
uses: actions/upload-artifact@v2
with:
name: KSPMMCfgValidator.exe
path: _build/KSPMMCfgValidator/Debug/bin/net461/KSPMMCfgValidator.exe
path: _build/KSPMMCfgValidator/Debug/bin/net48/Repack/KSPMMCfgValidator.exe
retention-days: 7
if: github.event_name == 'pull_request'
12 changes: 9 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ jobs:
run: apt-get update && apt-get install -y wget jq
- name: Checkout
uses: actions/checkout@v3
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7'
- name: Restore, build, and test
run: msbuild -r -p:configuration=Release
run: |
msbuild -r -p:configuration=Debug -p:TargetFramework=net48
dotnet build -f net7.0
- name: Smoke test the validator outside the build dir
run: |
cp _build/KSPMMCfgValidator/Release/bin/net461/KSPMMCfgValidator.exe .
cp _build/KSPMMCfgValidator/Release/bin/net48/Repack/KSPMMCfgValidator.exe .
chmod a+x KSPMMCfgValidator.exe
mono ./KSPMMCfgValidator.exe
Expand All @@ -46,7 +52,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.release_data.outputs.upload_url }}
asset_path: _build/KSPMMCfgValidator/Release/bin/net461/KSPMMCfgValidator.exe
asset_path: _build/KSPMMCfgValidator/Release/bin/net48/Repack/KSPMMCfgValidator.exe
asset_name: KSPMMCfgValidator.exe
asset_content_type: application/vnd.microsoft.portable-executable

Expand Down
12 changes: 6 additions & 6 deletions KSPMMCfgParser/KSPMMCfgParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
<Prefer32Bit>false</Prefer32Bit>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<TargetFramework>net461</TargetFramework>
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworks>net48;net7.0</TargetFrameworks>
<Optimize>true</Optimize>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DebugSymbols>false</DebugSymbols>
Expand All @@ -42,12 +40,14 @@
<RepositoryUrl>https://github.com/KSP-CKAN/KSPMMCfgParser</RepositoryUrl>
<RepositoryType>git</RepositoryType>
</PropertyGroup>
<ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net48' ">
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Transactions" />
<PackageReference Include="log4net" Version="2.0.10" />
<PackageReference Include="ParsecSharp" Version="3.4.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="ParsecSharp" Version="3.5.0" />
</ItemGroup>
<ItemGroup>
<None Include="../README.md" Pack="true" PackagePath="\"/>
Expand Down
17 changes: 16 additions & 1 deletion KSPMMCfgValidator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
FROM mono:latest
FROM ubuntu:latest

# Don't prompt for time zone
ENV DEBIAN_FRONTEND=noninteractive

# Set up Mono's APT repo
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates gnupg \
&& gpg --homedir /tmp --no-default-keyring --keyring /usr/share/keyrings/mono-official-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \
&& echo "deb [signed-by=/usr/share/keyrings/mono-official-archive-keyring.gpg] https://download.mono-project.com/repo/ubuntu stable-focal main" | tee /etc/apt/sources.list.d/mono-official-stable.list \
&& apt-get update

# Install the necessary pieces of Mono
RUN apt-get install -y --no-install-recommends \
mono-runtime ca-certificates-mono libmono-microsoft-csharp4.0-cil libmono-system-data4.0-cil libmono-system-runtime-serialization4.0-cil libmono-system-transactions4.0-cil libmono-system-net-http-webrequest4.0-cil

ADD KSPMMCfgValidator.exe /usr/local/bin/.
ENTRYPOINT ["mono", "/usr/local/bin/KSPMMCfgValidator.exe"]
66 changes: 42 additions & 24 deletions KSPMMCfgValidator/KSPMMCfgValidator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,60 @@
<Prefer32Bit>false</Prefer32Bit>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<TargetFramework>net461</TargetFramework>
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworks>net48;net7.0</TargetFrameworks>
<Optimize>true</Optimize>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DebugSymbols>false</DebugSymbols>
<DebugType>None</DebugType>
<DocumentationFile>$(BaseIntermediateOutputPath)$(AssemblyName).xml</DocumentationFile>
<NoWarn>NU1701</NoWarn>
<CoreCompileDependsOn>PrepareResources;$(CompileDependsOn)</CoreCompileDependsOn>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<PackageReference Include="CommandLineParser" Version="1.9.71" />
<PackageReference Include="log4net" Version="2.0.10" />
<PackageReference Include="ParsecSharp" Version="3.4.0"
PrivateAssets="All" />
<PackageReference Include="ILRepack" Version="2.0.18" />
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="ParsecSharp" Version="3.5.0" />
<PackageReference Include="ILRepack.MSBuild.Task" Version="2.0.13"
PrivateAssets="All"/>
<ProjectReference Include="..\KSPMMCfgParser\KSPMMCfgParser.csproj" />
GeneratePathProperty="true"
PrivateAssets="All" />
<ProjectReference Include="..\KSPMMCfgParser\KSPMMCfgParser.csproj">
<SetTargetFramework>TargetFramework=$(TargetFramework)</SetTargetFramework>
</ProjectReference>
<ProjectReference Include="..\Tests\Tests.csproj"
ReferenceOutputAssembly="false" />
ReferenceOutputAssembly="false">
<Private>false</Private>
<SetTargetFramework>TargetFramework=$(TargetFramework)</SetTargetFramework>
</ProjectReference>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>MSBuild:Compile</Generator>
<LastGenOutput>$(IntermediateOutputPath)Resources.Designer.cs</LastGenOutput>
<StronglyTypedFileName>$(IntermediateOutputPath)Resources.Designer.cs</StronglyTypedFileName>
<StronglyTypedLanguage>$(Language)</StronglyTypedLanguage>
<StronglyTypedNamespace>$(RootNamespace).Properties</StronglyTypedNamespace>
<StronglyTypedClassName>%(Filename)</StronglyTypedClassName>
</EmbeddedResource>
</ItemGroup>
<Target Name="UseOurResourceManager" AfterTargets="PrepareResources">
<WriteLinesToFile File="$(IntermediateOutputPath)Resources.Designer.cs"
Lines="$([System.IO.File]::ReadAllText('$(IntermediateOutputPath)Resources.Designer.cs')
.Replace('new global::System.Resources.ResourceManager', 'new SingleAssemblyResourceManager')
.Replace('internal', 'public')
.Replace(' [global::System.Diagnostics.CodeAnalysis', $([System.String]::Join('%0d%0a', '/// &lt;summary&gt;', '/// Constructor', '/// &lt;/summary&gt;', ' [global::System.Diagnostics.CodeAnalysis'))))"
Overwrite="true" />
</Target>
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
<Target Name="ILRepack" AfterTargets="Build" DependsOnTargets="Build">
<ItemGroup>
<InputAssemblies Include="log4net.dll" />
<InputAssemblies Include="CommandLine.dll" />
<InputAssemblies Include="ParsecSharp.dll" />
<InputAssemblies Include="KSPMMCfgParser.dll" />
</ItemGroup>
<ILRepack OutputAssembly="$(AssemblyName).exe"
MainAssembly="$(AssemblyName).exe"
InputAssemblies="@(InputAssemblies)"
OutputType="$(OutputType)"
WorkingDirectory="$(OutputPath)"
Internalize="true"
Parallel="true" />
<Target Condition=" '$(TargetFramework)' == 'net48' "
Name="ILRepack"
AfterTargets="Build"
DependsOnTargets="Build">
<Message Text="Repacking $(OutputPath)Repack\$(AssemblyName).exe"
Importance="high" />
<Message Text="Logging to $(OutputPath)ILRepack.log"
Importance="high" />
<Exec WorkingDirectory="$(OutputPath)"
Command="$(PkgILRepack_MSBuild_Task)\tools\ilrepack.exe /parallel /internalize /wildcards /targetplatform:v4 /log:ILRepack.log /out:Repack\$(AssemblyName).exe $(AssemblyName).exe *.dll"
EchoOff="true"
StandardOutputImportance="low" />
</Target>
</Project>
69 changes: 0 additions & 69 deletions KSPMMCfgValidator/Properties/Resources.Designer.cs

This file was deleted.

37 changes: 26 additions & 11 deletions KSPMMCfgValidator/SingleAssemblyResourceManager.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,56 @@
using System.IO;
using System.Globalization;
using System.Resources;
using System.Collections;
using System.Reflection;
using System.Collections.Generic;

namespace KSPMMCfgValidator
{
// Thanks and credit to this guy: https://stackoverflow.com/q/1952638/2422988

class SingleAssemblyResourceManager : ResourceManager
/// <summary>
/// Wrapper around ResourceManager that retrieves strings from the assembly
/// rather than external files
/// </summary>
public class SingleAssemblyResourceManager : ResourceManager
{
public SingleAssemblyResourceManager(string basename, Assembly assembly) : base(basename, assembly)
/// <summary>
/// Initialize the resource manager
/// </summary>
/// <param name="basename">To be passed to ResourceManager</param>
/// <param name="assembly">To be passed to ResourceManager</param>
public SingleAssemblyResourceManager(string basename, Assembly assembly)
: base(basename, assembly)
{
}

protected override ResourceSet InternalGetResourceSet(CultureInfo culture,
/// <summary>
/// Provides resources from the assembly to ResourceManager
/// </summary>
/// <param name="culture">The language to get</param>
/// <param name="createIfNotExists">Set to false to avoid loading if not already cached</param>
/// <param name="tryParents">Just gets passed to base class implementation</param>
/// <returns></returns>
protected override ResourceSet? InternalGetResourceSet(CultureInfo culture,
bool createIfNotExists, bool tryParents)
{
ResourceSet rs;
if (!myResourceSets.TryGetValue(culture, out rs))
if (!myResourceSets.TryGetValue(culture, out ResourceSet? rs))
{
// Lazy-load default language (without caring about duplicate assignment in race conditions, no harm done)
if (neutralResourcesCulture == null)
if (MainAssembly != null)
{
neutralResourcesCulture = GetNeutralResourcesLanguage(this.MainAssembly);
neutralResourcesCulture ??= GetNeutralResourcesLanguage(MainAssembly);
}

// If we're asking for the default language, then ask for the
// invariant (non-specific) resources.
if (neutralResourcesCulture.Equals(culture))
if (neutralResourcesCulture?.Equals(culture) ?? true)
{
culture = CultureInfo.InvariantCulture;
}
string resourceFileName = GetResourceFileName(culture);

Stream store = this.MainAssembly.GetManifestResourceStream(resourceFileName);
Stream? store = MainAssembly?.GetManifestResourceStream(resourceFileName);

// If we found the appropriate resources in the local assembly
if (store != null)
Expand All @@ -53,6 +68,6 @@ protected override ResourceSet InternalGetResourceSet(CultureInfo culture,
}

private CultureInfo? neutralResourcesCulture;
private Dictionary<CultureInfo, ResourceSet> myResourceSets = new Dictionary<CultureInfo, ResourceSet>();
private readonly Dictionary<CultureInfo, ResourceSet> myResourceSets = new Dictionary<CultureInfo, ResourceSet>();
}
}
43 changes: 25 additions & 18 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project>
<Project>
<PropertyGroup>
<AssemblyName>KSPMMCfgParser.Tests</AssemblyName>
<OutputPath>..\_build\$(AssemblyName)\$(Configuration)\bin\</OutputPath>
Expand All @@ -17,32 +17,39 @@
<Prefer32Bit>false</Prefer32Bit>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<TargetFramework>net461</TargetFramework>
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworks>net48;net7.0</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net48' ">
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Transactions" />
<Reference Include="System.Windows.Forms" />
<PackageReference Include="Castle.Core" Version="4.4.1" />
<PackageReference Include="log4net" Version="2.0.10" />
<PackageReference Include="Moq" Version="4.14.5" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="NUnit.ConsoleRunner" Version="3.12.0"
GeneratePathProperty="true" />
<PackageReference Include="MSBuildTasks" Version="1.5.0.235" />
<PackageReference Include="ParsecSharp" Version="3.4.0"
</ItemGroup>
<ItemGroup>
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="NUnit" Version="3.14.0"
PrivateAssets="All" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0"
PrivateAssets="All" />
<ProjectReference Include="..\KSPMMCfgParser\KSPMMCfgParser.csproj" />
<PackageReference Include="NUnit.ConsoleRunner" Version="3.16.3"
PrivateAssets="All"
GeneratePathProperty="true" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"
PrivateAssets="All"/>
<PackageReference Include="ParsecSharp" Version="3.5.0" />
<ProjectReference Include="..\KSPMMCfgParser\KSPMMCfgParser.csproj">
<SetTargetFramework>TargetFramework=$(TargetFramework)</SetTargetFramework>
</ProjectReference>
</ItemGroup>
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
<Target Name="Test" AfterTargets="Build" DependsOnTargets="Build">
<Exec EchoOff="true"
<Target Name="Test" AfterTargets="Build" DependsOnTargets="Build"
Condition=" '$(PkgNUnit_ConsoleRunner)' != '' ">
<Exec Condition=" '$(OS)' == 'Windows_NT' "
EchoOff="true"
Command="$(PkgNUnit_ConsoleRunner)\tools\nunit3-console.exe $(OutputPath)$(TargetFileName) --work=$(OutputPath)" />
<Exec Condition=" '$(OS)' == 'Unix' "
EchoOff="true"
Command="mono $(PkgNUnit_ConsoleRunner)/tools/nunit3-console.exe $(OutputPath)$(TargetFileName) --work=$(OutputPath)" />
</Target>
</Project>
Loading

0 comments on commit 341469e

Please sign in to comment.