I have created a simple Hello World application using Visual Studio 2022. The application is a WPF application that targets the .NET 6.0 framework. There is no code, just a "Hello World" TextBlock in MainWindow.xaml. When I try running the binaries on a Windows 10 machine, I get the following message box:
To run this application, you must install .NET Desktop Runtime 6.0.4 (x64). Would you like to download it now?
When I run the dotnet --info command, it displays the following:
Host (useful for support): Version: 6.0.4 Commit: be98e88c76
.NET SDKs installed: No SDKs were found.
.NET runtimes installed: Microsoft.NETCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]To install additional .NET runtimes or SDKs:
At this point I feel like I have everything I need but I can't get the application to run.
I have downloaded .NET Desktop Runtime 6.0.4 from this download page. It installed without any issues.
This happens on multiple machines I have tested with, including:
- Windows 10 "MSIX Packaging Tool Environment" image in Hyper-V
- Windows 11 "dev environment" image in Hyper-V
- Two Windows 10 development machines.
Recreating the issue
- Using Visual Studio, create a new WPF Application targeting .NET 6.0.
- Build the application.
- Copy EXE and DLL from
bin/Debug/net6.0-windowsto another machine. - Run EXE on the other machine.
2 Answers
Instead of copying the executable out of the debug folder, use the Publish feature and select the "self contained" option.
2The Build process generates:
assembly_name.depsassembly_name.pdbassembly_name.runtimeconfig.json
I was able to launch the application by including the runtimeconfig.json file.
With .NET Framework applications, it was possible to simply copy the EXE and DLLs but it seems like this is not possible with .NET Core applications.
The better approach for my needs is to use Publish to generate a single-file EXE that contains everything the application needs. The file it generates is pretty big though, about twice the size as my previous releases.
4