Skip to content

2. Windows build - Use build script and full path#77

Open
culix-7 wants to merge 13 commits intoSourMesen:masterfrom
culix-7:windows-build-batch-file-and-full-path
Open

2. Windows build - Use build script and full path#77
culix-7 wants to merge 13 commits intoSourMesen:masterfrom
culix-7:windows-build-batch-file-and-full-path

Conversation

@culix-7
Copy link
Copy Markdown

@culix-7 culix-7 commented Jan 3, 2026

  • Move WindowsPreBuild steps to powershell file
  • Add 'pester' tests to verify that powershell works

..

Hello, thank you so much for creating and sharing Mesen. It is absolutely fantastic. I very much enjoy using it and I wanted to try to give something back.

When building in Visual Studio on Windows 10 at the latest Mesen code - commit fabc9a6 - I get an error about "The file cannot be accessed" while building the UI project:

8>------ Build started: Project: UI, Configuration: Release x64 ------
8>C:\code\mesen\UI\Dependencies\MesenNesDB.txt
8>C:\code\mesen\UI\Dependencies\Internal\CheatDb.Nes.json
8>C:\code\mesen\UI\Dependencies\Internal\CheatDb.Snes.json
8>C:\code\mesen\UI\Dependencies\Satellaview\BSX0120-0.bin
8>C:\code\mesen\UI\Dependencies\Satellaview\BSX0121-0.bin
8>C:\code\mesen\UI\Dependencies\Satellaview\BSX0122-0.bin
8>C:\code\mesen\UI\Dependencies\Satellaview\BSX0123-0.bin
8>C:\code\mesen\UI\Dependencies\Satellaview\BSX0124-0.bin
8>8 File(s) copied
8>        1 file(s) copied.
8>        1 file(s) copied.
8>        1 file(s) copied.
8>Exception calling "GetFiles" with "0" argument(s): "The file cannot be accessed by the system.
8>"
8>At C:\Program Files\WindowsPowerShell\Modules\Microsoft.PowerShell.Archive\1.2.5\Microsoft.PowerShell.Archive.psm1:706
8>char:13
8>+             $files = $currentContent.GetFiles()
8>+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8>    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
8>    + FullyQualifiedErrorId : IOException
8>
8>The system cannot find the file specified.
8>C:\code\mesen\UI\UI.csproj(654,5): error MSB3073: The command "cd C:\code\mesen\bin\win-x64\Release\
8>C:\code\mesen\UI\UI.csproj(654,5): error MSB3073: rd Dependencies /s /q
8>C:\code\mesen\UI\UI.csproj(654,5): error MSB3073: md Dependencies
8>C:\code\mesen\UI\UI.csproj(654,5): error MSB3073: xcopy /s C:\code\mesen\UI\Dependencies\* Dependencies
8>C:\code\mesen\UI\UI.csproj(654,5): error MSB3073: copy libHarfBuzzSharp.dll Dependencies
8>C:\code\mesen\UI\UI.csproj(654,5): error MSB3073: copy libSkiaSharp.dll Dependencies
8>C:\code\mesen\UI\UI.csproj(654,5): error MSB3073: copy MesenCore.dll Dependencies
8>C:\code\mesen\UI\UI.csproj(654,5): error MSB3073: cd Dependencies
8>C:\code\mesen\UI\UI.csproj(654,5): error MSB3073: del ..\Dependencies.zip
8>C:\code\mesen\UI\UI.csproj(654,5): error MSB3073: powershell Compress-Archive -Path * -DestinationPath '..\Dependencies.zip' -Force
8>C:\code\mesen\UI\UI.csproj(654,5): error MSB3073: copy ..\Dependencies.zip C:\code\mesen\UI\" exited with code 1.

Have you ever seen this?

Potential Cause

I think this may be caused by my computer getting confused about the file path for the final Dependencies.zip zip file. It claims it is not able to find that file.
I am using Visual Studio 2022 Community, Version 17.14.23, doing a Release x64 build.

I'm not sure if this is an issue with my setup or if I did something wrong. My steps were:

  1. git clone the mesen repo to a local folder
  2. Open mesen.sln with Visual Studio 2022
  3. Select Release and x64 build config
  4. Click on Build -> Build Solution

My guess is that this is some difference between system environment variables and powershell's behaviour with paths, or what folders are included in paths.

