2

I am building a WPF application in .NET Core 3.1 and willing to restructure my build directory. Right now it looks like this:

Example of a Build folder

What I want to achieve is something like this:

Goal Build folder

The above example of I want to achieve is rather perfect, but I am not sure if it is possible at all. However, my goal is to minimize the amount of files that are kept at the output directory alongside the executable file.

I've looked up various solutions but they all seem to work only for .NET Framework. My guess is that it happens because the latter uses packages.config file and .NET Core 3.1 and above all use PackageReference formats.

What I've tried:

  1. Installing PrettyBin NuGet package. This theoretically allows to control the structure of the output folder, but only works in .NET Framework

  2. Following this link: Build DLL to a separate folder But, it makes use of App.config file which also exists only in .NET Framework projects.

  3. How to save DLLs in a different folder when compiling in Visual Studio? Also makes suggestions only based on .config file as far as I understood.

  4. This article: https://weblog.west-wind.com/posts/2019/Apr/30/NET-Core-30-SDK-Projects-Controlling-Output-Folders-and-Content I've tried that, but for some reason it was not changing the output directory as was suggested, but perhaps I was doing something wrong.

P.S: I've tried doing the same in .NET 5.0 and willing to migrate to the latter soon, so any solution for .NET 5.0 is also appreciated.

Bobbie
  • 163
  • 1
  • 11

1 Answers1

2

I found out that .NET 5.0 (And .NET Core) allows us to create Publish Profile and Publish the application with specific setup. This is discussed in the Microsoft docs here: https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file#publish-a-single-file-app---visual-studio

The Publish Profile that I used is:

enter image description here

When you save that and click publish, you will find the build files in the "Target location" that you specified. This will contain only two files**, like that:

enter image description here

Hope everyone will find it useful.

** There will be more files if you use your own .dll files and check them as "Copy Always" (In Copy to Output Directory)

Bobbie
  • 163
  • 1
  • 11