Forum Discussion
C# .NET Framework 4.8 -> .NET 9
So, I recently realized that I had been building my project off of the outdated .NET Framework 4.8. I recently decided to dig into it and update it to as far as my IDE (VS 2022) allows ... .NET 9 for C#13.
For the most part, it was a very straightforward transition. I copied all of the source code files into the new directory, fixed whatever lingering errors there were, and it built and ran on my development machine (Win11). BUT ...... when I put the EXE on a Win10 machine, it won't run. With the .NET Framework 4.8 build, all I had to do was paste the EXE onto the target PC and it would just work. Attempting to do that here, it won't fly ...... EXE will not launch.
Searching online, it appeared that installing the .NET runtimes would be the fix. I made sure the frameworks were installed on both PCs by typing [dotnet --list-frameworks] into CMD. Still doesn't work. Ensured targeted CPU was x64. Still nothing.
The one thing that DOES work is if I publish the EXE as a standalone. That pretty much tells me it is still a .NET issue, but I can't fathom why. I would like to get away from relying on this because it makes the resulting file absolutely huge. Can someone possibly point me in the right direction as to how to get the EXE to run without a standalone build?
1 Reply
A framework-dependent .NET application normally needs more than the EXE. Its publish output includes the application DLL, dependencies and runtime configuration; copying only the executable can leave the target without the information or assemblies needed to launch.
In Visual Studio, publish to a folder with Deployment Mode set to Framework-dependent and Target Runtime set to win-x64. Copy that complete publish folder to the Windows 10 computer. The equivalent command is dotnet publish -c Release -r win-x64 --self-contained false.
On the target, use dotnet --list-runtimes, not --list-frameworks. If this is WinForms or WPF, check specifically for Microsoft.WindowsDesktop.App 9.x of the correct architecture; the base runtime alone is insufficient. Run the deployed app from a terminal and preserve the exact error if it still fails. A self-contained build working is consistent with missing runtime/deployment dependencies, but does not identify which one without that error.