Valheim-Modding / JotunnModStub

Valheim mod skeleton using Jötunn
MIT No Attribution
31 stars 309 forks source link

Release packaging via Publish.ps1 does not work OOTB #4

Closed MofoMojo closed 3 years ago

MofoMojo commented 3 years ago

Following the Step-by-Step guide via these locations Setup Guide Readme Steps

When you attempt to publish Release build, you'll get errors around the packaging (see provided code block below).

Errors on Release Build

1>------ Rebuild All started: Project: MMNoMonsterArea, Configuration: Release Any CPU ------
1>  Executing Jotunn Prebuild Task creating MMHOOK dlls
1>  Processing E:\Games\Steam\steamapps\common\Valheim\valheim_Data\Managed\assembly_googleanalytics.dll
1>  Processing E:\Games\Steam\steamapps\common\Valheim\valheim_Data\Managed\assembly_guiutils.dll
1>  Processing E:\Games\Steam\steamapps\common\Valheim\valheim_Data\Managed\assembly_lux.dll
1>  Processing E:\Games\Steam\steamapps\common\Valheim\valheim_Data\Managed\assembly_postprocessing.dll
1>  Processing E:\Games\Steam\steamapps\common\Valheim\valheim_Data\Managed\assembly_simplemeshcombine.dll
1>  Processing E:\Games\Steam\steamapps\common\Valheim\valheim_Data\Managed\assembly_steamworks.dll
1>  Processing E:\Games\Steam\steamapps\common\Valheim\valheim_Data\Managed\assembly_sunshafts.dll
1>  Processing E:\Games\Steam\steamapps\common\Valheim\valheim_Data\Managed\assembly_utils.dll
1>  Processing E:\Games\Steam\steamapps\common\Valheim\valheim_Data\Managed\assembly_valheim.dll
1>  MMNoMonsterArea -> C:\Users\<username>\source\repos\JotunnModStub\JotunnModStub\bin\Release\MMNoMonsterArea.dll
1>  Publishing for Release from C:\Users\<username>\source\repos\JotunnModStub\JotunnModStub\bin\Release
1>  Packaging for ThunderStore...
1>  C:\Users\<username>\source\repos\JotunnModStub\JotunnModStubPackage\MMNoMonsterArea.dll
1>  Copy-Item : Could not find a part of the path 
1>  'C:\Users\<username>\source\repos\JotunnModStub\JotunnModStubPackage\plugins\MMNoMonsterArea.dll'.
1>  At C:\Users\<username>\source\repos\JotunnModStub\publish.ps1:67 char:5
1>  +     Copy-Item -Path "$TargetPath\$TargetAssembly" -Destination "$Pack ...
1>  +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>      + CategoryInfo          : NotSpecified: (:) [Copy-Item], DirectoryNotFoundException
1>      + FullyQualifiedErrorId : System.IO.DirectoryNotFoundException,Microsoft.PowerShell.Commands.CopyItemCommand
1>   
1>  Copy-Item : Cannot find path 'C:\Users\<username>\source\repos\JotunnModStub\JotunnModStubPackage\README.md' because it 
1>  does not exist.
1>  At C:\Users\<username>\source\repos\JotunnModStub\publish.ps1:68 char:5
1>  +     Copy-Item -Path "$PackagePath\README.md" -Destination "$ProjectPa ...
1>  +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>      + CategoryInfo          : ObjectNotFound: (C:\Users\stuar\...ckage\README.md:String) [Copy-Item], ItemNotFoundExce 
1>     ption
1>      + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand
1>   
1>  Compress-Archive : The path 'C:\Users\<username>\source\repos\JotunnModStub\JotunnModStubPackage\*' either does not exist 
1>  or is not a valid file system path.
1>  At C:\Users\<username>\source\repos\JotunnModStub\publish.ps1:69 char:5
1>  +     Compress-Archive -Path "$PackagePath\*" -DestinationPath "$Target ...
1>  +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>      + CategoryInfo          : InvalidArgument: (C:\Users\<username>\...odStubPackage\*:String) [Compress-Archive], InvalidO 
1>     perationException
1>      + FullyQualifiedErrorId : ArchiveCmdletPathNotFound,Compress-Archive
1>   
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

It appears the Path targets are incorrectly calculated. Consider the path: C:\Users\\source\repos**JotunnModStub**\JotunnModStubPackage\plugins\

The first JotunnModStub is from the forked repository and is the location of the solution files, publish.ps1, etc,.. There is NO JotunnModStubPackage sub-folder. There IS however another JotunModStub subfolder and in that there IS a Package subfolder.

I believe part of the problem is that the ps script doesn't put a \ in front of the packages and Copy-Item (even with -Recurse and -Force) is also a little inconsistent in execution depending on directory location/OS/PS build. I have a script which has ZERO problems creating sub directories with -Recurse and -Force but this one just doesn't work as expected. I have worked around the issue with the following simple changes:

    Write-Host "Packaging for ThunderStore..."
    $Package="Package"
    $PackagePath=$ProjectPath+"\"+$Package
    Write-Host "Copy From $TargetPath\$TargetAssembly"
    Write-Host "Copy To $PackagePath\plugins\$TargetAssembly"
    Copy-Item -Path "$TargetPath\$TargetAssembly" -Destination  (new-item -type directory -force "$PackagePath\plugins\") -Recurse -Force

Here are the errors you get with the default structure of the project

sirskunkalot commented 3 years ago

Thanks for pointing that out. I have corrected the script with tag v2.0.5.