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