0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 05:30:43 -05:00
modules/project/build.cake
Merijn Hendriks 820619b0dc [critical] Fix .NET Framework version (!42)
## Preface

The current version of Aki uses .NET Framework 4.7.2, C# 7.3.

However, this is not correct. Unity 2019.4.31f uses .NET Framework 4.7.1, C# 7.0 (you can see this when creating a new blank project in this unity version, then check the Assembly-CSharp.csproj).

You can load netstandard2.0 assemblies into EFT, which support C# 7.3.

## The issue

.NET Core 2.1 support types like `Span<T>` and `ReadOnlySpan<T>` which previous versions of .NET (.NET Core 2.0 / .NET Framework 4.8.1 and below, C# 7.1 and below) need to support through the `System.Memory` nuget package. Right now, this conflicts.

If you attempt to load an assembly like this, EFT will simply crash because `Span<T>` and `ReadOnlySpan<T>` do not exist inside mono's `mscorlib`.

## Why fix this

This is important for a variety of reasons:

- Prevent modders from accessing not available APIs leading to unexpected crashes
- Prevent possible compatability issues with EFT later
- Support for `Span<T>` and `ReadOnlySpan<T>` through `System.Memory` which is important for high-performance code and client mods (one of which I'm working on).

I really want to stress that this is an important issue to fix and should be merged ASAP. Unity 2019.4 being lax doesn't mean the next LTS version won't prevent loading.

## Why was the wrong version in the first place?

It was a best guess made by me 2 years ago. There were more pressing issues back then and it didn't crash on me. It started becoming an issue 1 year ago when I tried to port Aki to C#, because self-signed certificate generation is supported only within 4.7.2 and newer.

For reference: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.x509certificates.certificaterequest.createselfsigned?view=netframework-4.7.2

## What's affected?

All the `.csproj` files in this repo.

Merging this means that some mods might need to retarget from .NET Framework 4.7.2 to 4.7.1.

Co-authored-by: Dev <dev@dev.sp-tarkov.com>
Co-authored-by: Terkoiz <terkoiz@spt.dev>
Co-authored-by: Terkoiz <terkoiz@noreply.dev.sp-tarkov.com>
Co-authored-by: DanW <danw@noreply.dev.sp-tarkov.com>
Co-authored-by: Merijn Hendriks <merijn.d.hendriks@gmail.com>
Reviewed-on: SPT-AKI/Modules#42
Co-authored-by: Merijn Hendriks <senko-san@noreply.dev.sp-tarkov.com>
Co-committed-by: Merijn Hendriks <senko-san@noreply.dev.sp-tarkov.com>
2023-12-09 16:32:45 +00:00

107 lines
3.7 KiB
C#

string target = Argument<string>("target", "ExecuteBuild");
bool VSBuilt = Argument<bool>("vsbuilt", false);
#addin nuget:?package=Cake.FileHelpers&version=5.0.0
// Cake API Reference: https://cakebuild.net/dsl/
// setup variables
var buildDir = "./Build";
var delPaths = GetDirectories("./**/*(obj|bin)");
var licenseFile = "../LICENSE.md";
var managedFolder = string.Format("{0}/{1}/{2}", buildDir, "EscapeFromTarkov_Data", "Managed");
var bepInExPluginsFolder = string.Format("{0}/{1}/{2}", buildDir, "BepInEx", "plugins");
var bepInExPluginsSptFolder = string.Format("{0}/{1}", bepInExPluginsFolder, "spt");
var bepInExPatchersFolder = string.Format("{0}/{1}/{2}", buildDir, "BepInEx", "patchers");
var solutionPath = "./Modules.sln";
Setup(context =>
{
//building from VS will lock the files and fail to clean the project directories. Post-Build event on Aki.Build sets this switch to true to avoid this.
FileWriteText("./vslock", "lock");
});
Teardown(context =>
{
if(FileExists("./vslock"))
{
DeleteFile("./vslock"); //remove vslock file
}
});
// Clean build directory and remove obj / bin folder from projects
Task("Clean")
.WithCriteria(!VSBuilt)
.Does(() =>
{
CleanDirectory(buildDir);
})
.DoesForEach(delPaths, (directoryPath) =>
{
DeleteDirectory(directoryPath, new DeleteDirectorySettings
{
Recursive = true,
Force = true
});
});
// Build solution
Task("Build")
.IsDependentOn("Clean")
.WithCriteria(!FileExists("./vslock")) // check for lock file if running from VS
.Does(() =>
{
DotNetBuild(solutionPath, new DotNetBuildSettings
{
Configuration = "Release"
});
});
// Copy modules, managed dlls, and license to the build folder
Task("CopyBuildData")
.IsDependentOn("Build")
.Does(() =>
{
CleanDirectory(buildDir);
CreateDirectory(managedFolder);
CreateDirectory(bepInExPluginsFolder);
CreateDirectory(bepInExPluginsSptFolder);
CreateDirectory(bepInExPatchersFolder);
CopyFile(licenseFile, string.Format("{0}/LICENSE-Modules.txt", buildDir));
})
.DoesForEach(GetFiles("./Aki.*/bin/Release/net471/*.dll"), (dllPath) => //copy modules
{
if(dllPath.GetFilename().ToString().StartsWith("aki_"))
{
//Incase you want to see what is being copied for debuging
//Spectre.Console.AnsiConsole.WriteLine(string.Format("Adding Module: {0}", dllPath.GetFilename()));
string patcherTransferPath = string.Format("{0}/{1}", bepInExPatchersFolder, dllPath.GetFilename());
CopyFile(dllPath, patcherTransferPath);
}
if(dllPath.GetFilename().ToString().StartsWith("aki-"))
{
//Incase you want to see what is being copied for debuging
//Spectre.Console.AnsiConsole.WriteLine(string.Format("Adding Module: {0}", dllPath.GetFilename()));
string moduleTransferPath = string.Format("{0}/{1}", bepInExPluginsSptFolder, dllPath.GetFilename());
CopyFile(dllPath, moduleTransferPath);
}
else if (dllPath.GetFilename().ToString().StartsWith("Aki.")) // Only copy the custom-built dll's to Managed
{
//Incase you want to see what is being copied for debuging
//Spectre.Console.AnsiConsole.WriteLine(string.Format("Adding managed dll: {0}", dllPath.GetFilename()));
string fileTransferPath = string.Format("{0}/{1}", managedFolder, dllPath.GetFilename());
CopyFile(dllPath, fileTransferPath);
}
});
// Runs all build tasks based on dependency and configuration
Task("ExecuteBuild")
.IsDependentOn("CopyBuildData");
// Runs target task
RunTarget(target);