-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Microsoft.NET.TargetFrameworkInference.targets
109 lines (91 loc) · 6.31 KB
/
Microsoft.NET.TargetFrameworkInference.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!--
***********************************************************************************************
Microsoft.NET.TargetFrameworkInference.targets
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.
Copyright (c) .NET Foundation. All rights reserved.
***********************************************************************************************
-->
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
Note that this file is only included when $(TargetFramework) is set and so we do not need to check that here.
Common targets require that $(TargetFrameworkIdentifier) and $(TargetFrameworkVersion) are set by static evaluation
before they are imported. In common cases (currently netstandard, netcoreapp, or net), we infer them from the short
names given via TargetFramework to allow for terseness and lack of duplication in project files.
For other cases, the user must supply them manually.
For cases where inference is supported, the user need only specify the targets in TargetFrameworks, e.g:
<PropertyGroup>
<TargetFrameworks>net45;netstandard1.0</TargetFrameworks>
</PropertyGroup>
For cases where inference is not supported, identifier, version and profile can be specified explicitly as follows:
<PropertyGroup>
<TargetFrameworks>portable-net451+win81;xyz1.0</TargetFrameworks>
<PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'portable-net451+win81'">
<TargetFrameworkIdentifier>.NETPortable</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<TargetFrameworkProfile>Profile44</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'xyz1.0'">
<TargetFrameworkIdentifier>Xyz</TargetFrameworkVersion>
<PropertyGroup>
Note in the xyz1.0 case, which is meant to demonstrate a framework we don't yet recognize, we can still
infer the version of 1.0. The user can also override it as always we honor a TargetFrameworkIdentifier
or TargetFrameworkVersion that is already set.
-->
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
<!-- Split $(TargetFramework) (e.g. net45) into short identifier and short version (e.g. 'net' and '45'). -->
<PropertyGroup Condition="'$(TargetFramework)' != '' and !$(TargetFramework.Contains(',')) and !$(TargetFramework.Contains('+'))">
<_ShortFrameworkIdentifier>$(TargetFramework.TrimEnd('.0123456789'))</_ShortFrameworkIdentifier>
<_ShortFrameworkVersion>$(TargetFramework.Substring($(_ShortFrameworkIdentifier.Length)))</_ShortFrameworkVersion>
</PropertyGroup>
<!-- Map short name to long name. See earlier comment for example of how to work with identifiers that are not recognized here. -->
<PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == ''">
<TargetFrameworkIdentifier Condition="'$(_ShortFrameworkIdentifier)' == 'netstandard'">.NETStandard</TargetFrameworkIdentifier>
<TargetFrameworkIdentifier Condition="'$(_ShortFrameworkIdentifier)' == 'netcoreapp'">.NETCoreApp</TargetFrameworkIdentifier>
<TargetFrameworkIdentifier Condition="'$(_ShortFrameworkIdentifier)' == 'net'">.NETFramework</TargetFrameworkIdentifier>
</PropertyGroup>
<!-- Versions with dots are taken as is and just given leading 'v'. -->
<PropertyGroup Condition="'$(TargetFrameworkVersion)' == '' and '$(_ShortFrameworkVersion)' != '' and $(_ShortFrameworkVersion.Contains('.'))">
<TargetFrameworkVersion>v$(_ShortFrameworkVersion)</TargetFrameworkVersion>
</PropertyGroup>
<!-- Versions with no dots and up to 3 characters get leading 'v' and implicit dots between characters. -->
<PropertyGroup Condition="'$(TargetFrameworkVersion)' == '' and '$(_ShortFrameworkVersion)' != ''">
<TargetFrameworkVersion Condition="$(_ShortFrameworkVersion.Length) == 1">v$(_ShortFrameworkVersion[0]).0</TargetFrameworkVersion>
<TargetFrameworkVersion Condition="$(_ShortFrameworkVersion.Length) == 2">v$(_ShortFrameworkVersion[0]).$(_ShortFrameworkVersion[1])</TargetFrameworkVersion>
<TargetFrameworkVersion Condition="$(_ShortFrameworkVersion.Length) == 3">v$(_ShortFrameworkVersion[0]).$(_ShortFrameworkVersion[1]).$(_ShortFrameworkVersion[2])</TargetFrameworkVersion>
</PropertyGroup>
<!--
Trigger an error if we're unable to infer the framework identifier and version.
We have to evaluate this here and not in the target because by the time the target runs,
Microsoft.Common.targets will have defaulted to .NETFramework,Version=v4.0
-->
<PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '' or '$(TargetFrameworkVersion)' == ''">
<_UnsupportedTargetFrameworkError>true</_UnsupportedTargetFrameworkError>
</PropertyGroup>
<Target Name="_CheckForUnsupportedTargetFramework" BeforeTargets="_CheckForInvalidConfigurationAndPlatform">
<NETSdkError Condition="'$(_UnsupportedTargetFrameworkError)' == 'true'"
ResourceName="CannotInferTargetFrameworkIdentiferAndVersion"
FormatArguments="$(TargetFramework)" />
</Target>
<!--
Don't leave TargetFrameworkVersion empty if it still hasn't been determined. We will trigger the error above,
but we need this to be a valid version so that our error message does not get pre-empted by failure to interpret
version comparison expressions, which is currently unrecoverable in VS.
This is also an extra safeguard to ensure we never end up with common targets default of .NetFramework,Version=v4.0
-->
<PropertyGroup Condition="'$(TargetFrameworkVersion)' == ''">
<TargetFrameworkVersion >v0.0</TargetFrameworkVersion>
</PropertyGroup>
<!--
Append $(TargetFramework) directory to output and intermediate paths to prevent bin clashes between
targets.
-->
<PropertyGroup Condition="'$(TargetFramework)' != '' and '$(_UnsupportedTargetFrameworkError)' != 'true'">
<IntermediateOutputPath>$(IntermediateOutputPath)$(TargetFramework)\</IntermediateOutputPath>
<OutputPath>$(OutputPath)$(TargetFramework)\</OutputPath>
</PropertyGroup>
</Project>