I am trying to override OutputPath from Directory.Build.targets...
Is this a supported property to override?
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
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 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.
Most helpful comment
It works, thanks to help from Daniel Cazzulino [MSFT]. Updated instructions: Firstly, put the following in the
Directory.Build.propsfile: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
OutputPathproperty is not set, then close and reopen the ".sln", and it should pick up theOutputPathspecified in theDirectory.Build.propsfile.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.