Skip to content

PublishSelfContained should work with /t:Publish #32272

@eerhardt

Description

@eerhardt

Description

When publishing a trimmed app, I am currently getting an error:

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\SelfContainedTest\SelfContainedTest.csproj]

Even though I'm setting PublishSelfContained=true in my .csproj. I am also setting SelfContained=false because I don't want all of the runtime copied into my build output directory. I have many applications that I'm publishing (test apps in dotnet/aspnetcore) and each application is taking up ~100 MB in the bin directory. This is unnecessary bloat.

Reproduction Steps

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <PublishTrimmed>true</PublishTrimmed>
    <PublishSelfContained>true</PublishSelfContained>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>

    <!-- Set SelfContained=false to prevent the whole runtime from being copied into the build output directory -->
    <SelfContained>false</SelfContained>
  </PropertyGroup>

</Project>

Running dotnet msbuild /t:Publish on that project will fail. It will also fail just for:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <PublishTrimmed>true</PublishTrimmed>
    <PublishSelfContained>true</PublishSelfContained>
  </PropertyGroup>

</Project>

Expected behavior

I expect both apps above to publish successfully.

Actual behavior

Both of them produce the above error.

Regression?

No response

Known Workarounds

Explicitly specify SelfContained=true, but that causes bloat (will eventually be GBs) in my bin directory.

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions