C
C#8mo ago
Donut5162

❔ Publishing project

Hello, I am trying to publish a WPF project with NuGet dependencies. I am trying to publish to a single executable. I can publish it in visual studio and get a lightweight exe but it requires a few other DLLs. I can use the command line to publish to a single file but it is very large; the
--self-contained
--self-contained
flag is necessary for this, but it seems to include the .NET runtume in the executable. I would like to avoid this to reduce size since i believe windows comes with the runtime already. Any ideas?
16 Replies
JakenVeina
JakenVeina8mo ago
depends what version of the .NET runtime you're targeting a ClickOnce installer might be a good bet
Donut5162
Donut51628mo ago
is .NET backwards compatible with older versions?
JakenVeina
JakenVeina8mo ago
not completely, no
Donut5162
Donut51628mo ago
unfortuante
JakenVeina
JakenVeina8mo ago
but again, depends on the version you're targeting
Donut5162
Donut51628mo ago
.NET 6.0-windows
JakenVeina
JakenVeina8mo ago
.NET Core and .NET 5+ do not come pre-installed in Windows
Donut5162
Donut51628mo ago
oh okay I can do ClickOnce, I would have liked to avoid using an installer but if that's the best bet i guess it can't be helped
JakenVeina
JakenVeina8mo ago
they are available through the Windows Package Manager in Windows 10 and 11, so that doesn't necessarily mean you need to build a self-contained executable a ClickOnce is a decent solution alternatively, you can dive deeper into the self-contained rabbit hole there's a lot of gains to be made for build size when you make the extra step to AoT compilation and trimming
Donut5162
Donut51628mo ago
i will look into it, thanks 👍
Pobiega
Pobiega8mo ago
Sounds like you want to take a look at $singlefile
MODiX
MODiX8mo ago
dotnet publish -c Release -r <runtime identifier> -p:PublishSingleFile=true Use of -p:PublishSingleFile=true implies --self-contained true. Add --self-contained false to publish as runtime-dependent. -r RID and -p:PublishSingleFile=true can be moved to .csproj as the following properties:
<RuntimeIdentifier>RID</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>RID</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
but to target multiple RIDs, you have to use dotnet publish with the -r option for each RID. You can also add -p:IncludeNativeLibrariesForSelfExtract=true to include native libraries (like Common Language Runtime dlls) in the output executable. You might want to instead publish your application compiled Ahead Of Time to native code, see $nativeaot for examples. https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file https://docs.microsoft.com/en-us/dotnet/core/rid-catalog https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publish
Create a single file for application deployment - .NET
Learn what single file application is and why you should consider using this application deployment model.
.NET Runtime Identifier (RID) catalog - .NET
Learn about the runtime identifier (RID) and how RIDs are used in .NET.
Donut5162
Donut51628mo ago
oh shoot, adding --self-contained=false actually worked it's a single file and less than a megabyte well, it works on my machine at least...
Pobiega
Pobiega8mo ago
Yeah, but it will require the runtime to be installed
Donut5162
Donut51628mo ago
yeah
Accord
Accord8mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ Having issues placing a set of Console.WriteLine statements in the correct spotFirst, I am a beginner, so I would REALLY appreciate explanations on criticism. That way, I can unde❔ ✅ WinForms ListBox.DataSource not workingI have a ListBox that contains only instances of Employee. ToString looks like `Employee { Name: "Joplease help homework due in 20 minsProgram Description: You are to read an external file of random integer values until the end of file❔ Azure AD B2C Sign-In and Password Reset URL ParametersHey there, hope you all have an awesome day ahead. I got this azure ad b2c custom sign-in policy ca✅ Confusing wording, seeking clarification, NOT homework helpHello (again for those that remember) ive got this assignment, but yet again I have no idea what th❔ Two Program.cs files in new Blazor Web App template.After playing around with the preview version of .NET 8 I noticed that in the new Blazor Web App tem❔ ASP.NET Razor pages, understanding dataHello, I would greatly appreciate it if someone can help me understand how data works within razor p❔ DataBaseProblemHi Guys! I have this code when I try to make my db connection: SqlConnection con; public MainForm(❔ Converting mails with a attached pdf to a txt file using OCRWhat I'm creating is a software that when running it, it uses IMAP to access the specified email acc❔ Question about getter property of listso, i have some class containg property of type: `List<string>` , how can i thread-safe return this