2 ***********************************************************************************************
\r
3 Microsoft.NET.RuntimeIdentifierInference.targets
\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
9 Copyright (c) .NET Foundation. All rights reserved.
\r
10 ***********************************************************************************************
\r
12 <Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
\r
15 <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
\r
19 .NETFramework cannot load native package dependencies dynamically
\r
20 based on the current architecture. We have must have a RID to
\r
21 resolve and copy native dependencies to the output directory.
\r
23 When building a .NETFramework exe on Windows and not given a RID,
\r
24 we'll pick either win7-x64 or win7-x86 (based on PlatformTarget)
\r
25 if we're not given an explicit RID. However, if after resolving
\r
26 NuGet assets we find no copy-local native dependencies, we will
\r
27 emit the binary as AnyCPU.
\r
29 Note that we must set the RID here early (to be seen during NuGet
\r
30 restore) in order for the project.assets.json to include the
\r
31 native dependencies that will let us make the final call on
\r
32 AnyCPU or platform-specific.
\r
34 This allows these common cases to work without requiring mention
\r
35 of RuntimeIdentifier in the user project PlatformTarget:
\r
37 1. Building an AnyCPU .NETFramework application on any host OS
\r
38 with no native NuGet dependencies. (*)
\r
40 2. Building an x86 or x64 NETFramework application on and for
\r
41 Windows with native NuGet dependencies that do not require
\r
44 However, any other combination of host operating system, CPU
\r
45 architecture, and minimum Windows version will require some
\r
46 manual intervention in the project file to set up the right
\r
49 (*) Building NET4x from non-Windows is still not fully supported:
\r
50 https://github.com/dotnet/sdk/issues/335) The point above is
\r
51 that this code would not have to change to make the first
\r
52 scenario work on non-Windows hosts.
\r
54 (**) https://github.com/dotnet/sdk/issues/840 tracks improving
\r
55 the default RID selection here to make more non-AnyCPU scenarios
\r
56 work without user intervention. The current static evaluation
\r
57 requirement limits us.
\r
59 <PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' and
\r
60 '$(HasRuntimeOutput)' == 'true' and
\r
61 '$(OS)' == 'Windows_NT' and
\r
62 '$(RuntimeIdentifier)' == ''">
\r
63 <_UsingDefaultRuntimeIdentifier>true</_UsingDefaultRuntimeIdentifier>
\r
64 <RuntimeIdentifier Condition="'$(PlatformTarget)' == 'x64'">win7-x64</RuntimeIdentifier>
\r
65 <RuntimeIdentifier Condition="'$(PlatformTarget)' == 'x86' or '$(PlatformTarget)' == ''">win7-x86</RuntimeIdentifier>
\r
68 <PropertyGroup Condition="'$(PlatformTarget)' == ''">
\r
69 <_UsingDefaultPlatformTarget>true</_UsingDefaultPlatformTarget>
\r
72 <!-- Determine PlatformTarget (if not already set) from runtime identifier. -->
\r
74 <When Condition="'$(PlatformTarget)' != '' or '$(RuntimeIdentifier)' == ''" />
\r
76 <When Condition="$(RuntimeIdentifier.EndsWith('-x86')) or $(RuntimeIdentifier.Contains('-x86-'))">
\r
78 <PlatformTarget>x86</PlatformTarget>
\r
82 <When Condition="$(RuntimeIdentifier.EndsWith('-x64')) or $(RuntimeIdentifier.Contains('-x64-'))">
\r
84 <PlatformTarget>x64</PlatformTarget>
\r
88 <When Condition="$(RuntimeIdentifier.EndsWith('-arm')) or $(RuntimeIdentifier.Contains('-arm-'))">
\r
90 <PlatformTarget>arm</PlatformTarget>
\r
94 <!-- NOTE: PlatformTarget=arm64 is not currently supported and therefore no inference of that here. -->
\r
97 <PlatformTarget>AnyCPU</PlatformTarget>
\r
103 SelfContained was not an option in .NET Core SDK 1.0.
\r
104 Default SelfContained based on the RuntimeIdentifier, so projects don't have to explicitly set SelfContained.
\r
105 This avoids a breaking change from 1.0 behavior.
\r
107 <PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(HasRuntimeOutput)' == 'true' and '$(SelfContained)' == ''">
\r
108 <SelfContained Condition="'$(RuntimeIdentifier)' == ''">false</SelfContained>
\r
109 <SelfContained Condition="'$(RuntimeIdentifier)' != ''">true</SelfContained>
\r
112 <Target Name="_CheckForUnsupportedSelfContained"
\r
113 BeforeTargets="_CheckForInvalidConfigurationAndPlatform"
\r
114 Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(HasRuntimeOutput)' == 'true'">
\r
116 <NETSdkError Condition="'$(SelfContained)' == 'true' and '$(RuntimeIdentifier)' == ''"
\r
117 ResourceName="CannotHaveSelfContainedWithoutRuntimeIdentifier" />
\r
122 <!-- Projects can opt out of having the RID appended to the output path by setting this to false. -->
\r
123 <AppendRuntimeIdentifierToOutputPath Condition="'$(AppendRuntimeIdentifierToOutputPath)' == ''">true</AppendRuntimeIdentifierToOutputPath>
\r
127 Append $(RuntimeIdentifier) directory to output and intermediate paths to prevent bin clashes between
\r
130 But do not append the implicit default runtime identifier for .NET Framework apps as that would
\r
131 append a RID the user never mentioned in the path and do so even in the AnyCPU case.
\r
133 <PropertyGroup Condition="'$(AppendRuntimeIdentifierToOutputPath)' == 'true' and '$(RuntimeIdentifier)' != '' and '$(_UsingDefaultRuntimeIdentifier)' != 'true'">
\r
134 <IntermediateOutputPath>$(IntermediateOutputPath)$(RuntimeIdentifier)\</IntermediateOutputPath>
\r
135 <OutputPath>$(OutputPath)$(RuntimeIdentifier)\</OutputPath>
\r
139 Switch our default .NETFramework CPU architecture choice back to AnyCPU before
\r
140 compiling the exe if no copy-local native dependencies were resolved from NuGet
\r
142 <Target Name="AdjustDefaultPlatformTargetForNetFrameworkExeWithNoNativeCopyLocalItems"
\r
143 AfterTargets="ResolvePackageDependenciesForBuild"
\r
144 BeforeTargets="CoreCompile"
\r
145 Condition="'$(_UsingDefaultPlatformTarget)' == 'true' and
\r
146 '$(_UsingDefaultRuntimeIdentifier)' == 'true' and
\r
147 '@(NativeCopyLocalItems)' == ''">
\r
149 <PlatformTarget>AnyCPU</PlatformTarget>
\r