Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim unused/duplicate build artifacts #192

Open
runesoerensen opened this issue Feb 3, 2025 · 0 comments
Open

Trim unused/duplicate build artifacts #192

runesoerensen opened this issue Feb 3, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@runesoerensen
Copy link
Contributor

We currently don't do anything to clean up intermediate build artifacts following a build. However, running dotnet publish produces several unused build artifacts that are copied/duplicated to the bin/publish folders users will use.

In many cases this has a relatively small impact on the output footprint. However, the impact can be quite significant in certain cases -- especially when the source includes large files that are copied to the output directory, or when compiling self-contained and/or AOT apps.

The number of unused/duplicated files can be reduced by setting the artifacts path property during the build. Setting the artifacts path to a /tmp/foo folder, in combination with the PublishDir msbuild property, effectively eliminates most of the duplication.

Users can already configure this by including a Directory.Build.props file similar to this:

<Project>
  <PropertyGroup>
    <ArtifactsPath>/tmp/dotnetartifacts</ArtifactsPath>
  </PropertyGroup>
</Project>

The difference in disk usage (with and without artifacts path configured to a tmp directory) can be seen for a couple template webapiaot and blazor apps below.

We may want to consider setting the artifacts path by default for all builds (by setting the --artifacts-path parameter during dotnet publish).

Web API AOT app (`webapiaot` template)
================================

Workspace disk usage (without artifacts path set to tmp directory)
------------------------------------------------------------------

heroku@799072c54d1d:/workspace$ du -h
30M    ./bin/publish
30M    ./bin/Release/net9.0/linux-arm64/native
140M   ./bin/Release/net9.0/linux-arm64
140M   ./bin/Release/net9.0
140M   ./bin/Release
170M   ./bin
8.0K   ./Properties
16K    ./obj/Release/net9.0/linux-arm64/staticwebassets
50M    ./obj/Release/net9.0/linux-arm64/native
16K    ./obj/Release/net9.0/linux-arm64/refint
16K    ./obj/Release/net9.0/linux-arm64/ref
50M    ./obj/Release/net9.0/linux-arm64
50M    ./obj/Release/net9.0
50M    ./obj/Release
51M    ./obj
220M   .


Workspace disk usage (with artifacts path set to tmp directory)
---------------------------------------------------------------

heroku@b923600529ec:/workspace$ du -h
30M    ./bin/publish
30M    ./bin
8.0K   ./Properties
28K    ./obj
30M    .


Blazor template app (`blazor` template)
===================

Workspace disk usage (without artifacts path set to tmp directory)
------------------------------------------------------------------

heroku@1ede41998606:/workspace$ du -h
7.6M   ./bin/publish/wwwroot/lib/bootstrap/dist/css
3.5M   ./bin/publish/wwwroot/lib/bootstrap/dist/js
12M    ./bin/publish/wwwroot/lib/bootstrap/dist
12M    ./bin/publish/wwwroot/lib/bootstrap
12M    ./bin/publish/wwwroot/lib
12M    ./bin/publish/wwwroot
12M    ./bin/publish
512K   ./bin/Release/net9.0/linux-arm64
516K   ./bin/Release/net9.0
520K   ./bin/Release
13M    ./bin
8.0K   ./Properties
20K    ./Components/Pages
20K    ./Components/Layout
56K    ./Components
6.0M   ./wwwroot/lib/bootstrap/dist/css
2.5M   ./wwwroot/lib/bootstrap/dist/js
8.4M   ./wwwroot/lib/bootstrap/dist
8.4M   ./wwwroot/lib/bootstrap
8.4M   ./wwwroot/lib
8.4M   ./wwwroot
1.2M   ./obj/Release/net9.0/linux-arm64/compressed/publish
2.8M   ./obj/Release/net9.0/linux-arm64/compressed
156K   ./obj/Release/net9.0/linux-arm64/staticwebassets
12K    ./obj/Release/net9.0/linux-arm64/refint
12K    ./obj/Release/net9.0/linux-arm64/ref
12K    ./obj/Release/net9.0/linux-arm64/scopedcss/Components/Layout
16K    ./obj/Release/net9.0/linux-arm64/scopedcss/Components
12K    ./obj/Release/net9.0/linux-arm64/scopedcss/projectbundle
12K    ./obj/Release/net9.0/linux-arm64/scopedcss/bundle
44K    ./obj/Release/net9.0/linux-arm64/scopedcss
5.3M   ./obj/Release/net9.0/linux-arm64
5.3M   ./obj/Release/net9.0
5.3M   ./obj/Release
5.3M   ./obj
27M    .

Workspace disk usage (with artifacts path set to tmp directory)
---------------------------------------------------------------

heroku@785c48fba042:/workspace$ du -h
7.6M   ./bin/publish/wwwroot/lib/bootstrap/dist/css
3.5M   ./bin/publish/wwwroot/lib/bootstrap/dist/js
12M    ./bin/publish/wwwroot/lib/bootstrap/dist
12M    ./bin/publish/wwwroot/lib/bootstrap
12M    ./bin/publish/wwwroot/lib
12M    ./bin/publish/wwwroot
12M    ./bin/publish
12M    ./bin
8.0K   ./Properties
20K    ./Components/Pages
20K    ./Components/Layout
56K    ./Components
6.0M   ./wwwroot/lib/bootstrap/dist/css
2.5M   ./wwwroot/lib/bootstrap/dist/js
8.4M   ./wwwroot/lib/bootstrap/dist
8.4M   ./wwwroot/lib/bootstrap
8.4M   ./wwwroot/lib
8.4M   ./wwwroot
21M    .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant