How to get rid of '%AppName%.runtimeconfig.dev.json' files in release for Net 5.0

Viewed 596

I have created a console app for Net 5.0 and built realease of it. In release folder I found some files, which app don't really need (It starts and works without them): %AppName%.deps.json and %AppName%.runtimeconfig.dev.json. In the second file I found some list (under name 'additionalProbingPaths') with three absolute paths on my local machine (two of them even contains my user name). Obviously, those paths not useful on any other machine where my app will be run. I sought a way to disable generating this file at all, but found only that:

<GenerateRuntimeConfigurationFiles>false</GenerateRuntimeConfigurationFiles>

But this option disables generating %AppName%.runtimeconfig.json and my executable file not working. I found also this link (source code of MSBuild Task for generating those files). This task contains two bool options: WriteAdditionalProbingPathsToMainConfig and GenerateRuntimeConfigDevFile. They are almost what I want, but I can't find a way to set this options via project file's PropertyGroup. I tried:

<WriteAdditionalProbingPathsToMainConfig>true</WriteAdditionalProbingPathsToMainConfig>
<GenerateRuntimeConfigDevFile>false</GenerateRuntimeConfigDevFile>

But it doesn't work. Now I just delete that file via del command in Post-Build Event. Is there any way to prevent generate that file (%AppName%.runtimeconfig.dev.json)? These 'additionalProbingPaths', as I understand, lead to some local nuget repositories (but my app NOT install any of nuget packages!):

C:\\Users\\%UserName%\\.nuget\\packages
C:\\Users\\%UserName%\\.dotnet\\store\\|Arch|\\|tfm|

What are they needed for if my app is already built and ready to run. Or end app user need to download some packages to run my app? I use Visual Studio 2019, if it matters.

P.S: Sorry for such a stupid question but I'm a novice to Net Core.

1 Answers

It's worth nothing that the file %AppName%.runtimeconfig.dev.json is not copied to the publish directory, which should be what you package / send to your end user.

If I build a default app in release, via the dotnet build -c Release command, here's the content of the folder:

Build folder content

However, when I use the dotnet publish -c Release command (the only officially supported way to prepare the application for deployment), here's the folder's content; you can see the %AppName%.runtimeconfig.dev.json isn't there:

Publish folder content

From the official documentation regarding the publish command:

dotnet publish compiles the application, reads through its dependencies specified in the project file, and publishes the resulting set of files to a directory.
The dotnet publish command's output is ready for deployment to a hosting system (for example, a server, PC, Mac, laptop) for execution. It's the only officially supported way to prepare the application for deployment.

In contrast, the official documentation regarding the build command:

The dotnet build command builds the project and its dependencies into a set of binaries.
(...) the product of dotnet build isn't ready to be transferred to another machine to run. To create a version of the application that can be deployed, you need to publish it (for example, with the dotnet publish command).

Summary: don't worry about %AppName%.runtimeconfig.dev.json, and use the dotnet publish command instead.

Related