Skip to content

Commit

Permalink
Remove all checks regarding $(MSBuildAssemblyVersion) being set or not (
Browse files Browse the repository at this point in the history
#7165)

Remove all checks regarding $(MSBuildAssemblyVersion) being set or not
  • Loading branch information
dfederm authored Jan 7, 2022
1 parent 518c041 commit caf7d29
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 760 deletions.
156 changes: 0 additions & 156 deletions src/Tasks/Microsoft.CSharp.targets

Large diffs are not rendered by default.

85 changes: 11 additions & 74 deletions src/Tasks/Microsoft.Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -63,72 +63,21 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<Import Project="$(MSBuildProjectExtensionsPath)$(MSBuildProjectFile).*.props" Condition="'$(ImportProjectExtensionProps)' == 'true' and exists('$(MSBuildProjectExtensionsPath)')" />

<!--
Import wildcard "ImportBefore" props files if we're actually in a 12.0+ project (rather than a project being
treated as 4.0)
Wildcard imports come from $(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Imports\Microsoft.Common.props\ directory.
This is very similar to the same extension point used in Microsoft.Common.targets, which is located in
the $(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.targets\ directory.
Unfortunately, there is already a file named "Microsoft.Common.props" in this directory,
so we have to have a slightly different directory name to hold extensions.
-->
<ImportGroup Condition="'$(MSBuildAssemblyVersion)' != ''">
<!--
Wildcard imports come from $(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props.d folder.
This is very similar to the same extension point used in Microsoft.Common.targets, which is located in
the $(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.targets\ directory. Unfortunately, there
is already a file named "Microsoft.Common.props" in this directory so we have to have a slightly different
directory name to hold extensions.
-->
<Import Project="$(MSBuildUserExtensionsPath)\$(MSBuildToolsVersion)\Imports\Microsoft.Common.props\ImportBefore\*" Condition="'$(ImportUserLocationsByWildcardBeforeMicrosoftCommonProps)' == 'true' and exists('$(MSBuildUserExtensionsPath)\$(MSBuildToolsVersion)\Imports\Microsoft.Common.props\ImportBefore')"/>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Imports\Microsoft.Common.props\ImportBefore\*" Condition="'$(ImportByWildcardBeforeMicrosoftCommonProps)' == 'true' and exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Imports\Microsoft.Common.props\ImportBefore')"/>
</ImportGroup>

<!--
In VS 2010 SP1 and VS 2012, both supported for asset compatibility, the MSBuild installed
as part of them did not enforce using the local ToolsVersion (4.0) in all cases, but instead
just used whatever ToolsVersion was in the project file if it existed on the machine, and
only forced 4.0 if that ToolsVersion did not exist.
Moving forward, we do want to enforce a single acting ToolsVersion per version of Visual Studio,
but in order to approximate this behavior on VS 2010 SP1 and VS 2012 as well, we've redirected
the targets: If we're building using 4.X MSBuild (which doesn't define the new reserved
property, MSBuildAssemblyVersion), we'll point right back at the 4.0 targets, which still exist
as part of the .NET Framework. Only if we're using the new MSBuild will we point to the current
targets.
-->
<PropertyGroup Condition="'$(MSBuildAssemblyVersion)' == '' and ('$(VisualStudioVersion)' != '' and '$(VisualStudioVersion)' &gt;= '12.0')">
<!--
Reset VisualStudioVersion if it's 12.0+: Should be 10.0 if VS 2010 is installed or 11.0 otherwise,
but since we don't have a good way of telling whether VS 2010 is installed, make it 11.0 if
VS 2012 is installed or 10.0 otherwise. The reset should be safe because if it was already
set to something (e.g. 11.0 in a VS 2012 command prompt) then MSBuild's internal
VisualStudioVersion-defaulting code should never come into the picture, so the only way it could
be 12.0+ when building a TV 12.0 project (because we're in this file) using MSBuild 4.5 (because
MSBuildAssemblyVersion hasn't been set) is if it's a TV 12.0 project on an empty command prompt.
-->
<VisualStudioVersion Condition="Exists('$(MSBuildExtensionsPath)\4.0\Microsoft.Common.props')">11.0</VisualStudioVersion>
<VisualStudioVersion Condition="!Exists('$(MSBuildExtensionsPath)\4.0\Microsoft.Common.props')">10.0</VisualStudioVersion>
</PropertyGroup>

<!-- If building using 4.X MSBuild, we want to act like this project is TV 4.0, so override
the custom extensibility target locations with the hard-coded 4.0 equivalent. -->
<PropertyGroup Condition="'$(MSBuildAssemblyVersion)' == ''">
<CustomBeforeMicrosoftCommonProps Condition="'$(CustomBeforeMicrosoftCommonProps)'==''">$(MSBuildExtensionsPath)\v4.0\Custom.Before.$(MSBuildThisFile)</CustomBeforeMicrosoftCommonProps>
<CustomAfterMicrosoftCommonProps Condition="'$(CustomAfterMicrosoftCommonProps)'==''">$(MSBuildExtensionsPath)\v4.0\Custom.After.$(MSBuildThisFile)</CustomAfterMicrosoftCommonProps>
</PropertyGroup>

<!-- If building using 4.X MSBuild, we want to act like this project is TV 4.0, so import
Microsoft.Common.props from the 4.0 location, and make sure everything else in here is
set up such that if it's defaulted to something there, it won't be overridden here. -->
<Import Project="$(MSBuildExtensionsPath)\4.0\Microsoft.Common.props" Condition="'$(MSBuildAssemblyVersion)' == '' and Exists('$(MSBuildExtensionsPath)\4.0\Microsoft.Common.props')" />
<Import Project="$(MSBuildUserExtensionsPath)\$(MSBuildToolsVersion)\Imports\Microsoft.Common.props\ImportBefore\*" Condition="'$(ImportUserLocationsByWildcardBeforeMicrosoftCommonProps)' == 'true' and exists('$(MSBuildUserExtensionsPath)\$(MSBuildToolsVersion)\Imports\Microsoft.Common.props\ImportBefore')"/>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Imports\Microsoft.Common.props\ImportBefore\*" Condition="'$(ImportByWildcardBeforeMicrosoftCommonProps)' == 'true' and exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Imports\Microsoft.Common.props\ImportBefore')"/>

<PropertyGroup>
<CustomBeforeMicrosoftCommonProps Condition="'$(CustomBeforeMicrosoftCommonProps)'==''">$(MSBuildExtensionsPath)\v$(MSBuildToolsVersion)\Custom.Before.$(MSBuildThisFile)</CustomBeforeMicrosoftCommonProps>
<CustomAfterMicrosoftCommonProps Condition="'$(CustomAfterMicrosoftCommonProps)'==''">$(MSBuildExtensionsPath)\v$(MSBuildToolsVersion)\Custom.After.$(MSBuildThisFile)</CustomAfterMicrosoftCommonProps>
</PropertyGroup>

<!--
Only import the extension targets if we're actually in a 12.0 project here (rather than one we're attempting
to treat as 4.0) OR if the Dev11 Microsoft.Common.props don't exist. If it's a 12.0 project we're redirecting
to 4.0 and the Dev11 Microsoft.Common.props do exist, the extension targets will have been imported already
so there's no need to import them twice.
-->
<Import Project="$(CustomBeforeMicrosoftCommonProps)" Condition="'$(CustomBeforeMicrosoftCommonProps)' != '' and Exists('$(CustomBeforeMicrosoftCommonProps)') and ('$(MSBuildAssemblyVersion)' != '' or !Exists('$(MSBuildExtensionsPath)\4.0\Microsoft.Common.props'))" />
<Import Project="$(CustomBeforeMicrosoftCommonProps)" Condition="'$(CustomBeforeMicrosoftCommonProps)' != '' and Exists('$(CustomBeforeMicrosoftCommonProps)')" />

<!-- This is used to determine whether Microsoft.Common.targets needs to import
Microsoft.Common.props itself, or whether it has been imported previously,
Expand All @@ -149,22 +98,10 @@ Copyright (C) Microsoft Corporation. All rights reserved.

<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.VisualStudioVersion.v*.Common.props" Condition="'$(VisualStudioVersion)' == ''" />

<!--
Only import the extension targets if we're actually in a 12.0 project here (rather than one we're attempting
to treat as 4.0) OR if the Dev11 Microsoft.Common.props don't exist. If it's a 12.0 project we're redirecting
to 4.0 and the Dev11 Microsoft.Common.props do exist, the extension targets will have been imported already
so there's no need to import them twice.
-->
<Import Project="$(CustomAfterMicrosoftCommonProps)" Condition="'$(CustomAfterMicrosoftCommonProps)' != '' and Exists('$(CustomAfterMicrosoftCommonProps)') and ('$(MSBuildAssemblyVersion)' != '' or !Exists('$(MSBuildExtensionsPath)\4.0\Microsoft.Common.props'))" />
<Import Project="$(CustomAfterMicrosoftCommonProps)" Condition="'$(CustomAfterMicrosoftCommonProps)' != '' and Exists('$(CustomAfterMicrosoftCommonProps)')" />

<!--
Import wildcard "ImportAfter" props files if we're actually in a 12.0+ project (rather than a project being
treated as 4.0)
-->
<ImportGroup Condition="'$(MSBuildAssemblyVersion)' != ''">
<Import Project="$(MSBuildUserExtensionsPath)\$(MSBuildToolsVersion)\Imports\Microsoft.Common.props\ImportAfter\*" Condition="'$(ImportUserLocationsByWildcardAfterMicrosoftCommonProps)' == 'true' and exists('$(MSBuildUserExtensionsPath)\$(MSBuildToolsVersion)\Imports\Microsoft.Common.props\ImportAfter')"/>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Imports\Microsoft.Common.props\ImportAfter\*" Condition="'$(ImportByWildcardAfterMicrosoftCommonProps)' == 'true' and exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Imports\Microsoft.Common.props\ImportAfter')"/>
</ImportGroup>
<Import Project="$(MSBuildUserExtensionsPath)\$(MSBuildToolsVersion)\Imports\Microsoft.Common.props\ImportAfter\*" Condition="'$(ImportUserLocationsByWildcardAfterMicrosoftCommonProps)' == 'true' and exists('$(MSBuildUserExtensionsPath)\$(MSBuildToolsVersion)\Imports\Microsoft.Common.props\ImportAfter')"/>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Imports\Microsoft.Common.props\ImportAfter\*" Condition="'$(ImportByWildcardAfterMicrosoftCommonProps)' == 'true' and exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Imports\Microsoft.Common.props\ImportAfter')"/>

<!--
Import NuGet.props file.
Expand Down
Loading

0 comments on commit caf7d29

Please sign in to comment.