Skip to content

[AppHost] Make MSBuild trim-friendly #13322

@kasperk81

Description

@kasperk81

#13175 is merged. A next possible improvement could be making MSBuild trim friendly:

--- a/src/MSBuild/MSBuild.csproj
+++ b/src/MSBuild/MSBuild.csproj
@@ -15,6 +15,8 @@
          versions of this project -->
     <RuntimeIdentifiers Condition="'$(DotNetBuildSourceOnly)' != 'true'">win7-x86;win7-x64</RuntimeIdentifiers>
     <UseRidGraph>true</UseRidGraph>
+    <PublishTrimmed>true</PublishTrimmed>
+    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>

     <EnableDefaultItems>false</EnableDefaultItems>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>

Repro:

$ .dotnet/dotnet publish -f net10.0 src/MSBuild/MSBuild.csproj
...
Build failed with 29 error(s) in 2.6s

Two concrete benefits of making MSBuild trim-friendly:

  • Code bloat reduction in the final executable
  • Paves the path for AOT compatibility (~83% of PublishAot errors are trimming-related)

Not pitching AOT as a main goal here, but making the codebase trimming-safe naturally moves things in that direction if/when that ever becomes interesting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions