60

Setting OutputPath in the new Visual Studio 2017 project format automatically adds the target framework in the path. For example, if I have these set in the project file:

<TargetFramework>net462</TargetFramework>
<OutputPath>/build/debug/<OutputPath>

The actual output folder will resolve to /build/debug/net462/, not /build/debug/ like in the older versions. How do I solve this without workarounds like moving things around with post build actions?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
aksu
  • 1,748
  • 1
  • 11
  • 15
  • I surely hope that there's no heuristic trying to decide what I'd like to get. But in my case it's just plain old .net 4.6.2 as the targetframework states in my example. edit: this is an answer to a question that I don't see anymore. – aksu Apr 25 '17 at 06:11
  • Not sure if it help but maybe try to override output settings like this: ` – Semant1ka Apr 25 '17 at 06:13
  • `BaseOutputPath` sets the outputpath base for different configurations, so it does not help in this case (I tested this to make sure). Thanks for the suggestion though! – aksu Apr 25 '17 at 06:31
  • The first `/` in `/build/debug/` makes it an absolute path (in Ubuntu at least). – JBSnorro Jun 22 '20 at 18:52

2 Answers2

75

The solution is to use AppendTargetFrameworkToOutputPath https://www.tabsoverspaces.com/233608-stopping-msbuild-appending-targetframework-to-outputpath/

<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
aksu
  • 1,748
  • 1
  • 11
  • 15
  • 13
    to remove the runtime identifier: `false` `false` – Jon Jun 28 '17 at 15:48
  • 1
    Leave it to Microsoft to (1) not give "new .csproj format" a name, (2) have VS IDE create code that doesn't work, and (3) not document the real solution. Too bad, because the solution itself is a good one. – Edward Brey Apr 11 '18 at 11:24
  • 1
    Nowadays there is a note mentioning both these configuration parameters in https://learn.microsoft.com/en-us/visualstudio/ide/how-to-change-the-build-output-directory?view=vs-2019 – aksu Nov 12 '19 at 08:57
42

The answer above is right, but you may also want to remove the runtime identifier:

<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
Jon
  • 835
  • 8
  • 17