15

I am using visual studio 2022 and created a winforms .net 6 application. I specified an output path for my release build where i want the .exe created, but visual studio creates a subfolder called 'net6.0-windows' and puts the exe in there. How do i stop this and get it to put the exe where I specified?

Some background: I am upgrading a .Net Framework 4.8 Winforms to .Net 6. In .net framework it puts the exe in the output folder specified (no subfolders). I want to keep with the same behavior because other files and utilities also need to be in there or look in that folder.

Output path specified in visual studio

[Output path specified in visual studio]

Actual output path

[Actual output path]

Christian.K
  • 47,778
  • 10
  • 99
  • 143
Possibility
  • 153
  • 1
  • 5
  • Does your .csproj contain the property or ? It will do what you're seeing when more than one framework is being targeted in the same build. – Thomas F. Abraham Nov 24 '21 at 05:42
  • 1
    That's the default and expected behavior - Winforms is *Windows-only*, so you're really targetting `.net6-windows` and thus that's the subfolder you get. You can *stop this* - you need to get used to it and go with it .... – marc_s Nov 24 '21 at 06:20
  • .NET 6 is .NET *Core* 6. Runtime-specific folders are the default, probably since .NET Core 1.0. A .NET Core application may target different runtimes so it's impossible to just put everything into `bin\Release` – Panagiotis Kanavos Nov 24 '21 at 09:20
  • `I want to keep with the same behavior` you aren't using .NET Framework any more, you're using .NET Core. Tools expect to find files in the correct location. `bin\Release` doesn't even contain the published binaries, those go in the `publish` folder. If you publish a single-file executable the build folder will still contain individual files, while the `publish` folder will contain a single `.exe`. If you want to create an installer you'll have to use the runtime-specific files from the `publish` folder, not the `bin\Release` folder – Panagiotis Kanavos Nov 24 '21 at 09:23

1 Answers1

27

I'll provide the following information for reference and sake of answering the question.

You can prevent that the TargetFramework is added to the output folder by adding the following property to your project file.

<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>

Additionally, you can prevent a RuntimeIndentifier (e.g. win-x64), if any, to be added setting this property to false:

<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>

Should you do this?

Maybe not. Those directories are there for a reason: to allow multiple TargetFramework (versions) and/or multiple RuntimeIndentifier in parallel (otherwise outputs would mix in a unholy manner).

Christian.K
  • 47,778
  • 10
  • 99
  • 143
  • Is there a need to do this if you're building a WinForms/WPF app? I understand the need for it when building libraries that are distributed and used by many different runtime types, but what about when building a desktop app? – asaf92 Nov 24 '21 at 11:12
  • 1
    Thank you Christian, the first line you listed did the trick. For those wondering why i wanted this, this software is for manufacturing equipment and will only ever be installed on a couple of computers, so we dont use the publish, we just move the release build folder to a special location on the equipment and it needs to maintain correct functionality with other software. It has also the added pleasure of FDA regulations and documentation involved. – Possibility Nov 24 '21 at 14:50
  • 1
    Note that - as others have said - the "Release" (or "Debug") folder will generally _not_ include all dependencies that the application needs to run. The full story is, well, complicated (lookup "self contained .net core app" to start). In general, only after doing the "publish" step you can be sure you have all dependencies that the app requires to run on a different box. – Christian.K Nov 24 '21 at 14:53