Home > OS >  to run this program you must install .net (for a net5.0 windows forms app windows 11)
to run this program you must install .net (for a net5.0 windows forms app windows 11)

Time:12-25

I built a small C# windows forms project on Windows 11 using net5. It runs fine in debug mode under Vstudio 2019 latest (v16.11.8). If it helps any, the "dotnet --list-sdks" commands report that both .NET v5.0.404 and v6.0.101 are installed."dotnet --list-runtimes" reports that runtimes NETCore.App 3.1.22, 5.0.13, and 6.0.1 are installed, along with WindowsDesktop.App versions 3.1.22, 5.0.13, and 6.0.1.

When I build the app I use the post-build event to copy files to a different folder where I double click the .exe file to run the forms app. But the double click always tells me that to run the app I need to install ".NET" (exactly, no other info). Would you like to download it now? I click Yes, the popup dialog disappears, and nothing happens.

I copied the .exe first to the destination folder, and when that failed I copied the json config file, the DLL, and the .pdb file too. But still, no happiness.

I must be missing something simple since the app runs fine under vstudio.

I compared the contents of the Debug/net5.0-windows folder with my destination folder. The Debug folder had 44 other DLLs and a dozen language packs. I suspect that my .exe app cannot find all those DLLs for some reason. It should find them because of all the SDKs and runtimes that are installed. But I don't know enough about how to tell the .exe file to find and use all the installed SDKs and runtimes.

Can someone please tell me what I'm doing wrong and how I can get the exported file to run using the installed runtimes? Thank you.

CodePudding user response:

You can publish it with a single executable option - https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file#publish-a-single-file-app---visual-studio

You can do this via VS gui or with the .net cli like: dotnet publish -r win-x64 -p:PublishSingleFile=true --self-contained false

  • Related