C# – .NET Core applications on Linux (Redhat) create mysterious “.net” directories/files in the user’s home directory

.NET Core applications on Linux (Redhat) create mysterious “.net” directories/files in the user’s home directory… here is a solution to the problem.

.NET Core applications on Linux (Redhat) create mysterious “.net” directories/files in the user’s home directory

We have a series of .NET Core console applications installed in a specific directory:

/users/apps/app1/MyApp1
/users/apps/app2/MyApp2

etc….

The application works well. However, we ran into an issue where the .NET runtime seemed to put some files in the “.net” folder of the current user’s home directory.

[email protected]::/home/unclejoe> ls -la
total 40
drwx------.  8 unclejoe mygroup    139 Jan 24 14:42 .
drwxr-xr-x. 90 root    root  4096 Jan 21 15:29 ..
-rw-------.  1 unclejoe mygroup  15510 Jan 24 14:42 .bash_history
drwx------.  10 unclejoe mygroup      190 Jan 24 01:42 .net

In the .net folder, we see a bunch of seemingly temporary folders:

[[email protected] .net]$ ls -la
total 4
drwx------. 10 unclejoe mygroup  190 Jan 24 01:42 .
drwx------. 14 unclejoe mygroup 4096 Jan 23 16:28 ..
drwx------.  4 unclejoe mygroup 46 Jan 24 12:09 MyApp1
drwx------.  5 unclejoe mygroup 66 Jan 24 01:42 MyApp2

Further drilling:

[[email protected] MyApp1]$ ls -la
total 24
drwx------.  4 unclejoe mygroup   46 Jan 24 12:09 .
drwx------. 10 unclejoe mygroup  190 Jan 24 01:42 ..
drwx------.  2 unclejoe mygroup 8192 Jan 24 01:42 cz1zui3n.uma
drwx------.  2 unclejoe mygroup 8192 Jan 24 12:09 pvwttlkm.z4s

Drill the furthest :

[[email protected] MyApp1]$ cd cz1zui3n.uma
[[email protected] cz1zui3n.uma]$ ls -l
total 30808
-rw-r--r--. 1 unclejoe mygroup   330240 Jan 24 01:42 Autofac.dll
-rw-r--r--. 1 unclejoe mygroup    16384 Jan 24 01:42 Autofac.Extensions.DependencyInjection.dll
-rw-r--r--. 1 unclejoe mygroup   143609 Jan 24 01:42 MyApp1.deps.json
-rw-r--r--. 1 unclejoe mygroup    10752 Jan 24 01:42 MyApp1.dll
-rw-r--r--. 1 unclejoe mygroup      149 Jan 24 01:42 MyApp1.runtimeconfig.json
-rw-r--r--. 1 unclejoe mygroup    27136 Jan 24 01:42 Common.dll

The problem is that we don’t want to push these artifacts (dlls/application binaries) here because it takes up a lot of space over time, especially when these weird temporary directories are created (and never cleaned up on their own).

Question:

  1. Do you know what causes these directories and files to be created? It appears to have been created after the application has been running for a while.
  2. What aspects should we examine to determine the root cause?

Thanks!

Solution

Is the application published as a single-file application? If so, the documentation has some indications.

Looking at the fact that it’s extracting 3rd party libraries, I guess this might be relevant :

Previously in .NET Core 3.0, when a user runs your single-file app, .NET Core host first extracts all files to a directory before running the application. .NET 5 improves this experience by directly running the code without the need to extract the files from the app.

This explains the location:

If extraction is used the files are extracted to disk before the app
starts:

  • If environment variable DOTNET_BUNDLE_EXTRACT_BASE_DIR is set to a
    path, the files will be extracted to a directory under that path.
  • Otherwise if running on Linux or MacOS, the files will be extracted to
    a directory under $HOME/.net.
  • If running on Windows, the files will be
    extracted to a directory under %TEMP%/.net.

Related Problems and Solutions