2 ***********************************************************************************************
3 Microsoft.CSharp.targets
5 WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
6 created a backup copy. Incorrect changes to this file will make it
7 impossible to load or build your projects from the command-line or the IDE.
9 This file defines the steps in the standard build process specific for C# .NET projects.
10 For example, it contains the step that actually calls the C# compiler. The remainder
11 of the build process is defined in Microsoft.Common.targets, which is imported by
14 Copyright (C) Microsoft Corporation. All rights reserved.
15 ***********************************************************************************************
18 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
20 We are doing a cross-targeting build if there is no list of target frameworks specified
21 nor is there a current target framework being built individually. In that case, this import is
22 redirected to Microsoft.CSharp.CrossTargeting.targets.
24 <PropertyGroup Condition="'$(TargetFrameworks)' != '' and '$(TargetFramework)' == ''">
25 <IsCrossTargetingBuild>true</IsCrossTargetingBuild>
29 In VS 2010 SP1 and VS 2012, both supported for asset compatibility, the MSBuild installed
30 as part of them did not enforce using the local ToolsVersion (4.0) in all cases, but instead
31 just used whatever ToolsVersion was in the project file if it existed on the machine, and
32 only forced 4.0 if that ToolsVersion did not exist.
34 Moving forward, we do want to enforce a single acting ToolsVersion per version of Visual Studio,
35 but in order to approximate this behavior on VS 2010 SP1 and VS 2012 as well, we've redirected
36 the targets: If we're building using 4.X MSBuild (which doesn't define the new reserved
37 property, MSBuildAssemblyVersion), we'll point right back at the 4.0 targets, which still exist
38 as part of the .NET Framework. Only if we're using the new MSBuild will we point to the current
43 <When Condition="'$(MSBuildAssemblyVersion)' == ''">
45 <CSharpTargetsPath>$(MSBuildFrameworkToolsPath)\Microsoft.CSharp.targets</CSharpTargetsPath>
47 <!-- Same condition as in .NET 4.5 C# targets so that we can override the behavior where it defaults to
48 MSBuildToolsPath, which would be incorrect in this case -->
49 <CscToolPath Condition="'$(CscToolPath)' == '' and '$(BuildingInsideVisualStudio)' != 'true'">$(MsBuildFrameworkToolsPath)</CscToolPath>
52 <When Condition="'$(IsCrossTargetingBuild)' == 'true'">
54 <CSharpTargetsPath>$(MSBuildToolsPath)\Microsoft.CSharp.CrossTargeting.targets</CSharpTargetsPath>
59 <CSharpTargetsPath>$(MSBuildToolsPath)\Microsoft.CSharp.CurrentVersion.targets</CSharpTargetsPath>
65 <PropertyGroup Condition="'$(MSBuildAssemblyVersion)' == ''">
67 Overrides for the Microsoft.Common.targets extension targets. Used to make sure that only the imports we specify
68 (hard-coded to 4.0 locations) are used, not the 12.0 locations that would be used by default. Defined here because
69 Microsoft.CSharp.targets imports Microsoft.Common.targets from the current directory rather than using MSBuildToolsPath,
70 so defining these in Microsoft.Common.targets alone would not suffice for C# projects.
72 NOTE: This logic is duplicated in Microsoft.VisualBasic.targets (VB has the same problem) and in Microsoft.Common.targets
73 (for anyone who DOES import it directly), so for any changes to this logic in this file, please also edit the other two.
75 <ImportByWildcardBefore40MicrosoftCommonTargets Condition="'$(ImportByWildcardBefore40MicrosoftCommonTargets)' == ''">$(ImportByWildcardBeforeMicrosoftCommonTargets)</ImportByWildcardBefore40MicrosoftCommonTargets>
76 <ImportByWildcardBefore40MicrosoftCommonTargets Condition="'$(ImportByWildcardBefore40MicrosoftCommonTargets)' == ''">true</ImportByWildcardBefore40MicrosoftCommonTargets>
78 <ImportByWildcardAfter40MicrosoftCommonTargets Condition="'$(ImportByWildcardAfter40MicrosoftCommonTargets)' == ''">$(ImportByWildcardAfterMicrosoftCommonTargets)</ImportByWildcardAfter40MicrosoftCommonTargets>
79 <ImportByWildcardAfter40MicrosoftCommonTargets Condition="'$(ImportByWildcardAfter40MicrosoftCommonTargets)' == ''">true</ImportByWildcardAfter40MicrosoftCommonTargets>
81 <ImportUserLocationsByWildcardBefore40MicrosoftCommonTargets Condition="'$(ImportUserLocationsByWildcardBefore40MicrosoftCommonTargets)' == ''">$(ImportUserLocationsByWildcardBeforeMicrosoftCommonTargets)</ImportUserLocationsByWildcardBefore40MicrosoftCommonTargets>
82 <ImportUserLocationsByWildcardBefore40MicrosoftCommonTargets Condition="'$(ImportUserLocationsByWildcardBefore40MicrosoftCommonTargets)' == ''">true</ImportUserLocationsByWildcardBefore40MicrosoftCommonTargets>
84 <ImportUserLocationsByWildcardAfter40MicrosoftCommonTargets Condition="'$(ImportUserLocationsByWildcardAfter40MicrosoftCommonTargets)' == ''">$(ImportUserLocationsByWildcardAfterMicrosoftCommonTargets)</ImportUserLocationsByWildcardAfter40MicrosoftCommonTargets>
85 <ImportUserLocationsByWildcardAfter40MicrosoftCommonTargets Condition="'$(ImportUserLocationsByWildcardAfter40MicrosoftCommonTargets)' == ''">true</ImportUserLocationsByWildcardAfter40MicrosoftCommonTargets>
87 <ImportByWildcardBeforeMicrosoftCommonTargets>false</ImportByWildcardBeforeMicrosoftCommonTargets>
88 <ImportByWildcardAfterMicrosoftCommonTargets>false</ImportByWildcardAfterMicrosoftCommonTargets>
89 <ImportUserLocationsByWildcardBeforeMicrosoftCommonTargets>false</ImportUserLocationsByWildcardBeforeMicrosoftCommonTargets>
90 <ImportUserLocationsByWildcardAfterMicrosoftCommonTargets>false</ImportUserLocationsByWildcardAfterMicrosoftCommonTargets>
92 <CustomBeforeMicrosoftCommonTargets Condition="'$(CustomBeforeMicrosoftCommonTargets)' == ''">$(MSBuildExtensionsPath)\v4.0\Custom.Before.Microsoft.Common.targets</CustomBeforeMicrosoftCommonTargets>
93 <CustomAfterMicrosoftCommonTargets Condition="'$(CustomAfterMicrosoftCommonTargets)' == ''">$(MSBuildExtensionsPath)\v4.0\Custom.After.Microsoft.Common.targets</CustomAfterMicrosoftCommonTargets>
95 <!-- Overrides for the Microsoft.CSharp.targets extension targets -->
96 <ImportByWildcardBefore40MicrosoftCSharpTargets Condition="'$(ImportByWildcardBefore40MicrosoftCSharpTargets)' == ''">$(ImportByWildcardBeforeMicrosoftCSharpTargets)</ImportByWildcardBefore40MicrosoftCSharpTargets>
97 <ImportByWildcardBefore40MicrosoftCSharpTargets Condition="'$(ImportByWildcardBefore40MicrosoftCSharpTargets)' == ''">true</ImportByWildcardBefore40MicrosoftCSharpTargets>
99 <ImportByWildcardAfter40MicrosoftCSharpTargets Condition="'$(ImportByWildcardAfter40MicrosoftCSharpTargets)' == ''">$(ImportByWildcardAfterMicrosoftCSharpTargets)</ImportByWildcardAfter40MicrosoftCSharpTargets>
100 <ImportByWildcardAfter40MicrosoftCSharpTargets Condition="'$(ImportByWildcardAfter40MicrosoftCSharpTargets)' == ''">true</ImportByWildcardAfter40MicrosoftCSharpTargets>
102 <ImportUserLocationsByWildcardBefore40MicrosoftCSharpTargets Condition="'$(ImportUserLocationsByWildcardBefore40MicrosoftCSharpTargets)' == ''">$(ImportUserLocationsByWildcardBeforeMicrosoftCSharpTargets)</ImportUserLocationsByWildcardBefore40MicrosoftCSharpTargets>
103 <ImportUserLocationsByWildcardBefore40MicrosoftCSharpTargets Condition="'$(ImportUserLocationsByWildcardBefore40MicrosoftCSharpTargets)' == ''">true</ImportUserLocationsByWildcardBefore40MicrosoftCSharpTargets>
105 <ImportUserLocationsByWildcardAfter40MicrosoftCSharpTargets Condition="'$(ImportUserLocationsByWildcardAfter40MicrosoftCSharpTargets)' == ''">$(ImportUserLocationsByWildcardAfterMicrosoftCSharpTargets)</ImportUserLocationsByWildcardAfter40MicrosoftCSharpTargets>
106 <ImportUserLocationsByWildcardAfter40MicrosoftCSharpTargets Condition="'$(ImportUserLocationsByWildcardAfter40MicrosoftCSharpTargets)' == ''">true</ImportUserLocationsByWildcardAfter40MicrosoftCSharpTargets>
108 <ImportByWildcardBeforeMicrosoftCSharpTargets>false</ImportByWildcardBeforeMicrosoftCSharpTargets>
109 <ImportByWildcardAfterMicrosoftCSharpTargets>false</ImportByWildcardAfterMicrosoftCSharpTargets>
110 <ImportUserLocationsByWildcardBeforeMicrosoftCSharpTargets>false</ImportUserLocationsByWildcardBeforeMicrosoftCSharpTargets>
111 <ImportUserLocationsByWildcardAfterMicrosoftCSharpTargets>false</ImportUserLocationsByWildcardAfterMicrosoftCSharpTargets>
113 <CustomBeforeMicrosoftCSharpTargets Condition="'$(CustomBeforeMicrosoftCSharpTargets)' == ''">$(MSBuildExtensionsPath)\v4.0\Custom.Before.Microsoft.CSharp.targets</CustomBeforeMicrosoftCSharpTargets>
114 <CustomAfterMicrosoftCSharpTargets Condition="'$(CustomAfterMicrosoftCSharpTargets)' == ''">$(MSBuildExtensionsPath)\v4.0\Custom.After.Microsoft.CSharp.targets</CustomAfterMicrosoftCSharpTargets>
117 <PropertyGroup Condition="'$(MSBuildAssemblyVersion)' == '' and ('$(TargetFrameworkIdentifier)' == '.NETFramework' or '$(TargetFrameworkIdentifier)' == 'Silverlight' or ('$(TargetFrameworkIdentifier)' == '' and ('$(TargetRuntime)' == 'Managed' or '$(TargetRuntime)' == '')))">
119 Overrides for the Microsoft.NETFramework.props extension targets. Used to make sure that only the imports we specify
120 (hard-coded to 4.0 locations) are used, not the 12.0 locations that would be used by default. Required because
121 Microsoft.Common.targets imports it from the current directory, so we don't get a chance to redirect these in its
122 own redirection targets.
124 NOTE: This logic is duplicated in Microsoft.VisualBasic.targets and in Microsoft.Common.targets because VB and C#
125 import Microsoft.Common.targets from the current directory and thus don't get the benefit of these redirections either,
126 so for any changes to this logic in this file, please also edit the other two.
128 <ImportByWildcardBefore40MicrosoftNetFrameworkProps Condition="'$(ImportByWildcardBefore40MicrosoftNetFrameworkProps)' == ''">$(ImportByWildcardBeforeMicrosoftNetFrameworkProps)</ImportByWildcardBefore40MicrosoftNetFrameworkProps>
129 <ImportByWildcardBefore40MicrosoftNetFrameworkProps Condition="'$(ImportByWildcardBefore40MicrosoftNetFrameworkProps)' == ''">true</ImportByWildcardBefore40MicrosoftNetFrameworkProps>
131 <ImportByWildcardAfter40MicrosoftNetFrameworkProps Condition="'$(ImportByWildcardAfter40MicrosoftNetFrameworkProps)' == ''">$(ImportByWildcardAfterMicrosoftNetFrameworkProps)</ImportByWildcardAfter40MicrosoftNetFrameworkProps>
132 <ImportByWildcardAfter40MicrosoftNetFrameworkProps Condition="'$(ImportByWildcardAfter40MicrosoftNetFrameworkProps)' == ''">true</ImportByWildcardAfter40MicrosoftNetFrameworkProps>
134 <ImportUserLocationsByWildcardBefore40MicrosoftNetFrameworkProps Condition="'$(ImportUserLocationsByWildcardBefore40MicrosoftNetFrameworkProps)' == ''">$(ImportUserLocationsByWildcardBeforeMicrosoftNetFrameworkProps)</ImportUserLocationsByWildcardBefore40MicrosoftNetFrameworkProps>
135 <ImportUserLocationsByWildcardBefore40MicrosoftNetFrameworkProps Condition="'$(ImportUserLocationsByWildcardBefore40MicrosoftNetFrameworkProps)' == ''">true</ImportUserLocationsByWildcardBefore40MicrosoftNetFrameworkProps>
137 <ImportUserLocationsByWildcardAfter40MicrosoftNetFrameworkProps Condition="'$(ImportUserLocationsByWildcardAfter40MicrosoftNetFrameworkProps)' == ''">$(ImportUserLocationsByWildcardAfterMicrosoftNetFrameworkProps)</ImportUserLocationsByWildcardAfter40MicrosoftNetFrameworkProps>
138 <ImportUserLocationsByWildcardAfter40MicrosoftNetFrameworkProps Condition="'$(ImportUserLocationsByWildcardAfter40MicrosoftNetFrameworkProps)' == ''">true</ImportUserLocationsByWildcardAfter40MicrosoftNetFrameworkProps>
140 <ImportByWildcardBeforeMicrosoftNetFrameworkProps>false</ImportByWildcardBeforeMicrosoftNetFrameworkProps>
141 <ImportByWildcardAfterMicrosoftNetFrameworkProps>false</ImportByWildcardAfterMicrosoftNetFrameworkProps>
142 <ImportUserLocationsByWildcardBeforeMicrosoftNetFrameworkProps>false</ImportUserLocationsByWildcardBeforeMicrosoftNetFrameworkProps>
143 <ImportUserLocationsByWildcardAfterMicrosoftNetFrameworkProps>false</ImportUserLocationsByWildcardAfterMicrosoftNetFrameworkProps>
146 <ImportGroup Condition="'$(MSBuildAssemblyVersion)' == ''">
147 <Import Project="$(MSBuildUserExtensionsPath)\4.0\Microsoft.CSharp.targets\ImportBefore\*" Condition="'$(ImportUserLocationsByWildcardBefore40MicrosoftCSharpTargets)' == 'true' and exists('$(MSBuildUserExtensionsPath)\4.0\Microsoft.CSharp.targets\ImportBefore')"/>
148 <Import Project="$(MSBuildExtensionsPath)\4.0\Microsoft.CSharp.targets\ImportBefore\*" Condition="'$(ImportByWildcardBefore40MicrosoftCSharpTargets)' == 'true' and exists('$(MSBuildExtensionsPath)\4.0\Microsoft.CSharp.targets\ImportBefore')"/>
151 <!-- Really should be imported right before Microsoft.Common.targets, but because Microsoft.CSharp.targets imports
152 Microsoft.Common.targets from the current directory rather than using MSBuildToolsPath (which would redirect to our
153 targets), we're stuck doing it this way instead. -->
154 <ImportGroup Condition="'$(MSBuildAssemblyVersion)' == ''">
155 <Import Project="$(MSBuildUserExtensionsPath)\4.0\Microsoft.Common.targets\ImportBefore\*" Condition="'$(ImportUserLocationsByWildcardBefore40MicrosoftCommonTargets)' == 'true' and exists('$(MSBuildUserExtensionsPath)\4.0\Microsoft.Common.targets\ImportBefore')"/>
156 <Import Project="$(MSBuildExtensionsPath)\4.0\Microsoft.Common.targets\ImportBefore\*" Condition="'$(ImportByWildcardBefore40MicrosoftCommonTargets)' == 'true' and exists('$(MSBuildExtensionsPath)\4.0\Microsoft.Common.targets\ImportBefore')"/>
159 <!-- Really should be imported right before Microsoft.NETFramework.props, but because Microsoft.CSharp.targets imports
160 Microsoft.Common.targets from the current directory rather than using MSBuildToolsPath (which would redirect to our
161 targets), and Microsoft.Common.targets does likewise with Microsoft.NETFramework.props, we're stuck doing it this
163 <ImportGroup Condition="'$(MSBuildAssemblyVersion)' == ''">
164 <Import Project="$(MSBuildUserExtensionsPath)\4.0\Microsoft.NETFramework.props\ImportBefore\*" Condition="'$(ImportUserLocationsByWildcardBefore40MicrosoftNetFrameworkProps)' == 'true' and exists('$(MSBuildUserExtensionsPath)\4.0\Microsoft.NETFramework.props\ImportBefore')"/>
165 <Import Project="$(MSBuildExtensionsPath)\4.0\Microsoft.NETFramework.props\ImportBefore\*" Condition="'$(ImportByWildcardBefore40MicrosoftNetFrameworkProps)' == 'true' and exists('$(MSBuildExtensionsPath)\4.0\Microsoft.NETFramework.props\ImportBefore')"/>
168 <Import Project="$(CSharpTargetsPath)" />
170 <!-- Really should be imported right after Microsoft.NETFramework.props, but because Microsoft.CSharp.targets imports
171 Microsoft.Common.targets from the current directory rather than using MSBuildToolsPath (which would redirect to our
172 targets), and Microsoft.Common.targets does likewise with Microsoft.NETFramework.props, we're stuck doing it this
174 <ImportGroup Condition="'$(MSBuildAssemblyVersion)' == ''">
175 <Import Project="$(MSBuildExtensionsPath)\4.0\Microsoft.NETFramework.props\ImportAfter\*" Condition="'$(ImportByWildcardAfter40MicrosoftNetFrameworkProps)' == 'true' and exists('$(MSBuildExtensionsPath)\4.0\Microsoft.NETFramework.props\ImportAfter')"/>
176 <Import Project="$(MSBuildUserExtensionsPath)\4.0\Microsoft.NETFramework.props\ImportAfter\*" Condition="'$(ImportUserLocationsByWildcardAfter40MicrosoftNetFrameworkProps)' == 'true' and exists('$(MSBuildUserExtensionsPath)\4.0\Microsoft.NETFramework.props\ImportAfter')"/>
179 <!-- Really should be imported right after Microsoft.Common.targets, but because Microsoft.CSharp.targets imports
180 Microsoft.Common.targets from the current directory rather than using MSBuildToolsPath (which would redirect to our
181 targets), we're stuck doing it this way instead. -->
182 <ImportGroup Condition="'$(MSBuildAssemblyVersion)' == ''">
183 <Import Project="$(MSBuildExtensionsPath)\4.0\Microsoft.Common.targets\ImportAfter\*" Condition="'$(ImportByWildcardAfter40MicrosoftCommonTargets)' == 'true' and exists('$(MSBuildExtensionsPath)\4.0\Microsoft.Common.targets\ImportAfter')"/>
184 <Import Project="$(MSBuildUserExtensionsPath)\4.0\Microsoft.Common.targets\ImportAfter\*" Condition="'$(ImportUserLocationsByWildcardAfter40MicrosoftCommonTargets)' == 'true' and exists('$(MSBuildUserExtensionsPath)\4.0\Microsoft.Common.targets\ImportAfter')"/>
187 <ImportGroup Condition="'$(MSBuildAssemblyVersion)' == ''">
188 <Import Project="$(MSBuildExtensionsPath)\4.0\Microsoft.CSharp.targets\ImportAfter\*" Condition="'$(ImportByWildcardAfter40MicrosoftCSharpTargets)' == 'true' and exists('$(MSBuildExtensionsPath)\4.0\Microsoft.CSharp.targets\ImportAfter')"/>
189 <Import Project="$(MSBuildUserExtensionsPath)\4.0\Microsoft.CSharp.targets\ImportAfter\*" Condition="'$(ImportUserLocationsByWildcardAfter40MicrosoftCSharpTargets)' == 'true' and exists('$(MSBuildUserExtensionsPath)\4.0\Microsoft.CSharp.targets\ImportAfter')"/>
192 <!-- Fix up FrameworkPathOverride, which is primarily used to determine the location of mscorlib.dll in the
193 (relatively uncommon) situation where the reference assemblies, in which it's usually found, are not
194 installed. Defined here rather than in Microsoft.Common.targets because the .NET Microsoft.CSharp.targets
195 imports Microsoft.Common.targets from the current directory. -->
196 <PropertyGroup Condition="'$(MSBuildAssemblyVersion)' == ''">
197 <FrameworkPathOverride Condition="!Exists('$(FrameworkPathOverride)\mscorlib.dll')">$(MSBuildFrameworkToolsPath)</FrameworkPathOverride>