Visualstudio-docs: Overriding OutputPath in Directory.Build.targets

Created on 28 Mar 2018  Â·  5Comments  Â·  Source: MicrosoftDocs/visualstudio-docs

I am trying to override OutputPath from Directory.Build.targets...

Is this a supported property to override?


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Most helpful comment

It works, thanks to help from Daniel Cazzulino [MSFT]. Updated instructions: Firstly, put the following in the Directory.Build.props file:

<?xml version="1.0" encoding="utf-8"?>
<Project>
   <PropertyGroup>
      <BaseIntermediateOutputPath>C:\VS Build Output\$(MSBuildProjectFile) Intermediate\</BaseIntermediateOutputPath>
      <OutputPath>C:\VS Build Output\$(MSBuildProjectFile) Output\$(Configuration)\</OutputPath>
   </PropertyGroup>
</Project>

Then you must delete the two elements in every ".csproj" file because the properties in a ".csproj" take precedence over those in Directory.Build.props.

If VS displays an error saying that the OutputPath property is not set, then close and reopen the ".sln", and it should pick up the OutputPath specified in the Directory.Build.props file.

A <BaseOutputPath> property does not exist (VS 15.8.3), or if it does exist, then it didn't work for me, therefore I used <OutputPath> with $(Configuration) to achieve the same effect.

All 5 comments

Me too. I tested Directory.Build.props in VS 15.8.2 and either it doesn't work for OutputPath or I wrote the wrong XML. It works great for BaseIntermediateOutputPath but not for OutputPath. I tried a number of variations and I also tried Directory.Build.targets, but I was unable to override OutputPath. For example, I put the following in Directory.Build.props, and BaseIntermediateOutputPath works great but not OutputPath.

<?xml version="1.0" encoding="utf-8"?>
<Project>
   <PropertyGroup>
      <BaseIntermediateOutputPath>C:\VS Build Output\$(MSBuildProjectFile) Intermediate\</BaseIntermediateOutputPath>
      <OutputPath>C:\VS Build Output\$(MSBuildProjectFile) Output\$(Configuration)\</OutputPath>
   </PropertyGroup>
</Project>

What exactly should the Directory.Build.props file contain? And should the line <OutputPath>bin\Debug\</OutputPath> be deleted from every .csproj file or can Directory.Build.props or Directory.Build.targets override it? Thanks.

It works, thanks to help from Daniel Cazzulino [MSFT]. Updated instructions: Firstly, put the following in the Directory.Build.props file:

<?xml version="1.0" encoding="utf-8"?>
<Project>
   <PropertyGroup>
      <BaseIntermediateOutputPath>C:\VS Build Output\$(MSBuildProjectFile) Intermediate\</BaseIntermediateOutputPath>
      <OutputPath>C:\VS Build Output\$(MSBuildProjectFile) Output\$(Configuration)\</OutputPath>
   </PropertyGroup>
</Project>

Then you must delete the two elements in every ".csproj" file because the properties in a ".csproj" take precedence over those in Directory.Build.props.

If VS displays an error saying that the OutputPath property is not set, then close and reopen the ".sln", and it should pick up the OutputPath specified in the Directory.Build.props file.

A <BaseOutputPath> property does not exist (VS 15.8.3), or if it does exist, then it didn't work for me, therefore I used <OutputPath> with $(Configuration) to achieve the same effect.

I get the first one, but I thought that $(Configuration) is disallowed in that context since it's too early

@damageboy
I don't know the answer to that question (re too early or not), but it worked for me in VS 15.8.3. I think a good simple solution to this ambiguity would be for Microsoft to create a BaseOutputPath property akin to BaseIntermediateOutputPath, and then the use of $(Configuration) would be no longer necessary in this situation.

Since a solution to the issue has been found, I'm going to close this issue. If you want to make a feature suggestion, please do so on Developer Community.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tpodolak picture tpodolak  Â·  3Comments

JeepNL picture JeepNL  Â·  3Comments

patrikhuber picture patrikhuber  Â·  4Comments

ChrisMaddock picture ChrisMaddock  Â·  3Comments

H35am picture H35am  Â·  4Comments