Click here to Skip to main content
16,022,060 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want a single file executable capable of being run by itself and no other dll's, etc.

I ran msbuild /t:Publish

No error messages, but result is not what I want. Result is that in the Debug folder an app.publish folder is created containing a setup file, an executable, manifest file, and a folder('Application Files') with another folder containing two files ending in .deploy and .manifest.

When I try to run the executable(not the setup application created), the following exceptions happen:

Unhandled Exeception: System.TypeInitializationException
System.IO.FileNotFoundException: could not load file or assembly library12(dll) or one of its dependencies

The above exceptions pop up briefly in a black screen and then disappear.

What I have tried:

I tried modifying the csproj to set PublishSingleFile and IncludeNativeLibrariesForSelfExtract to true

but to no avail. Thank you guys again!
Posted
Updated 20-Aug-24 0:52am
v3
Comments
[no name] 20-Aug-24 8:17am    
If you just want a single executable program, then do not use "Publish". Just build your application and copy the executable that is produced.
Pada Temp 20-Aug-24 9:12am    
I should have included the following detail in the post, but I have tried what you are suggesting, i.e. using Build and the executable file produced. The issue I confronted was that it creates files in addition to the executable (e.g. dll's, etc). I am looking for a way to have everything in just one (presumably larger sized) executable without any additional files/dll's. Thank you!
[no name] 20-Aug-24 9:22am    
If your application targets DLL libraries then you need to include them with the executable. You probably need to forget what you are trying to do and use the proper tools provided by Microsoft.
Pada Temp 20-Aug-24 9:24am    
Yes, DLL libraries are targeted and they should be included in the executable. I am using a Visual Studio, but is there another Microsoft tool that should be used?
[no name] 20-Aug-24 9:29am    
DLL libraries are NOT included in executables. The whole point of them is that they are shared between multiple applications, so it does not make sense to build them into single applications.

1 solution

Assuming you are using .NET Core, take a look at the first answer and screendumps for the publishing settings here:
https://stackoverflow.com/questions/49967697/make-net-core-console-app-a-single-exe[^]
Make sure you have both the self-contained and single file options selected.

When using older .NET versions, e.g. 4.8 or older, you can use Fody Costura to generate a single exe:
GitHub - Fody/Costura: Embed references as resources[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900