Fix - Use the full path

I found that if I change the build script to use the full path for the zip file, then the build succeeds.
I went into the PreBuildWindows command and added a batch file %~f path expansion for the file path.
The build then succeeds just fine.

So I wanted to offer this patch to use the full file path.

Move build steps into script

To make viewing and maintaining the build steps a bit easier for humans, I took the liberty of copying the PreBuildWindows commands into a powershell script.

This would let anyone view all of the steps in one place, e.g. inside a regular Visual Studio editor window, and be able to use regular newlines for spacing, instead of having to edit everything inside a Visual Studio properties window, or use the special 
 characters for newlines.

Just like with PR #79 , I have [set up this branch (including both #79 and this PR) in my own branch in my own copy of the repo, and run the tests with both linux/mac fixes and Windows fixes to prove that it works and the tests all pass.

Thank you for your time.

@culix-7 culix-7 changed the title Windows build - Use batch file and full path 2. Windows build - Use batch file and full path Jan 9, 2026
@culix-7 culix-7 marked this pull request as draft January 9, 2026 14:29
@culix-7 culix-7 force-pushed the windows-build-batch-file-and-full-path branch from 2d5e3d4 to 0b99617 Compare January 13, 2026 15:40
@culix-7
Copy link
Copy Markdown
Author

culix-7 commented Jan 13, 2026

Update: Converted batch file to powershell script.

Alright, after combining my changes from PRs 79, 77, and 78 all into one branch in my own copy of the repo, I ran into several issues where a Windows batch file just doesn't work well.
batch has too many issues not being able to handle paths and quoting. I was not able to get it to work in all of the platforms and builds that are needed.

I have added a commit converting the batch file into a powershell script instead.
Powershell is much more capable at handling paths, trailing slashes, quotes, and so forth.
Even better - powershell has a built-in test language available called 'pester'. This makes it possible to mock and test the script to prove that it works just as needed - in both local builds and github CI cloud builds.
pester comes pre-installed with github Windows machines so everything is set up, and it is fairly easy to install if you don't already have it.

Anyone should be able to run .\UI\test_all_windows.ps1 in a powershell to run the tests here and prove that the prebuild_windows.ps1 works in all of the situations that we need.

@culix-7 culix-7 force-pushed the windows-build-batch-file-and-full-path branch from 0b99617 to 82bf596 Compare January 14, 2026 00:09
move build steps out of the `.csproj` file and into a separate `.bat` file.
this should make it easier to read and edit.
you can use newlines

no behaviour changes
expand path for `Dependencies.zip` with `~f` batch syntax
ensures that powershell can always find the file
* improve quoting and handle input vars
* make sure cd and directory expansion happens correctly
@culix-7 culix-7 force-pushed the windows-build-batch-file-and-full-path branch from 82bf596 to 832958b Compare January 14, 2026 00:10
@culix-7 culix-7 changed the title 2. Windows build - Use batch file and full path 2. Windows build - Use build script and full path Jan 14, 2026
bat file has many problems being stable and consistent,
and handliing paths and input.

powershell should be more reliable
use constants to remove repeated strings
@culix-7 culix-7 force-pushed the windows-build-batch-file-and-full-path branch from 832958b to b534e61 Compare January 14, 2026 04:42
* Wrap the entire script in 'try { .. } catch {}' brackets. This allows us to capture anything that went wrong and report it for both tests and visual studio
* Format a nice error message, and write that to stdout.

If we format it in a specific way, Visual Studio will display it nicely right inside the IDE, in the Error List window.
The user can click on that line to jump to the script.
* Use specific exception types when throwing exceptions, to better declare what is happening
* Add input validation to check for empty args. This should never happen, but we might as well be robust to it.
* Add checks for folders that don't exist
* Extract some strings to constants
* Add troubleshooting info on how to fix problems
Apparently pester has no way to easily get the name of the current running test.
This has been an open issue since at least June 2020 - pester/Pester#1611

you can hack around it by setting an environment variable,
but that makes the code pretty ugly.

at least do this for now.
@culix-7 culix-7 force-pushed the windows-build-batch-file-and-full-path branch from e2e6b0b to 17be5f6 Compare January 17, 2026 00:13
@culix-7 culix-7 marked this pull request as ready for review January 18, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant