migrate mod build package to .NET 5 to allow full nullable annotations (#837)

This commit is contained in:
Jesse Plamondon-Willard 2022-04-07 01:51:50 -04:00
parent e58e8a2283
commit 6b05296e71
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
10 changed files with 16 additions and 58 deletions

View File

@ -413,9 +413,19 @@ when you compile it.
## Release notes
## Upcoming release
* Migrated from .NET Standard 2.0 to .NET 5.0.
* Added detection for Xbox app game folders.
* Internal refactoring.
**Troubleshooting:**
Due to the framework change, you might see build errors like _task failed unexpectedly_ that mentions `System.Runtime Version=5.0.0`. If so:
1. Make sure you have Visual Studio 2022 or later.
2. Exit all instances of Visual Studio.
3. Delete the hidden `.vs` folder in your solution folder.
4. Delete the `bin` and `obj` folders in each project folder.
5. Reopen the solution and rebuild, and now it should work fine.
## 4.0.0
Released 30 November 2021.

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<RootNamespace>StardewModdingAPI.ModBuildConfig.Analyzer</RootNamespace>
<Version>3.0.0</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<IncludeBuildOutput>false</IncludeBuildOutput>
<OutputPath>bin</OutputPath>
<LangVersion>latest</LangVersion>

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<!--build-->
<RootNamespace>StardewModdingAPI.ModBuildConfig</RootNamespace>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<RootNamespace>StardewModdingAPI</RootNamespace>
<Description>Provides toolkit interfaces which are available to SMAPI mods.</Description>
<TargetFrameworks>net5.0; netstandard2.0</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<RootNamespace>StardewModdingAPI.Toolkit</RootNamespace>
<Description>A library which encapsulates mod-handling logic for mod managers and tools. Not intended for use by mods.</Description>
<TargetFrameworks>net5.0; netstandard2.0</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

View File

@ -198,12 +198,7 @@ namespace StardewModdingAPI.Toolkit
/// <param name="version">The version string.</param>
/// <param name="parsed">The parsed representation.</param>
/// <returns>Returns whether parsing the version succeeded.</returns>
public static bool TryParse(string? version,
#if NET5_0_OR_GREATER
[NotNullWhen(true)]
#endif
out ISemanticVersion? parsed
)
public static bool TryParse(string? version, [NotNullWhen(true)] out ISemanticVersion? parsed)
{
return SemanticVersion.TryParse(version, allowNonStandard: false, out parsed);
}
@ -213,12 +208,7 @@ namespace StardewModdingAPI.Toolkit
/// <param name="allowNonStandard">Whether to allow non-standard extensions to semantic versioning.</param>
/// <param name="parsed">The parsed representation.</param>
/// <returns>Returns whether parsing the version succeeded.</returns>
public static bool TryParse(string? version, bool allowNonStandard,
#if NET5_0_OR_GREATER
[NotNullWhen(true)]
#endif
out ISemanticVersion? parsed
)
public static bool TryParse(string? version, bool allowNonStandard, [NotNullWhen(true)] out ISemanticVersion? parsed)
{
if (version == null)
{

View File

@ -115,9 +115,7 @@ namespace StardewModdingAPI.Toolkit.Serialization.Models
*********/
/// <summary>Normalize whitespace in a raw string.</summary>
/// <param name="input">The input to strip.</param>
#if NET5_0_OR_GREATER
[return: NotNullIfNotNull("input")]
#endif
private string? NormalizeWhitespace(string? input)
{
return input

View File

@ -33,9 +33,7 @@ namespace StardewModdingAPI.Toolkit.Serialization.Models
*********/
/// <summary>Normalize whitespace in a raw string.</summary>
/// <param name="input">The input to strip.</param>
#if NET5_0_OR_GREATER
[return: NotNullIfNotNull("input")]
#endif
private string? NormalizeWhitespace(string? input)
{
return input?.Trim();

View File

@ -54,9 +54,7 @@ namespace StardewModdingAPI.Toolkit.Serialization.Models
*********/
/// <summary>Normalize whitespace in a raw string.</summary>
/// <param name="input">The input to strip.</param>
#if NET5_0_OR_GREATER
[return: NotNullIfNotNull("input")]
#endif
private string? NormalizeWhitespace(string? input)
{
return input?.Trim();

View File

@ -92,43 +92,7 @@ namespace StardewModdingAPI.Toolkit.Utilities
[Pure]
public static string GetRelativePath(string sourceDir, string targetPath)
{
#if NET5_0
return Path.GetRelativePath(sourceDir, targetPath);
#else
// NOTE:
// this is a heuristic implementation that works in the cases SMAPI needs it for, but it
// doesn't handle all edge cases (e.g. case-sensitivity on Linux, or traversing between
// UNC paths on Windows). SMAPI and mods will use the more robust .NET 5 version anyway
// though, this is only for compatibility with the mod build package.
// convert to URIs
Uri from = new(sourceDir.TrimEnd(PathUtilities.PossiblePathSeparators) + "/");
Uri to = new(targetPath.TrimEnd(PathUtilities.PossiblePathSeparators) + "/");
if (from.Scheme != to.Scheme)
throw new InvalidOperationException($"Can't get path for '{targetPath}' relative to '{sourceDir}'.");
// get relative path
string rawUrl = Uri.UnescapeDataString(from.MakeRelativeUri(to).ToString());
if (rawUrl.StartsWith("file://"))
rawUrl = PathUtilities.WindowsUncRoot + rawUrl.Substring("file://".Length);
string relative = PathUtilities.NormalizePath(rawUrl);
// normalize
if (relative == "")
relative = ".";
else
{
// trim trailing slash from URL
if (relative.EndsWith(PathUtilities.PreferredPathSeparator.ToString()))
relative = relative.Substring(0, relative.Length - 1);
// fix root
if (relative.StartsWith("file:") && !targetPath.Contains("file:"))
relative = relative.Substring("file:".Length);
}
return relative;
#endif
}
/// <summary>Get whether a path is relative and doesn't try to climb out of its containing folder (e.g. doesn't contain <c>../</c>).</summary>