Skip to content

Commit

Permalink
Use $(TargetFrameworkIdentifier) and $(TargetFrameworkVersion) co…
Browse files Browse the repository at this point in the history
…nsistently

- always use `$([MSBuild]::VersionXYZ(...))` for version checks
- use `$(NETCoreAppFrameworkIdentifier)` where it's available
- move `$(KnownAppHostPackOrFrameworkReferenceTfm)` setting to Directory.Build.props
  - use it to correct `@(KnownFrameworkReference)` updates
  - metadata of those items still uses `netcoreapp5.0`
  - see also dotnet/efcore#22279 (comment)

nits:
- do not assume `$(TargetFrameworkVersion)` starts with a 'v'; valid w/o it
- add `$(_IsMicrosoftNETCoreApp20OrOlder)` property in OpenAPI targets file
  - evaluate the `Condition` once instead of three times
  • Loading branch information
dougbu committed Aug 30, 2020
1 parent b4a198c commit 44696c8
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 20 deletions.
12 changes: 9 additions & 3 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,20 @@
<AssemblyVersion>$(AspNetCoreMajorVersion).$(AspNetCoreMinorVersion).0.0</AssemblyVersion>
</PropertyGroup>

<PropertyGroup>
<KnownAppHostPackOrFrameworkReferenceTfm>$(DefaultNetCoreTargetFramework)</KnownAppHostPackOrFrameworkReferenceTfm>
<KnownAppHostPackOrFrameworkReferenceTfm Condition=" '$(TargetFrameworkIdentifier)' == '$(NETCoreAppFrameworkIdentifier)' AND
$([MSBuild]::VersionGreaterThanOrEquals('$(TargetFrameworkVersion)', '5.0')) ">netcoreapp$(TargetFrameworkVersion.TrimStart('vV'))</KnownAppHostPackOrFrameworkReferenceTfm>
</PropertyGroup>

<ItemGroup>
<KnownFrameworkReference Update="Microsoft.NETCore.App">
<!-- Always update the 'latest version', whether the repo is servicing or not. -->
<LatestRuntimeFrameworkVersion Condition="'%(TargetFramework)' == '$(DefaultNetCoreTargetFramework)'">$(MicrosoftNETCoreAppRuntimeVersion)</LatestRuntimeFrameworkVersion>
<LatestRuntimeFrameworkVersion Condition="'%(TargetFramework)' == '$(KnownAppHostPackOrFrameworkReferenceTfm)'">$(MicrosoftNETCoreAppRuntimeVersion)</LatestRuntimeFrameworkVersion>
<!-- Only update the default runtime version for preview builds. -->
<DefaultRuntimeFrameworkVersion Condition="'%(TargetFramework)' == '$(DefaultNetCoreTargetFramework)' and '$(IsServicingBuild)' != 'true'">$(MicrosoftNETCoreAppRuntimeVersion)</DefaultRuntimeFrameworkVersion>
<DefaultRuntimeFrameworkVersion Condition="'%(TargetFramework)' == '$(KnownAppHostPackOrFrameworkReferenceTfm)' and '$(IsServicingBuild)' != 'true'">$(MicrosoftNETCoreAppRuntimeVersion)</DefaultRuntimeFrameworkVersion>
<!-- Only update the targeting pack version for preview builds. -->
<TargetingPackVersion Condition="'%(TargetFramework)' == '$(DefaultNetCoreTargetFramework)' and '$(IsServicingBuild)' != 'true'">$(MicrosoftNETCoreAppRefPackageVersion)</TargetingPackVersion>
<TargetingPackVersion Condition="'%(TargetFramework)' == '$(KnownAppHostPackOrFrameworkReferenceTfm)' and '$(IsServicingBuild)' != 'true'">$(MicrosoftNETCoreAppRefPackageVersion)</TargetingPackVersion>
</KnownFrameworkReference>

