Skip to content

Commit

Permalink
Move workload targets imports
Browse files Browse the repository at this point in the history
Workload targets imports now go soon after target framework inference, allowing
them to override property defaults from the .NET SDK
  • Loading branch information
dsplaisted committed Nov 1, 2020
1 parent a1096f8 commit 6bf1cba
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<ImportFrameworkWinFXTargets Condition="'$(ImportFrameworkWinFXTargets)' == ''">false</ImportFrameworkWinFXTargets>
</PropertyGroup>

<!-- For .NET Framework, reference core assemblies -->
<PropertyGroup>
<_TargetFrameworkVersionWithoutV>$(TargetFrameworkVersion.TrimStart('vV'))</_TargetFrameworkVersionWithoutV>
</PropertyGroup>
Expand All @@ -67,6 +66,25 @@ Copyright (c) .NET Foundation. All rights reserved.
-->
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.RuntimeIdentifierInference.targets" />


<!-- Import workload targets -->
<Import Project="Microsoft.NET.Sdk.ImportWorkloads.targets" Condition="'$(MSBuildEnableWorkloadResolver)' == 'true'" />

<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Windows.targets" Condition="'$(TargetPlatformIdentifier)' == 'Windows'" />
<Import Project="$(MSBuildThisFileDirectory)../../Microsoft.NET.Sdk.WindowsDesktop/targets/Microsoft.NET.Sdk.WindowsDesktop.targets" Condition="'$(ImportWindowsDesktopTargets)' == 'true'"/>


<PropertyGroup Condition="'$(TargetPlatformIdentifier)' != ''">
<!-- Set TargetPlatformVersion if it isn't set. This is so that we have a valid TargetPlatformMoniker for Restore.
This avoids an issue where projects with multitargeted unknown platforms would fail to restore because the platforms
weren't included in the TargetPlatformMoniker for restore, obscuring the errors about unknown platforms or missing
workloads. -->
<TargetPlatformVersion Condition="'$(TargetPlatformVersion)' == ''">0.0</TargetPlatformVersion>

<!-- Default SupportedOSPlatformVersion to TargetPlatformVersion -->
<SupportedOSPlatformVersion Condition="'$(SupportedOSPlatformVersion)' == ''">$(TargetPlatformVersion)</SupportedOSPlatformVersion>
</PropertyGroup>

<!-- Checks for EOL frameworks -->
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.EolTargetFrameworks.targets" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1027,26 +1027,4 @@ Copyright (c) .NET Foundation. All rights reserved.
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.FSharp.targets" Condition="'$(Language)' == 'F#'" />
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.ILLink.targets" />
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.Analyzers.targets" Condition="'$(Language)' == 'C#' or '$(Language)' == 'VB'" />
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Windows.targets" Condition="'$(TargetPlatformIdentifier)' == 'Windows'" />
<Import Project="$(MSBuildThisFileDirectory)../../Microsoft.NET.Sdk.WindowsDesktop/targets/Microsoft.NET.Sdk.WindowsDesktop.targets" Condition="'$(ImportWindowsDesktopTargets)' == 'true'"/>

<!-- Import workload targets -->
<Import Project="Microsoft.NET.Sdk.ImportWorkloads.targets" Condition="'$(MSBuildEnableWorkloadResolver)' == 'true'" />

<!-- TargetPlatformMoniker and TargetPlatformDisplayName would normally be set in Microsoft.Common.CurrentVersion.targets. However, the
TargetPlatformVersion may have been set later than that in evaluation by platform-specific targets. So fix up those properties here -->
<PropertyGroup Condition="'$(TargetPlatformMoniker)' == '' and '$(TargetPlatformIdentifier)' != ''">
<!-- Set TargetPlatformVersion if it isn't set. This is so that we have a valid TargetPlatformMoniker for Restore.
This avoids an issue where projects with multitargeted unknown platforms would fail to restore because the platforms
weren't included in the TargetPlatformMoniker for restore, obscuring the errors about unknown platforms or missing
workloads. -->
<TargetPlatformVersion Condition="'$(TargetPlatformVersion)' == ''">0.0</TargetPlatformVersion>
<TargetPlatformMoniker>$(TargetPlatformIdentifier),Version=$(TargetPlatformVersion)</TargetPlatformMoniker>
<TargetPlatformDisplayName>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetPlatformSDKDisplayName($(TargetPlatformIdentifier), $(TargetPlatformVersion)))</TargetPlatformDisplayName>
</PropertyGroup>

<!-- Default SupportedOSPlatformVersion to TargetPlatformVersion -->
<PropertyGroup Condition="'$(SupportedOSPlatformVersion)' == ''">
<SupportedOSPlatformVersion>$(TargetPlatformVersion)</SupportedOSPlatformVersion>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,7 @@ Copyright (c) .NET Foundation. All rights reserved.

<!-- Exclude files from OutputPath and IntermediateOutputPath from default item globs. Use the value
of these properties before the TargetFramework is appended, so that if these values are specified
in the project file, the specified value will be used for the exclude.
We may be able to move this to Microsoft.NET.Sdk.DefaultItems.targets (where the other DefaultItemExcludes
are defined) if we fix https://github.com/dotnet/sdk/issues/550
-->
in the project file, the specified value will be used for the exclude. -->
<PropertyGroup>
<DefaultItemExcludes>$(DefaultItemExcludes);$(OutputPath)/**</DefaultItemExcludes>
<DefaultItemExcludes>$(DefaultItemExcludes);$(IntermediateOutputPath)/**</DefaultItemExcludes>
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/Microsoft.NET.Build.Tests/WorkloadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void It_should_fail_without_workload_when_multitargeted()
}

[CoreMSBuildOnlyFact]
public void It_should_fail_without_when_multitargeted_to_unknown_platforms()
public void It_should_fail_when_multitargeted_to_unknown_platforms()
{
var testProject = new TestProject()
{
Expand Down

0 comments on commit 6bf1cba

Please sign in to comment.