Skip to content

Commit

Permalink
Support Common output via BuildDir and PublishDir
Browse files Browse the repository at this point in the history
Promote PublishDir to BuildDir status
Use BuildDir to initialize MSBuildProjectExtensionsPath
Use BuildDir for mismatch warning instead of BaseIntermediateOutputPath
  • Loading branch information
Nirmal4G committed Dec 25, 2020
1 parent 86939e5 commit a9563c0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
29 changes: 17 additions & 12 deletions src/Tasks/Microsoft.Common.CurrentVersion.targets
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ Copyright (C) Microsoft Corporation. All rights reserved.
Several properties must be set in the main project file, before using this .TARGETS file.
However, if the properties are not set, we pick some defaults.
BuildDir:
Indicates the final output location for the project or solution.
All the *OutpuPath properties should derive from this.
OutDir:
Indicates the final output location for the project or solution. When building a solution,
OutDir can be used to gather multiple project outputs in one location. In addition,
Expand Down Expand Up @@ -142,6 +146,8 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<_OutputPathWasMissing Condition="'$(_OriginalPlatform)' != '' and '$(_OriginalConfiguration)' != '' and '$(OutputPath)' == ''">true</_OutputPathWasMissing>
<!-- Check whether BaseOutputPath was specified -->
<BaseOutputPathWasSpecified Condition="'$(BaseOutputPath)' != ''">true</BaseOutputPathWasSpecified>
<!-- Initialize BuildDir when empty, to ensure build doesn't produce inconsistent paths -->
<BuildDir>$([MSBuild]::EnsureTrailingSlash($([MSBuild]::ValueOrDefault('$(BuildDir)', 'build'))))</BuildDir>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -150,12 +156,12 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
<ConfigurationName Condition="'$(ConfigurationName)' == ''">$(Configuration)</ConfigurationName>

<BaseOutputPath>$([MSBuild]::EnsureTrailingSlash($([MSBuild]::ValueOrDefault('$(BaseOutputPath)', 'bin'))))</BaseOutputPath>
<BaseOutputPath>$([MSBuild]::EnsureTrailingSlash($([MSBuild]::ValueOrDefault('$(BaseOutputPath)', '$(BuildDir)bin'))))</BaseOutputPath>
<OutputPath Condition="'$(OutputPath)' == '' and '$(PlatformName)' == 'AnyCPU'">$([System.IO.Path]::Combine('$(BaseOutputPath)', '$(Configuration)'))</OutputPath>
<OutputPath Condition="'$(OutputPath)' == '' and '$(PlatformName)' != 'AnyCPU'">$([System.IO.Path]::Combine('$(BaseOutputPath)', '$(PlatformName)', '$(Configuration)'))</OutputPath>
<OutputPath>$([MSBuild]::EnsureTrailingSlash('$(OutputPath)'))</OutputPath>

<BaseIntermediateOutputPath>$([MSBuild]::EnsureTrailingSlash($([MSBuild]::ValueOrDefault('$(BaseIntermediateOutputPath)', 'obj'))))</BaseIntermediateOutputPath>
<BaseIntermediateOutputPath>$([MSBuild]::EnsureTrailingSlash($([MSBuild]::ValueOrDefault('$(BaseIntermediateOutputPath)', '$(BuildDir)obj'))))</BaseIntermediateOutputPath>
<IntermediateOutputPath Condition="'$(IntermediateOutputPath)' == '' and '$(PlatformName)' == 'AnyCPU'">$([System.IO.Path]::Combine('$(BaseIntermediateOutputPath)', '$(Configuration)'))</IntermediateOutputPath>
<IntermediateOutputPath Condition="'$(IntermediateOutputPath)' == '' and '$(PlatformName)' != 'AnyCPU'">$([System.IO.Path]::Combine('$(BaseIntermediateOutputPath)', '$(PlatformName)', '$(Configuration)'))</IntermediateOutputPath>
<IntermediateOutputPath>$([MSBuild]::EnsureTrailingSlash('$(IntermediateOutputPath)'))</IntermediateOutputPath>
Expand Down Expand Up @@ -476,7 +482,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.

<!-- Output location for publish target. -->
<PropertyGroup>
<PublishDir>$([MSBuild]::EnsureTrailingSlash($([MSBuild]::ValueOrDefault('$(PublishDir)', '$(OutputPath)app.publish'))))</PublishDir>
<PublishDir>$([MSBuild]::EnsureTrailingSlash($([MSBuild]::ValueOrDefault('$(PublishDir)', 'publish'))))</PublishDir>
</PropertyGroup>

<!--
Expand Down Expand Up @@ -839,17 +845,16 @@ Copyright (C) Microsoft Corporation. All rights reserved.