<KnownFrameworkReference Condition="'$(UseAspNetCoreSharedRuntime)' != 'true'" Remove="Microsoft.AspNetCore.App" />
Expand Down
9 changes: 3 additions & 6 deletions eng/Workarounds.targets
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
<ItemGroup>
<FrameworkReference Remove="Microsoft.AspNetCore.App" Condition="'$(DoNotApplyWorkaroundsToMicrosoftAspNetCoreApp)' != 'true'" />
<!-- Required because the Razor SDK will generate attributes -->
<Reference Include="Microsoft.AspNetCore.Mvc" Condition="'$(UsingMicrosoftNETSdkWeb)' == 'true' AND '$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(GenerateRazorAssemblyInfo)' == 'true'" />
<Reference Include="Microsoft.AspNetCore.Mvc" Condition="'$(UsingMicrosoftNETSdkWeb)' == 'true' AND
'$(TargetFrameworkIdentifier)' == '$(NETCoreAppFrameworkIdentifier)' AND
'$(GenerateRazorAssemblyInfo)' == 'true'" />
</ItemGroup>

<!-- Workaround https://github.com/dotnet/aspnetcore/issues/7503. This chains GenerateSourceLinkFile before razor component targets run. -->
Expand All @@ -40,11 +42,6 @@
<PackageReference Include="Internal.AspNetCore.BuildTasks" PrivateAssets="All" Version="$(InternalAspNetCoreBuildTasksPackageVersion)" IsImplicitlyDefined="true" />
</ItemGroup>

<PropertyGroup>
<KnownAppHostPackOrFrameworkReferenceTfm>$(DefaultNetCoreTargetFramework)</KnownAppHostPackOrFrameworkReferenceTfm>
<KnownAppHostPackOrFrameworkReferenceTfm Condition="'$(KnownAppHostPackOrFrameworkReferenceTfm)' == 'net5.0'">netcoreapp5.0</KnownAppHostPackOrFrameworkReferenceTfm>
</PropertyGroup>

<ItemGroup>
<!-- Workaround when there is no vNext SDK available, copy known apphost/framework reference info from 3.1 -->
<KnownAppHostPack
Expand Down
2 changes: 1 addition & 1 deletion eng/targets/CSharp.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- For 'legacy' .csproj files, set map TargetFrameworkVersion back to TargetFramework -->
<PropertyGroup Condition=" '$(TargetFramework)' == '' AND '$(TargetFrameworks)' == '' ">
<TargetFramework>net$(TargetFrameworkVersion.Substring(1).Replace('.',''))</TargetFramework>
<TargetFramework>net$(TargetFrameworkVersion.TrimStart('vV').Replace('.',''))</TargetFramework>
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ Copyright (c) .NET Foundation. All rights reserved.

<!-- Resolve the RazorLangVersion based on values imported or TFM. -->
<PropertyGroup>
<_TargetFrameworkVersionWithoutV>$(TargetFrameworkVersion.TrimStart('vV'))</_TargetFrameworkVersionWithoutV>
<_TargetingNETCoreApp30OrLater Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(_TargetFrameworkVersionWithoutV)' >= '3.0'">true</_TargetingNETCoreApp30OrLater>
<_TargetingNET50OrLater Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(_TargetFrameworkVersionWithoutV)' >= '5.0'">true</_TargetingNET50OrLater>
<_TargetingNETCoreApp30OrLater Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND
$([MSBuild]::VersionGreaterThanOrEquals('$(TargetFrameworkVersion)', '3.0')) ">true</_TargetingNETCoreApp30OrLater>
<_TargetingNET50OrLater Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND
$([MSBuild]::VersionGreaterThanOrEquals('$(TargetFrameworkVersion)', '5.0')) ">true</_TargetingNET50OrLater>

<!--
Infer the RazorLangVersion if no value was specified. When adding support for newer target frameworks, list newer language versions first.
Expand Down Expand Up @@ -227,7 +228,10 @@ Copyright (c) .NET Foundation. All rights reserved.
<CopyRefAssembliesToPublishDirectory Condition="'$(CopyRefAssembliesToPublishDirectory)'==''">$(PreserveCompilationReferences)</CopyRefAssembliesToPublishDirectory>

