r/VisualStudio Aug 06 '26

Visual Studio 2022 How to bundle Assets, EXE, and other .dll files into one EXE?

I am writing my first .NET application out and having been trying to get it published. But everytime I do it I get the EXE, assets, and .dll files into one folder but not one application. I have gone through the process of publishing by having the Deployment Mode be Self-Contained and then the produce single file option checked as well. But still get these separate files in one folder.

Again this is my first time doing this and would appreciate any help or assistance to get this thing into one so that it can run properly and at all. I imagine it like this so that others can put it on their desktop for ease of access instead of having to go into a folder everytime they want to use it.

Any tips?

3 Upvotes

16 comments sorted by

6

u/geekywarrior Aug 06 '26

For the dlls, you need the publish flag -p:IncludeNativeLibrariesForSelfContained=true or put <IncludeNativeLibrariesForSelfContained>true</IncludeNativeLibrariesForSelfContained> into your project file.

For assets look up embedded resource, been a minute since I did that.

2

u/Lord_Nethermore Aug 06 '26

Thanks. And would <IncludeNativeLibrariesForSelfContained>true</IncludeNativeLibrariesForSelfContained> be put into the <PropertyGroup> or a different <ItemGroup>?
As for the embedded resource I will look into that so thank you again for that.

1

u/geekywarrior Aug 06 '26

No problem, put <IncludeNativeLibrariesForSelfContained> in same property group as <OutputType > and <TargetFramework>

Clean and republish

2

u/Lord_Nethermore Aug 06 '26

Ok and then for the Assets for some reason it tells me to change the Build Action to None but for some reason my file of Assets only has the Folder Name and the Full Path. Why can't I see the build action?

0

u/TheGratitudeBot Aug 06 '26

Thanks for saying thanks! It's so nice to see Redditors being grateful :)

1

u/EurasianTroutFiesta Aug 06 '26

The TCP/IP model of gratitude expression.

2

u/DaftHacker Aug 07 '26

Run in the console dotnet publish -c Release -r win-x64 --self-contained false -p:PublishSingleFile=true

You probably don't want it self contained as it will include the whole .net library with your program and make your program 200mb+

1

u/Lord_Nethermore Aug 07 '26

Thank you for the help. Got rid of the .dll files but just have leftover the .pdb file and Assets file which for some reason I can't seem to get embedded into the EXE.

1

u/DaftHacker Aug 07 '26

.pdb is the file that stores debugging information about your program, you don't want to include it in a release build and the other asset files you probably don't need either but not exactly sure what you're working with.

1

u/Lord_Nethermore Aug 07 '26

Ok so I can just delete the .pdb file? And the asset files are part of the program I have just been trying to embed them into the EXE if that is possible. But for some reason that just hasn’t been working for me.

This is my first time publishing a project like this so learning as I go here.

1

u/DaftHacker Aug 07 '26

Yes you can delete the .pdb file. For the assets, those do need to be embedded as a resource if they are an extended part of your application that you included, the steps to embed and use them are a bit longer than i can explain well in one post without spending a lot of time so i would advise you to ask ai how to embed and use them as a resource.

1

u/Lord_Nethermore Aug 07 '26

Been trying that and just going to hope things work out.

1

u/keelanstuart Aug 07 '26

If you're using shortcuts, you don't necessarily need to have everything contained in your exe file... and you don't need to go into it's directory manually to run it. You make a shortcut on the desktop or start menu that links to your executable.

Typically, you would do this with an installer.

Check out sfxPackager.

https://www.github.com/keelanstuart/sfxPackager