question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PublishTrimmed should imply self-contained

See original GitHub issue

Doing the following steps:

  • dotnet new console
  • dotnet publish -p:PublishTrimmed=true

Results in the following error:

C:\Users\eerhardt\.nuget\packages\microsoft.net.illink.tasks\8.0.100-1.22619.1\build\Microsoft.NET.ILLink.targets(196,5): error NETSDK1102: Optimizing assemblies for size is not supported for
the selected publish configuration. Please ensure that you are publishing a self-contained app. [C:\DotNetTest\Net8Console\Net8Console.csproj]

However, doing

  • dotnet publish -p:PublishAot=true
  • -or-
  • dotnet publish -p:PublishSingleFile=true

Just works without more command line args.

We should make PublishTrimmed=true imply SelfContained=true, just like PublishAot=true and PublishSingleFile=true does. That way users don’t need to pass extra args on the command line, just to make this work.

If in the future we want to support a mode where PublishTrimmed=true, but SelfContained=false, those customers can explicitly --self-contained false. This is consistent with the current PublishSingleFile=true behavior. By default it is self-contained. And you can opt into Framework Dependent Deployment with dotnet publish -p:PublishSingleFile=true --self-contained false.

cc @vitek-karas @sbomer @agocke

Issue Analytics

  • State:open
  • Created 8 months ago
  • Reactions:2
  • Comments:93 (92 by maintainers)

github_iconTop GitHub Comments

2reactions
DamianEdwardscommented, Feb 3, 2023

I’ve read all the reasoning here, and while I don’t fault the logic, I find the fact that PublishAot will now simply error without PublishSelfContained also being specified a strange UX for us to default to, especially when we seem to believe it’s extremely unlikely we’d ever support AOT with FDD apps.

2reactions
jkotascommented, Feb 2, 2023

When it comes to PublishAot, PublishTrimmed, and PublishSingleFile, we recommend devs put these properties in their csproj.

These properties enable analyzers that warn about the form factor incompatibilities in the inner dev loop.

Setting these properties via command line is not a pit of success.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trim self-contained applications - .NET
Learn how to trim self-contained apps to reduce their size. ... <PublishTrimmed> should be set in the project file so that trim-incompatible ...
Read more >
Should I use self-contained or framework-dependent ...
In this post I compare the impact of the framework-dependent vs self-contained mode on Docker image size, taking layer caching into account.
Read more >
.net - How to publish a self-contained C# executable that ...
The easiest way I've found to do this is to make a separate self-contained build of B and then simply copy over the...
Read more >
Publishing a self-contained single-file .NET 5 executable
A self-contained . NET application is one that doesn't rely on there being any shared components on the target machine (such as the...
Read more >
Making a tiny .NET Core 3.0 entirely self-contained single ...
Here is a .NET Core 3.0 Hello World app. 225 files, 69 megs. Now I'll open the csproj and add PublishTrimmed = true....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found