<!-- For 2.x projects desktop and .NET Core projects, if they're opting in to runtime compilation (indicated by PreserveCompilationContext=true), set PreserveCompilationReferences = true -->
<PreserveCompilationReferences Condition="'$(PreserveCompilationContext)' == 'true' AND (('$(TargetFrameworkIdentifier)' == '.NETFramework') OR ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(_TargetFrameworkVersionWithoutV)' &lt; '3.0'))">true</PreserveCompilationReferences>
<PreserveCompilationReferences Condition=" '$(PreserveCompilationContext)' == 'true' AND
('$(TargetFrameworkIdentifier)' == '.NETFramework' OR
('$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND
'$(_TargetingNETCoreApp30OrLater)' != 'true')) ">true</PreserveCompilationReferences>

<!--
We can't set the actual default value here due to evaluation order (depends on $(OutDir)).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project>
<PropertyGroup>
<_IsMicrosoftNETCoreApp20OrOlder>false</_IsMicrosoftNETCoreApp20OrOlder>
<_IsMicrosoftNETCoreApp20OrOlder Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND
$([MSBuild]::VersionLessThanOrEquals('$(TargetFrameworkVersion)', '2.0') ">true</_IsMicrosoftNETCoreApp20OrOlder>
</PropertyGroup>
<PropertyGroup Condition=" '$(OpenApiGenerateDocuments)' == '' ">
<OpenApiGenerateDocuments>true</OpenApiGenerateDocuments>
<OpenApiGenerateDocuments
Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(TargetFrameworkVersion.TrimStart(&quot;vV&quot;))' &lt; '2.1' " />
<OpenApiGenerateDocuments Condition=" $(_IsMicrosoftNETCoreApp20OrOlder) " />
</PropertyGroup>
<PropertyGroup Condition=" '$(OpenApiGenerateDocumentsOnBuild)' == '' ">
<OpenApiGenerateDocumentsOnBuild>$(OpenApiGenerateDocuments)</OpenApiGenerateDocumentsOnBuild>
Expand All @@ -22,7 +26,7 @@
Text="OpenAPI document generation is disabled. Add '&lt;OpenApiGenerateDocuments>true&lt;/OpenApiGenerateDocuments>' to the project." />
<!-- E.g. project set $(OpenApiGenerateDocuments) to 'true' but TFM is not supported. -->
<Error
Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(TargetFrameworkVersion.TrimStart(&quot;vV&quot;))' &lt; '2.1' "
Condition=" $(_IsMicrosoftNETCoreApp20OrOlder) "
Text="OpenAPI document generation is not supported when targeting netcoreapp2.0 or earlier. Disable the feature or move to a later target framework." />
<!-- E.g. project set $(OpenApiGenerateDocumentsOnBuild) to 'false' but did not invoke GenerateOpenApiDocuments. -->
<Error Condition=" !Exists('$(_OpenApiDocumentsCache)' )"
Expand All @@ -43,7 +47,7 @@
Text="OpenAPI document generation is disabled. Add '&lt;OpenApiGenerateDocuments>true&lt;/OpenApiGenerateDocuments>' to the project." />
<!-- E.g. project sets $(OpenApiGenerateDocuments) to 'true' but TFM is not supported. -->
<Error
Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(TargetFrameworkVersion.TrimStart(&quot;vV&quot;))' &lt; '2.1' "
Condition=" $(_IsMicrosoftNETCoreApp20OrOlder) "
Text="OpenAPI document generation is not supported when targeting netcoreapp2.0 or earlier. Disable the feature or move to a later target framework." />

<PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Tools/dotnet-watch/src/assets/DotNetWatch.targets
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ them to a file.
DependsOnTargets="_CollectWatchItems">

<PropertyGroup>
<_IsMicrosoftNETCoreApp31OrNewer
Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '3.1'))">true</_IsMicrosoftNETCoreApp31OrNewer>
<_IsMicrosoftNETCoreApp31OrNewer Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND
$([MSBuild]::VersionGreaterThanOrEquals('$(TargetFrameworkVersion)', '3.1'))">true</_IsMicrosoftNETCoreApp31OrNewer>

<_IsMicrosoftNETCoreApp31OrNewer Condition="'$(_IsMicrosoftNETCoreApp31OrNewer)' == ''">false</_IsMicrosoftNETCoreApp31OrNewer>
</PropertyGroup>
Expand Down

0 comments on commit 44696c8

Please sign in to comment.