<!--
Log a warning if:
1. $(EnableBaseIntermediateOutputPathMismatchWarning) is 'true'
2. $(BaseIntermediateOutputPath) was set in the body of a project after its default value was set in Microsoft.Common.props
3. $(BaseIntermediateOutputPath) is not the same as $(MSBuildProjectExtensionsPath)
1. $(EnableBuildDirMismatchWarning) is 'true'
2. $(BuildDir) was set in the body of a project after its default value was set in Microsoft.Common.props
3. $(BuildDir) is not the same as $(MSBuildProjectExtensionsPath)
Similar to the error above, there are cases when users set $(BaseIntermediateOutputPath) in the body of their project and things build but only by coincidence.
MSBuild does not know if $(BaseIntermediateOutputPath) changing would cause problems so tools like NuGet must set $(EnableBaseIntermediateOutputPathMismatchWarning)
to 'true'.
Similar to the error above, there are cases when users set $(BuildDir) in the body of their project and things build but only by coincidence.
MSBuild does not know if $(BuildDir) changing would cause problems so tools like NuGet must set $(EnableBuildDirMismatchWarning) to 'true'.
-->
<Warning Condition=" '$(EnableBaseIntermediateOutputPathMismatchWarning)' == 'true' And '$(_InitialBaseIntermediateOutputPath)' != '$(BaseIntermediateOutputPath)' And '$(BaseIntermediateOutputPath)' != '$(MSBuildProjectExtensionsPath)' "
<Warning Condition=" '$(EnableBuildDirMismatchWarning)' == 'true' And '$(_InitialBuildDir)' != '$(BuildDir)' And '$(BuildDir)' != '$(MSBuildProjectExtensionsPath)' "
Code="MSB3539"
Text="The value of the property &quot;BaseIntermediateOutputPath&quot; was modified after it was used by MSBuild which can lead to unexpected build results. Tools such as NuGet will write outputs to the path specified by the &quot;MSBuildProjectExtensionsPath&quot; instead. To set this property, you must do so before Microsoft.Common.props is imported, for example by using Directory.Build.props. For more information, please visit https://go.microsoft.com/fwlink/?linkid=869650"
Text="The value of the property &quot;BuildDir&quot; was modified after it was used by MSBuild which can lead to unexpected build results. Tools such as NuGet will write outputs to the path specified by the &quot;MSBuildProjectExtensionsPath&quot; instead. To set this property, you must do so before Microsoft.Common.props is imported, for example by using Directory.Build.props. For more information, please visit https://go.microsoft.com/fwlink/?linkid=869650"
/>
</Target>

Expand Down Expand Up @@ -5471,7 +5476,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.

<RemoveDir
Directories="$(PublishDir)"
Condition="'$(PublishDir)'=='$(OutputPath)app.publish\' and Exists('$(PublishDir)')"/>
Condition="'$(PublishDir)' == '$([MSBuild]::EnsureTrailingSlash(`publish`))' and Exists('$(PublishDir)')"/>

</Target>

Expand Down
12 changes: 6 additions & 6 deletions src/Tasks/Microsoft.Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<Import Project="$(DirectoryBuildPropsPath)" Condition="'$(ImportDirectoryBuildProps)' == 'true' and exists('$(DirectoryBuildPropsPath)')"/>

<!--
The declaration of $(BaseIntermediateOutputPath) had to be moved up from Microsoft.Common.CurrentVersion.targets
in order for the $(MSBuildProjectExtensionsPath) to use it as a default.
The $(BuildDir) replaces $(BaseIntermediateOutputPath) to enable common root output path across multiple projects
and for the $(MSBuildProjectExtensionsPath) to use it as a default.
-->
<PropertyGroup>
<BaseIntermediateOutputPath>$([MSBuild]::EnsureTrailingSlash($([MSBuild]::ValueOrDefault('$(BaseIntermediateOutputPath)', 'obj'))))</BaseIntermediateOutputPath>
<_InitialBaseIntermediateOutputPath>$(BaseIntermediateOutputPath)</_InitialBaseIntermediateOutputPath>
<BuildDir>$([MSBuild]::EnsureTrailingSlash($([MSBuild]::ValueOrDefault('$(BuildDir)', 'build'))))</BuildDir>
<_InitialBuildDir>$(BuildDir)</_InitialBuildDir>
</PropertyGroup>

<!--
Expand All @@ -49,10 +49,10 @@ Copyright (C) Microsoft Corporation. All rights reserved.
management system can write out multiple files but the order of the import is alphabetic because MSBuild sorts the list.
-->
<PropertyGroup>
<MSBuildProjectExtensionsPath>$([MSBuild]::EnsureTrailingSlash($([MSBuild]::ValueOrDefault('$(MSBuildProjectExtensionsPath)', '$(BaseIntermediateOutputPath)'))))</MSBuildProjectExtensionsPath>
<MSBuildProjectExtensionsPath>$([MSBuild]::EnsureTrailingSlash($([MSBuild]::ValueOrDefault('$(MSBuildProjectExtensionsPath)', '$(BuildDir)'))))</MSBuildProjectExtensionsPath>
<!--
Import paths that are relative default to be relative to the importing file. However, since MSBuildExtensionsPath
defaults to BaseIntermediateOutputPath we expect it to be relative to the project directory. So if the path is relative
defaults to BuildDir we expect it to be relative to the project directory. So if the path is relative
it needs to be made absolute based on the project directory.
-->
<MSBuildProjectExtensionsPath Condition="!$([System.IO.Path]::IsPathRooted('$(MSBuildProjectExtensionsPath)'))">$([MSBuild]::NormalizeDirectory('$(MSBuildProjectDirectory)', '$(MSBuildProjectExtensionsPath)'))</MSBuildProjectExtensionsPath>
Expand Down

0 comments on commit a9563c0

Please sign in to comment.