Skip to content

Commit

Permalink
Updated: Modernised Projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Oct 10, 2022
1 parent 6c208c1 commit 3354fcc
Show file tree
Hide file tree
Showing 35 changed files with 1,345 additions and 237 deletions.
85 changes: 63 additions & 22 deletions Publish.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
Full or relative path to a file containing the changelog for the mod.
The changelog should be written in Markdown format.
.PARAMETER ReadmePath
Full or relative path to a file containing the changelog for the mod.
The changelog should be written in Markdown format.
.PARAMETER IsPrerelease
Default: $False
Expand Down Expand Up @@ -125,7 +129,17 @@
Whether the project should be built.
Setting this to false lets you use the publish part of the script standalone in a non .NET environment.
.PARAMETER RemoveExe
Default: $True
Removes executables from build output. Useful when performing R2R Optimisation.
.PARAMETER UseScriptDirectory
Default: $True
Uses script directory for performing build. Otherwise uses current directory.
.EXAMPLE
.\Publish.ps1 -ProjectPath "Reloaded.Hooks.ReloadedII/Reloaded.Hooks.ReloadedII.csproj" -PackageName "Reloaded.Hooks.ReloadedII" -PublishOutputDir "Publish/ToUpload"
Expand All @@ -141,29 +155,32 @@ param (
$IsPrerelease=$False,
$MakeDelta=$False,
$ChangelogPath="",
$ReadmePath="",
$Build=$True,
$BuildR2R=$False,

$RemoveExe=$True,
$UseScriptDirectory=$True,

## => User Config <= ##
$ProjectPath = "Reloaded.Hooks.ReloadedII/Reloaded.Hooks.ReloadedII.csproj",
$PackageName = "Reloaded.Hooks.ReloadedII",
$ProjectPath = "Reloaded.Universal.Monitor.csproj",
$PackageName = "Reloaded.Universal.Monitor",
$PublishOutputDir = "Publish/ToUpload",

## => User: Delta Config
# Pick one and configure settings below.
$MetadataFileName = "Sewer56.Update.ReleaseMetadata.json",
$UseGitHubDelta = $True,
$UseGitHubDelta = $False, # GitHub Releases
$UseGameBananaDelta = $False,
$UseNuGetDelta = $False,

$GitHubUserName = "Sewer56",
$GitHubRepoName = "Reloaded.SharedLib.Hooks.ReloadedII",
$GitHubFallbackPattern = "reloaded.sharedlib.hooks.zip", # For migrating from legacy.
$GitHubUserName = "", # Name of the GitHub user where the mod is contained
$GitHubRepoName = "", # Name of the GitHub repo where the mod is contained
$GitHubFallbackPattern = "", # For migrating from legacy build script.
$GitHubInheritVersionFromTag = $True, # Uses version determined from release tag as opposed to metadata file in latest release.

$GameBananaItemId = 333681, # From mod page URL.

$NuGetPackageId = "reloaded.sharedlib.hooks",
$NuGetPackageId = "Reloaded.Universal.Monitor",
$NuGetFeedUrl = "http://packages.sewer56.moe:5000/v3/index.json",
$NuGetAllowUnlisted = $False,

Expand All @@ -187,17 +204,25 @@ $reloadedToolsPath = "./Publish/Tools/Reloaded-Tools" # Used to check if tool
$updateToolsPath = "./Publish/Tools/Update-Tools" # Used to check if update tools are installed.
$reloadedToolPath = "$reloadedToolsPath/Reloaded.Publisher.exe" # Path to Reloaded publishing tool.
$updateToolPath = "$updateToolsPath/Sewer56.Update.Tool.dll" # Path to Update tool.
$changelogFullPath = $null
$readmeFullPath = $null
if ($ChangelogPath) { $changelogFullPath = [System.IO.Path]::GetFullPath($ChangelogPath) }
if ($ReadmePath) { $readmeFullPath = [System.IO.Path]::GetFullPath($ReadmePath) }

## => Script <= ##
# Set Working Directory
Split-Path $MyInvocation.MyCommand.Path | Push-Location
[Environment]::CurrentDirectory = $PWD
$UseScriptDirectory = [bool]::Parse($UseScriptDirectory)
if ($UseScriptDirectory) {
Split-Path $MyInvocation.MyCommand.Path | Push-Location
[Environment]::CurrentDirectory = $PWD
}

# Convert Booleans
$IsPrerelease = [bool]::Parse($IsPrerelease)
$MakeDelta = [bool]::Parse($MakeDelta)
$Build = [bool]::Parse($Build)
$BuildR2R = [bool]::Parse($BuildR2R)
$RemoveExe = [bool]::Parse($RemoveExe)
$UseGitHubDelta = [bool]::Parse($UseGitHubDelta)
$UseGameBananaDelta = [bool]::Parse($UseGameBananaDelta)
$UseNuGetDelta = [bool]::Parse($UseNuGetDelta)
Expand All @@ -206,26 +231,28 @@ $PublishGeneric = [bool]::Parse($PublishGeneric)
$PublishNuGet = [bool]::Parse($PublishNuGet)
$PublishGameBanana = [bool]::Parse($PublishGameBanana)
$GitHubInheritVersionFromTag = [bool]::Parse($GitHubInheritVersionFromTag)
$TempDirectory = [System.IO.Path]::GetTempPath() + [System.IO.Path]::GetRandomFileName()
$TempDirectoryBuild = "$TempDirectory/build"

function Get-Tools {
# Download Tools (if needed)
$ProgressPreference = 'SilentlyContinue'
if (-not(Test-Path -Path $reloadedToolsPath -PathType Any)) {
Write-Host "Downloading Reloaded Tools"
Invoke-WebRequest -Uri "https://github.com/Reloaded-Project/Reloaded-II/releases/latest/download/Tools.zip" -OutFile "$env:TEMP/Tools.zip"
Expand-Archive -LiteralPath "$env:TEMP/Tools.zip" -DestinationPath $reloadedToolsPath
Invoke-WebRequest -Uri "https://github.com/Reloaded-Project/Reloaded-II/releases/latest/download/Tools.zip" -OutFile "$TempDirectory/Tools.zip"
Expand-Archive -LiteralPath "$TempDirectory/Tools.zip" -DestinationPath $reloadedToolsPath

# Remove Items
Remove-Item "$env:TEMP/Tools.zip" -ErrorAction SilentlyContinue
Remove-Item "$TempDirectory/Tools.zip" -ErrorAction SilentlyContinue
}

if ($MakeDelta -and -not(Test-Path -Path $updateToolsPath -PathType Any)) {
Write-Host "Downloading Update Library Tools"
Invoke-WebRequest -Uri "https://github.com/Sewer56/Update/releases/latest/download/Sewer56.Update.Tool.zip" -OutFile "$env:TEMP/Sewer56.Update.Tool.zip"
Expand-Archive -LiteralPath "$env:TEMP/Sewer56.Update.Tool.zip" -DestinationPath $updateToolsPath
Invoke-WebRequest -Uri "https://github.com/Sewer56/Update/releases/latest/download/Sewer56.Update.Tool.zip" -OutFile "$TempDirectory/Sewer56.Update.Tool.zip"
Expand-Archive -LiteralPath "$TempDirectory/Sewer56.Update.Tool.zip" -DestinationPath $updateToolsPath

# Remove Items
Remove-Item "$env:TEMP/Sewer56.Update.Tool.zip" -ErrorAction SilentlyContinue
Remove-Item "$TempDirectory/Sewer56.Update.Tool.zip" -ErrorAction SilentlyContinue
}
}

Expand All @@ -240,8 +267,8 @@ function Build {
dotnet clean $ProjectPath

if ($BuildR2R) {
dotnet publish $ProjectPath -c Release -r win-x86 --self-contained false -o "$publishBuildDirectory/x86" /p:PublishReadyToRun=true
dotnet publish $ProjectPath -c Release -r win-x64 --self-contained false -o "$publishBuildDirectory/x64" /p:PublishReadyToRun=true
dotnet publish $ProjectPath -c Release -r win-x86 --self-contained false -o "$publishBuildDirectory/x86" /p:PublishReadyToRun=true /p:OutputPath="$TempDirectoryBuild/x86"
dotnet publish $ProjectPath -c Release -r win-x64 --self-contained false -o "$publishBuildDirectory/x64" /p:PublishReadyToRun=true /p:OutputPath="$TempDirectoryBuild/x64"

# Remove Redundant Files
Move-Item -Path "$publishBuildDirectory/x86/ModConfig.json" -Destination "$publishBuildDirectory/ModConfig.json" -ErrorAction SilentlyContinue
Expand All @@ -250,11 +277,15 @@ function Build {
Remove-Item "$publishBuildDirectory/x64/ModConfig.json" -ErrorAction SilentlyContinue
}
else {
dotnet publish $ProjectPath -c Release --self-contained false -o "$publishBuildDirectory"
dotnet publish $ProjectPath -c Release --self-contained false -o "$publishBuildDirectory" /p:OutputPath="$TempDirectoryBuild"
}

# Cleanup Unnecessary Files
Get-ChildItem $publishBuildDirectory -Include *.exe -Recurse | Remove-Item -Force -Recurse
Remove-Item $TempDirectoryBuild -Recurse -ErrorAction SilentlyContinue
if ($RemoveExe) {
Get-ChildItem $publishBuildDirectory -Include *.exe -Recurse | Remove-Item -Force -Recurse
}

Get-ChildItem $publishBuildDirectory -Include *.pdb -Recurse | Remove-Item -Force -Recurse
Get-ChildItem $publishBuildDirectory -Include *.xml -Recurse | Remove-Item -Force -Recurse
}
Expand Down Expand Up @@ -286,7 +317,11 @@ function Get-Common-Publish-Args {

$arguments = "--modfolder `"$publishBuildDirectory`" --packagename `"$PackageName`""
if ($ChangelogPath) {
$arguments += " --changelogpath `"$ChangelogPath`""
$arguments += " --changelogpath `"$changelogFullPath`""
}

if ($ReadmePath) {
$arguments += " --readmepath `"$readmeFullPath`""
}

if ($AllowDeltas -and $MakeDelta) {
Expand Down Expand Up @@ -333,6 +368,7 @@ function Cleanup {
}

# Build & Publish
New-Item $TempDirectory -ItemType Directory -ErrorAction SilentlyContinue
Cleanup
Get-Tools

Expand Down Expand Up @@ -361,7 +397,12 @@ if ($PublishGameBanana) {
Publish-GameBanana
}

# Remove Temp Folder
Remove-Item $TempDirectory -Recurse -ErrorAction SilentlyContinue

# Restore Working Directory
Write-Host "Done."
Write-Host "Upload the files in folder `"$PublishOutputDir`" to respective location or website."
Pop-Location
if ($UseScriptDirectory) {
Pop-Location
}
143 changes: 143 additions & 0 deletions Reloaded.Trimming.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
<!--
Originally inspired by https://github.com/space-wizards/RobustToolbox , under the MIT License
Modified by Sewer56 to include support for .NET6 IsTrimmable property.
-->

<!--
Stuff for using ILLink trimming without self-contained deployments.
This is not something officially supported by the .NET SDK currently, but we can simply run ILLink ourselves.
A lot of stuff taken from Microsoft.NET.ILLink.targets in the SDK files.
-->

<ItemDefinitionGroup>
<ReloadedLinkRoots>
<Visible>false</Visible>
</ReloadedLinkRoots>
<ReloadedLinkAssemblies>
<Visible>false</Visible>
</ReloadedLinkAssemblies>
</ItemDefinitionGroup>

<Target Name="ReloadedILLink"
BeforeTargets="ILLink"
Condition="'$(PublishTrimmed)' != 'true' And
'$(ReloadedILLink)' == 'true'"
DependsOnTargets="_ComputeAssembliesToPostprocessOnPublish">

<!-- Original Target: ComputeManagedAssemblyToLink -->
<ComputeManagedAssemblies Assemblies="@(ResolvedFileToPublish->WithMetadataValue('PostprocessAssembly', 'true'))">
<Output TaskParameter="ManagedAssemblies" ItemName="ManagedAssemblyToLink" />
</ComputeManagedAssemblies>

<ItemGroup>
<!-- The linker implicitly picks up PDBs next to input assemblies. We will filter these out of the publish set. -->
<__PDBToLink Include="@(ResolvedFileToPublish)" Exclude="@(ManagedAssemblyToLink->'%(RelativeDir)%(Filename).pdb')" />
<_PDBToLink Include="@(ResolvedFileToPublish)" Exclude="@(__PDBToLink)" />
</ItemGroup>

<ItemGroup>
<_LinkedResolvedFileToPublishCandidate Include="@(ManagedAssemblyToLink->'$(IntermediateLinkDir)%(Filename)%(Extension)')" />
<_LinkedResolvedFileToPublishCandidate Include="@(_PDBToLink->'$(IntermediateLinkDir)%(Filename)%(Extension)')" />
</ItemGroup>

<!-- Original Target: PrepareForILLink -->
<!-- Set IsTrimmable for any assemblies that already have customized TrimMode. -->
<ItemGroup>
<ManagedAssemblyToLink>
<IsTrimmable>true</IsTrimmable>
</ManagedAssemblyToLink>
</ItemGroup>

<PropertyGroup>
<TrimMode Condition=" '$(TrimMode)' == '' ">link</TrimMode>
<!-- For .NET 6+, assemblies without IsTrimmable attribute get the "copy" action. -->
<TrimmerDefaultAction Condition=" '$(TrimmerDefaultAction)' == '' ">copy</TrimmerDefaultAction>
<ILLinkTreatWarningsAsErrors Condition=" '$(ILLinkTreatWarningsAsErrors)' == '' ">$(TreatWarningsAsErrors)</ILLinkTreatWarningsAsErrors>
<_ExtraTrimmerArgs>--skip-unresolved true $(_ExtraTrimmerArgs)</_ExtraTrimmerArgs>
<TrimmerSingleWarn Condition=" '$(TrimmerSingleWarn)' == '' ">true</TrimmerSingleWarn>
</PropertyGroup>

<!-- SetIsTrimmable for any assemblies listed in TrimmableAssembly.
TrimmableAssembly -> ReloadedLinkAssemblies
-->
<JoinItems Left="@(ManagedAssemblyToLink)" LeftKey="FileName" LeftMetadata="*"
Right="@(ReloadedLinkAssemblies)"
ItemSpecToUse="Left">
<Output TaskParameter="JoinResult" ItemName="_TrimmableManagedAssemblyToLink" />
</JoinItems>
<ItemGroup>
<!-- Set trimmable for assemblies which we wish to trim. -->
<ManagedAssemblyToLink Remove="@(_TrimmableManagedAssemblyToLink)" />
<ManagedAssemblyToLink Include="@(_TrimmableManagedAssemblyToLink)" IsTrimmable="true" />
</ItemGroup>

<!-- Root the main assembly, whether or not it has IsTrimmable set. -->
<ItemGroup>
<ReloadedLinkRoots Include="@(IntermediateAssembly)" />
</ItemGroup>

<!-- In .NET6+, set the action explicitly for any with IsTrimmable MSBuild metadata -->
<ItemGroup>

</ItemGroup>


<!-- Custom: Print assemblies for trimming. -->
<ItemGroup>
<TrimmingItemsToPrint Include="@(ManagedAssemblyToLink)">
<Text>Input Assembly: %(filename) [Mode: %(ManagedAssemblyToLink.TrimMode)]</Text>
</TrimmingItemsToPrint>
</ItemGroup>

<Message Text="%(TrimmingItemsToPrint.Text)" Importance="high" />

<!-- Do the trimming. -->
<Delete Files="@(_LinkedResolvedFileToPublishCandidate)" />
<ILLink AssemblyPaths="@(ManagedAssemblyToLink)"
ReferenceAssemblyPaths="@(ReferencePath)"
RootAssemblyNames="@(ReloadedLinkRoots)"
TrimMode="$(TrimMode)"
DefaultAction="$(TrimmerDefaultAction)"
RemoveSymbols="false"
FeatureSettings="@(_TrimmerFeatureSettings)"
CustomData="@(_TrimmerCustomData)"

BeforeFieldInit="$(_TrimmerBeforeFieldInit)"
OverrideRemoval="$(_TrimmerOverrideRemoval)"
UnreachableBodies="$(_TrimmerUnreachableBodies)"
UnusedInterfaces="$(_TrimmerUnusedInterfaces)"
IPConstProp="$(_TrimmerIPConstProp)"
Sealer="$(_TrimmerSealer)"

Warn="$(ILLinkWarningLevel)"
NoWarn="$(NoWarn)"
TreatWarningsAsErrors="$(ILLinkTreatWarningsAsErrors)"
WarningsAsErrors="$(WarningsAsErrors)"
WarningsNotAsErrors="$(WarningsNotAsErrors)"
SingleWarn="$(TrimmerSingleWarn)"

CustomSteps="@(_TrimmerCustomSteps)"
RootDescriptorFiles="@(TrimmerRootDescriptor)"
OutputDirectory="$(IntermediateLinkDir)"
DumpDependencies="$(_TrimmerDumpDependencies)"
ExtraArgs="$(_ExtraTrimmerArgs)"
ToolExe="$(_DotNetHostFileName)"
ToolPath="$(_DotNetHostDirectory)"
ContinueOnError="ErrorAndContinue">
<Output TaskParameter="ExitCode" PropertyName="_ILLinkExitCode" />
</ILLink>

<Touch Files="$(_LinkSemaphore)" AlwaysCreate="true" Condition=" '$(_ILLinkExitCode)' == '0' " />

<!-- Original Target: ILLink -->
<ItemGroup>
<_LinkedResolvedFileToPublish Include="@(_LinkedResolvedFileToPublishCandidate)" Condition="Exists('%(Identity)')" />
<ResolvedFileToPublish Remove="@(ManagedAssemblyToLink)" />
<ResolvedFileToPublish Remove="@(_PDBToLink)" />
<ResolvedFileToPublish Include="@(_LinkedResolvedFileToPublish)" />
</ItemGroup>

</Target>
</Project>
9 changes: 9 additions & 0 deletions Reloaded.Universal.Monitor/BuildLinked.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Set Working Directory
Split-Path $MyInvocation.MyCommand.Path | Push-Location
[Environment]::CurrentDirectory = $PWD

Remove-Item "$env:RELOADEDIIMODS/Reloaded.Universal.Monitor/*" -Force -Recurse
dotnet publish "./Reloaded.Universal.Monitor.csproj" -c Release -o "$env:RELOADEDIIMODS/Reloaded.Universal.Monitor" /p:OutputPath="./bin/Release" /p:ReloadedILLink="true"

# Restore Working Directory
Pop-Location
Loading

0 comments on commit 3354fcc

Please sign in to comment.