Merge remote-tracking branch 'joncham/sgen-msvc2'
[mono.git] / mcs / tools / xbuild / xbuild / 4.0 / Microsoft.Common.targets
1 <Project DefaultTargets="Build" InitialTargets="_ValidateEssentialProperties" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2         <PropertyGroup>
3                 <ImportByWildcardBeforeMicrosoftCommonTargets Condition="'$(ImportByWildcardBeforeMicrosoftCommonTargets)' == ''">true</ImportByWildcardBeforeMicrosoftCommonTargets>
4                 <ImportByWildcardAfterMicrosoftCommonTargets Condition="'$(ImportByWildcardAfterMicrosoftCommonTargets)' == ''">true</ImportByWildcardAfterMicrosoftCommonTargets>
5         </PropertyGroup>
6
7         <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\$(MSBuildThisFile)\ImportBefore\*"
8                 Condition="'$(ImportByWildcardBeforeMicrosoftCommonTargets)' == 'true' and Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\$(MSBuildThisFile)\ImportBefore')"/>
9
10         <PropertyGroup>
11                 <TargetExt Condition="'$(OutputType)' == 'Winexe'">.exe</TargetExt>
12                 <TargetExt Condition="'$(OutputType)' == 'Exe'">.exe</TargetExt>
13                 <TargetExt Condition="'$(OutputType)' == 'Library'">.dll</TargetExt>
14                 <TargetExt Condition="'$(OutputType)' == 'Netmodule'">.netmodule</TargetExt>
15         </PropertyGroup>
16
17         <PropertyGroup>
18                 <ProjectDir Condition="'$(ProjectDir)' == ''">$(MSBuildProjectDirectory)\</ProjectDir>
19         </PropertyGroup>
20
21         <PropertyGroup>
22                 <AssemblyName Condition="'$(AssemblyName)' == ''">$(RootNamespace)</AssemblyName>
23                 <OutputPath Condition="'$(OutputPath)' != '' and !HasTrailingSlash('$(OutputPath)')">$(OutputPath)\</OutputPath> 
24                 <OutputPath Condition=" '$(Platform)'=='' and '$(Configuration)'=='' and '$(OutputPath)'=='' ">bin\Debug\</OutputPath>
25                 <WarningLevel Condition="'$(WarningLevel)' == ''" >2</WarningLevel>
26
27                 <TargetFrameworkIdentifier Condition="'$(TargetFrameworkIdentifier)' == ''">.NETFramework</TargetFrameworkIdentifier>
28                 <TargetFrameworkVersion Condition="'$(TargetFrameworkVersion)' == ''">v4.0</TargetFrameworkVersion>
29
30                 <TargetFrameworkMoniker Condition="'$(TargetFrameworkMoniker)' == '' and '$(TargetFrameworkProfile)' != ''">$(TargetFrameworkIdentifier),Version=$(TargetFrameworkVersion),Profile=$(TargetFrameworkProfile)</TargetFrameworkMoniker>
31                 <TargetFrameworkMoniker Condition="'$(TargetFrameworkMoniker)' == ''">$(TargetFrameworkIdentifier),Version=$(TargetFrameworkVersion)</TargetFrameworkMoniker>
32         </PropertyGroup>
33
34         <PropertyGroup>
35                 <OutDir Condition="'$(OutDir)' == ''">$(OutputPath)</OutDir>
36                 <OutDir Condition="'$(OutDir)' != '' and !HasTrailingSlash('$(OutDir)')">$(OutDir)\</OutDir>
37
38                 <_OriginalConfiguration>$(Configuration)</_OriginalConfiguration>
39                 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
40                 <ConfigurationName Condition="'$(ConfigurationName)' == ''">$(Configuration)</ConfigurationName>
41
42                 <_OriginalPlatform>$(Platform)</_OriginalPlatform>
43                 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
44                 <PlatformName Condition="'$(PlatformName)' == ''">$(Platform)</PlatformName>
45
46                 <AddAdditionalExplicitAssemblyReferences Condition="'$(AddAdditionalExplicitAssemblyReferences)' == ''">true</AddAdditionalExplicitAssemblyReferences>
47                 <AdditionalExplicitAssemblyReferences Condition="'$(AddAdditionalExplicitAssemblyReferences)' == 'true' and '$(TargetFrameworkVersion)' != 'v2.0' and '$(TargetFrameworkVersion)' != 'v3.0'">System.Core;$(AdditionalExplicitAssemblyReferences)</AdditionalExplicitAssemblyReferences>
48         </PropertyGroup>
49
50         <PropertyGroup>
51                 <SkipCopyUnchangedFiles Condition="'$(SkipCopyUnchangedFiles)' == ''">true</SkipCopyUnchangedFiles>
52         </PropertyGroup>
53
54         <PropertyGroup>
55                 <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)' == ''">obj\</BaseIntermediateOutputPath>
56                 <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)' != '' and !HasTrailingSlash('$(BaseIntermediateOutputPath)')">$(BaseIntermediateOutputPath)\</BaseIntermediateOutputPath>
57                 <CleanFile Condition="'$(CleanFile)'==''">$(MSBuildProjectFile).FilesWrittenAbsolute.txt</CleanFile>
58         </PropertyGroup>
59
60         <PropertyGroup Condition="'$(IntermediateOutputPath)' == ''">
61                 <IntermediateOutputPath Condition=" '$(PlatformName)' == 'AnyCPU'">$(BaseIntermediateOutputPath)$(Configuration)\</IntermediateOutputPath>
62                 <IntermediateOutputPath Condition=" '$(PlatformName)' != 'AnyCPU'">$(BaseIntermediateOutputPath)$(PlatformName)\$(Configuration)\</IntermediateOutputPath>
63         </PropertyGroup>
64
65         <PropertyGroup>
66                 <IntermediateOutputPath Condition="'$(IntermediateOutputPath)' != '' and !HasTrailingSlash('$(IntermediateOutputPath)')">$(IntermediateOutputPath)\</IntermediateOutputPath>
67         </PropertyGroup>
68
69         <ItemGroup>
70                 <IntermediateAssembly Include="$(IntermediateOutputPath)$(AssemblyName)$(TargetExt)" />
71
72                 <!-- creating this as a item to use FullPath on it, to build TargetPath -->
73                 <_OutDirItem Include="$(OutDir)"/>
74         </ItemGroup>
75
76         <PropertyGroup>
77                 <TargetName Condition="'$(TargetName)' == '' ">$(AssemblyName)</TargetName>
78                 <TargetFileName Condition="'$(TargetFileName)' == '' ">$(TargetName)$(TargetExt)</TargetFileName>
79                 <TargetDir Condition=" '$(TargetDir)' == '' ">@(_OutDirItem->'%(FullPath)')</TargetDir>
80                 <TargetPath Condition=" '$(TargetPath)' == '' ">@(_OutDirItem->'%(FullPath)\$(TargetFileName)')</TargetPath>
81                 <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildProjectFullPath);$(MSBuildToolsPath)\Microsoft.Common.targets</MSBuildAllProjects>
82                 <KeyOriginatorFile Condition=" '$(SignAssembly)' == 'true' ">$(AssemblyOriginatorKeyFile)</KeyOriginatorFile>
83         </PropertyGroup>
84
85         <Target Name="_ValidateEssentialProperties">
86                 <Error Condition=" '$(OutputPath)' == '' and '$(SkipInvalidConfigurations)' != 'true'"
87                         Text="'OutputPath' property is not set for this project. Usually this is caused by invalid Configuration/Platform combination. Original values: Configuration: $(_OriginalConfiguration) Platform: $(_OriginalPlatform)."/>
88
89                 <Warning Condition=" '$(OutputPath)' == '' and '$(SkipInvalidConfigurations)' == 'true'"
90                         Text="'OutputPath' property is not set for this project. Usually this is caused by invalid Configuration/Platform combination. Original values: Configuration: $(_OriginalConfiguration) Platform: $(_OriginalPlatform)."/>
91
92                 <!-- If OutDir is specified via the command line, then the earlier check
93                      to add a trailing slash won't have any affect, so error here. -->
94                 <Error
95                         Condition="'$(OutDir)' != '' and !HasTrailingSlash('$(OutDir)')"
96                         Text="OutDir property must end with a slash."/>
97         </Target>
98
99         <Target Name="PrepareForBuild">
100                 <Message Importance="High" Text="Configuration: $(Configuration) Platform: $(Platform)"/>
101
102                 <!-- Look for app.config, if $(AppConfig) is specified, then use that. Else look in
103                      @(None) and @(Content) -->
104                 <CreateItem Include="$(AppConfig)" Condition="'$(AppConfig)' != ''"
105                         AdditionalMetadata="TargetPath=$(TargetFileName).config">
106                         <Output TaskParameter="Include" ItemName="AppConfigWithTargetPath" />
107                 </CreateItem>
108
109                 <FindAppConfigFile PrimaryList="@(None)" SecondaryList="@(Content)" TargetPath="$(TargetFileName).config"
110                         Condition="'$(AppConfig)' == ''">
111                         <Output TaskParameter="AppConfigFile" ItemName="AppConfigWithTargetPath"/>
112                 </FindAppConfigFile>
113
114                 <MakeDir 
115                         Directories="$(OutDir);$(IntermediateOutputPath);@(DocFileItem->'%(RelativeDir)')"
116                 />
117         </Target>
118
119         <PropertyGroup>
120                 <GetFrameworkPathsDependsOn />
121         </PropertyGroup>
122         <Target Name="GetFrameworkPaths"
123                 Condition="'$(TargetFrameworkIdentifier)' == '' or '$(TargetFrameworkIdentifier)' == '.NETFramework'"
124                 DependsOnTargets="$(GetFrameworkPathsDependsOn)">
125                 <GetFrameworkPath>
126                         <Output Condition="'$(TargetFrameworkVersion)' == 'v4.0'"
127                                 TaskParameter="FrameworkVersion40Path"
128                                 ItemName="_CombinedTargetFrameworkDirectoriesItem"/>
129                         <Output Condition="'$(TargetFrameworkVersion)' == 'v3.5'"
130                                 TaskParameter="FrameworkVersion35Path"
131                                 ItemName="_CombinedTargetFrameworkDirectoriesItem"/>
132                         <Output Condition="'$(TargetFrameworkVersion)' == 'v3.0' or '$(TargetFrameworkVersion)' == 'v3.5'" 
133                                 TaskParameter="FrameworkVersion30Path"
134                                 ItemName="_CombinedTargetFrameworkDirectoriesItem"/>
135                         <Output Condition="'$(TargetFrameworkVersion)' == 'v2.0' or '$(TargetFrameworkVersion)' == 'v3.0' or '$(TargetFrameworkVersion)' == 'v3.5'" 
136                                 TaskParameter="FrameworkVersion20Path"
137                                 ItemName="_CombinedTargetFrameworkDirectoriesItem"/>
138                 </GetFrameworkPath>
139                 <CreateProperty Value="@(_CombinedTargetFrameworkDirectoriesItem)">
140                         <Output TaskParameter="Value" PropertyName="TargetFrameworkDirectory"/>
141                 </CreateProperty>
142
143                 <Warning Text="TargetFrameworkVersion '$(TargetFrameworkVersion)' not supported by this toolset (ToolsVersion: $(MSBuildToolsVersion))."
144                         Condition="'$(TargetFrameworkVersion)' != 'v4.0' and '$(TargetFrameworkVersion)' != 'v3.5' and '$(TargetFrameworkVersion)' != 'v3.0' and '$(TargetFrameworkVersion)' != 'v2.0'"/>
145         </Target>
146
147         <PropertyGroup>
148                 <GetReferenceAssemblyPathsDependsOn />
149         </PropertyGroup>
150         <Target Name="GetReferenceAssemblyPaths" DependsOnTargets="$(GetReferenceAssemblyPathsDependsOn)">
151                 <!-- in case of .NETFramework, $(TargetFrameworkDirectory) would have been set by
152                 GetFrameworkPaths, if it hasn't been changed, then clear it, to avoid duplicates -->
153                 <CreateProperty Value="" Condition="'@(_CombinedTargetFrameworkDirectoriesItem)' == '$(TargetFrameworkDirectory)'">
154                         <Output TaskParameter="Value" PropertyName="TargetFrameworkDirectory"/>
155                 </CreateProperty>
156
157                 <GetReferenceAssemblyPaths
158                         Condition="'$(TargetFrameworkMoniker)' != '' and '$(_TargetFrameworkDirectories)' == ''"
159                         TargetFrameworkMoniker="$(TargetFrameworkMoniker)"
160                         RootPath="$(TargetFrameworkRootPath)">
161
162                         <Output TaskParameter="ReferenceAssemblyPaths" PropertyName="_TargetFrameworkDirectories"/>
163                         <Output TaskParameter="FullFrameworkReferenceAssemblyPaths" PropertyName="_FullFrameworkReferenceAssemblyPaths"/>
164                         <Output TaskParameter="TargetFrameworkMonikerDisplayName" PropertyName="TargetFrameworkMonikerDisplayName"/>
165                 </GetReferenceAssemblyPaths>
166
167                 <CreateProperty Value="$(_TargetFrameworkDirectories);$(TargetFrameworkDirectory)">
168                         <Output TaskParameter="Value" PropertyName="TargetFrameworkDirectory"/>
169                 </CreateProperty>
170         </Target>
171
172         <PropertyGroup>
173                 <AllowedReferenceAssemblyFileExtensions Condition=" '$(AllowedReferenceAssemblyFileExtensions)' == '' ">
174                         .exe;
175                         .dll
176                 </AllowedReferenceAssemblyFileExtensions>
177
178                 <AllowedReferenceRelatedFileExtensions Condition=" '$(AllowedReferenceRelatedFileExtensions)' == '' ">
179                         .mdb
180                 </AllowedReferenceRelatedFileExtensions>
181
182                 <AssemblySearchPaths Condition="'$(AssemblySearchPaths)' == ''">
183                         {CandidateAssemblyFiles};
184                         $(ReferencePath);
185                         {HintPathFromItem};
186                         {TargetFrameworkDirectory};
187                         {PkgConfig};
188                         {GAC};
189                         {RawFileName};
190                         $(OutDir)
191                 </AssemblySearchPaths>
192
193                 <ResolveReferencesDependsOn>
194                         BeforeResolveReferences;
195                         ResolveProjectReferences;
196                         ResolveAssemblyReferences;
197                         AfterResolveReferences
198                 </ResolveReferencesDependsOn>
199
200                 <ResolveAssemblyReferencesDependsOn>
201                         GetFrameworkPaths;
202                         GetReferenceAssemblyPaths;
203                         PrepareForBuild
204                 </ResolveAssemblyReferencesDependsOn>
205         </PropertyGroup>
206
207         <Target Name="ResolveReferences" DependsOnTargets="$(ResolveReferencesDependsOn)"/>
208
209         <Target Name="BeforeResolveReferences" />
210         <Target Name="AfterResolveReferences" />
211
212         <Target Name="ResolveAssemblyReferences" DependsOnTargets="$(ResolveAssemblyReferencesDependsOn)">
213                 <CreateItem Include="@(Reference)" Exclude="$(AdditionalExplicitAssemblyReferences)">
214                         <Output TaskParameter="Include" ItemName="_Reference"/>
215                 </CreateItem>
216
217                 <CreateItem Include="$(AdditionalExplicitAssemblyReferences)">
218                         <Output TaskParameter="Include" ItemName="_Reference"/>
219                 </CreateItem>
220
221                 <ResolveAssemblyReference
222                         Assemblies="@(_Reference)"
223                         AssemblyFiles="@(ChildProjectReferences)"
224                         SearchPaths="$(AssemblySearchPaths)"
225                         CandidateAssemblyFiles="@(Content);@(None)"
226                         TargetFrameworkDirectories="$(TargetFrameworkDirectory)"
227                         AllowedAssemblyExtensions="$(AllowedReferenceAssemblyFileExtensions)"
228                         AllowedRelatedFileExtensions="$(AllowedReferenceRelatedFileExtensions)"
229                         FindDependencies="true"
230                         FindSatellites="true"
231                         FindRelatedFiles="true"
232                         TargetFrameworkMoniker="$(TargetFrameworkMoniker)"
233                         TargetFrameworkMonikerDisplayName="$(TargetFrameworkMonikerDisplayName)"
234                         TargetFrameworkVersion="$(TargetFrameworkVersion)"
235                 >
236                         <Output TaskParameter="ResolvedFiles" ItemName="ResolvedFiles"/>
237                         <Output TaskParameter="ResolvedFiles" ItemName="ReferencePath"/>
238                         <Output TaskParameter="ResolvedDependencyFiles" ItemName="_ResolvedDependencyFiles"/>
239                         <Output TaskParameter="RelatedFiles" ItemName="_ReferenceRelatedPaths"/>
240                         <Output TaskParameter="SatelliteFiles" ItemName="ReferenceSatellitePaths"/>
241                         <Output TaskParameter="CopyLocalFiles" ItemName="ReferenceCopyLocalPaths"/>
242                 </ResolveAssemblyReference>
243         </Target>
244
245         <Target
246                 Name="AssignProjectConfigurations"
247                 Condition="'@(ProjectReference)' != ''">
248
249                 <!-- assign configs if building a solution file -->
250                 <AssignProjectConfiguration
251                         ProjectReferences = "@(ProjectReference)"
252                         SolutionConfigurationContents = "$(CurrentSolutionConfigurationContents)"
253                         Condition="'$(BuildingSolutionFile)' == 'true'">
254
255                         <Output TaskParameter = "AssignedProjects" ItemName = "ProjectReferenceWithConfiguration"/>
256                 </AssignProjectConfiguration>
257
258                 <!-- Else, just -->
259                 <CreateItem Include="@(ProjectReference)" Condition="'$(BuildingSolutionFile)' != 'true'">
260                         <Output TaskParameter="Include" ItemName="ProjectReferenceWithConfiguration"/>
261                 </CreateItem>
262
263         </Target>
264
265         <!-- Split projects into 2 lists
266                 ProjectReferenceWithConfigurationExistent: Projects existent on disk
267                 ProjectReferenceWithConfigurationNonExistent: Projects non-existent on disk -->
268
269         <Target Name="SplitProjectReferencesByExistent"
270                 DependsOnTargets="AssignProjectConfigurations">
271
272                 <CreateItem Include="@(ProjectReferenceWithConfiguration)" Condition="'@(ProjectReferenceWithConfiguration)' != ''">
273                         <Output TaskParameter="Include" ItemName="ProjectReferenceWithConfigurationExistent"
274                                 Condition="Exists ('%(ProjectReferenceWithConfiguration.Identity)')"/>
275
276                         <Output TaskParameter="Include" ItemName="ProjectReferenceWithConfigurationNonExistent"
277                                 Condition="!Exists ('%(ProjectReferenceWithConfiguration.Identity)')"/>
278                 </CreateItem>
279         </Target>
280
281         <Target
282                 Name="ResolveProjectReferences"
283                 DependsOnTargets="SplitProjectReferencesByExistent"
284         >
285                 <!-- If building from a .sln.proj or from IDE, then referenced projects have already
286                      been built, so just get the target paths -->
287                 <MSBuild
288                         Projects="@(ProjectReferenceWithConfigurationExistent)"
289                         Targets="GetTargetPath"
290                         Properties="%(ProjectReferenceWithConfigurationExistent.SetConfiguration); %(ProjectReferenceWithConfigurationExistent.SetPlatform)"
291                         Condition="'@(ProjectReferenceWithConfigurationExistent)' != '' and ('$(BuildingSolutionFile)' == 'true' or '$(BuildingInsideVisualStudio)' == 'true')">
292
293                         <Output TaskParameter="TargetOutputs" ItemName="ChildProjectReferences" />
294                 </MSBuild>
295
296                 <!-- Building a project directly, build the referenced the projects also -->
297                 <MSBuild
298                         Projects="@(ProjectReferenceWithConfigurationExistent)"
299                         Properties="%(ProjectReferenceWithConfigurationExistent.SetConfiguration); %(ProjectReferenceWithConfigurationExistent.SetPlatform)"
300                         Condition="'@(ProjectReferenceWithConfigurationExistent)' != '' and '$(BuildingSolutionFile)' != 'true' and '$(BuildingInsideVisualStudio)' != 'true' ">
301
302                         <Output TaskParameter="TargetOutputs" ItemName="ChildProjectReferences" />
303                 </MSBuild>
304
305                 <Warning Text="Referenced Project %(ProjectReferenceWithConfigurationNonExistent.Identity) not found, ignoring."
306                          Condition="'@(ProjectReferenceWithConfigurationNonExistent)' != ''"/>
307         </Target>
308
309         <Target Name = "CopyFilesMarkedCopyLocal">
310                 <Copy
311                         SourceFiles="@(ReferenceCopyLocalPaths)"
312                         DestinationFiles="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')"
313                         SkipUnchangedFiles="$(SkipCopyUnchangedFiles)">
314                         <Output TaskParameter = "DestinationFiles" ItemName = "FileWritesShareable"/>
315                 </Copy>
316         </Target>
317
318         <Target Name="_ComputeNonExistentFileProperty" Condition='false'>
319                 <CreateProperty Value="__NonExistentSubDir__\__NonExistentFile__">
320                         <Output TaskParameter="Value" PropertyName="NonExistentFile"/>
321                 </CreateProperty>
322         </Target>
323
324         <PropertyGroup>
325                 <BuildDependsOn>
326                         BeforeBuild;
327                         CoreBuild;
328                         AfterBuild
329                 </BuildDependsOn>
330         </PropertyGroup>
331
332         <Target Name="BeforeBuild"/>
333         <Target Name="AfterBuild"/>
334
335         <Target Name="Build" DependsOnTargets="$(BuildDependsOn)" Outputs="$(TargetPath)"/>
336
337         <PropertyGroup>
338                 <CoreBuildDependsOn>
339                         PrepareForBuild;
340                         GetFrameworkPaths;
341                         GetReferenceAssemblyPaths;
342                         PreBuildEvent;
343                         ResolveReferences;
344                         CopyFilesMarkedCopyLocal;
345                         PrepareResources;
346                         Compile;
347                         PrepareForRun;
348                         DeployOutputFiles;
349                         _RecordCleanFile;
350                         PostBuildEvent
351                 </CoreBuildDependsOn>
352         </PropertyGroup>
353
354         <Target
355                 Name="CoreBuild"
356                 DependsOnTargets="$(CoreBuildDependsOn)"
357                 Outputs="$(OutDir)$(AssemblyName)$(TargetExt)">
358
359                 <OnError ExecuteTargets="_TimestampAfterCompile;PostBuildEvent"
360                         Condition=" '$(RunPostBuildEvent)' == 'Always' or '$(RunPostBuildEvent)' == 'OnOutputUpdated'"/>
361
362                 <OnError ExecuteTargets="_RecordCleanFile" />
363         </Target>
364
365         <PropertyGroup>
366                 <CompileDependsOn>
367                         ResolveReferences;
368                         BeforeCompile;
369                         _TimestampBeforeCompile;
370                         CoreCompile;
371                         _TimestampAfterCompile;
372                         AfterCompile
373                 </CompileDependsOn>
374         </PropertyGroup>
375
376         <Target Name="BeforeCompile" />
377         <Target Name="AfterCompile" />
378
379         <Target Name="Compile" DependsOnTargets="$(CompileDependsOn)"/>
380
381         <PropertyGroup>
382                 <PrepareForRunDependsOn>
383                         DeployOutputFiles
384                 </PrepareForRunDependsOn>
385         </PropertyGroup>
386         <Target Name="PrepareForRun" DependsOnTargets="$(PrepareForRunDependsOn)"/>
387
388         <PropertyGroup>
389                 <PrepareResourcesDependsOn>
390                         AssignTargetPaths;
391                         SplitResourcesByCulture;
392                         CreateManifestResourceNames;
393                         CopyNonResxEmbeddedResources;
394                         GenerateResources;
395                         GenerateSatelliteAssemblies;
396                         CompileLicxFiles
397                 </PrepareResourcesDependsOn>
398         </PropertyGroup>
399         <Target Name="PrepareResources" DependsOnTargets="$(PrepareResourcesDependsOn)" />
400
401         <Target Name="SplitResourcesByCulture" DependsOnTargets="AssignTargetPaths">
402                 <!-- Extract .licx files into @(LicxFiles) -->
403                 <CreateItem Include="@(EmbeddedResourceWithTargetPath)" Condition="'%(Extension)' == '.licx'">
404                         <Output TaskParameter="Include" ItemName="LicxFiles"/>
405                 </CreateItem>
406
407                 <!-- Split *remaining* resource files into various groups.. -->
408                 <AssignCulture Files="@(EmbeddedResourceWithTargetPath)" Condition="'%(Extension)' != '.licx'">
409                         <Output TaskParameter="AssignedFilesWithNoCulture" ItemName="ResourcesWithNoCulture"/>
410                         <Output TaskParameter="AssignedFilesWithCulture" ItemName="ResourcesWithCulture"/>
411                 </AssignCulture>
412
413                 <CreateItem Include="@(ResourcesWithNoCulture)" Condition="'%(Extension)' == '.resx'">
414                         <Output TaskParameter="Include" ItemName="ResxWithNoCulture"/>
415                 </CreateItem>
416
417                 <CreateItem Include="@(ResourcesWithNoCulture)" Condition="'%(Extension)' != '.resx'">
418                         <Output TaskParameter="Include" ItemName="NonResxWithNoCulture"/>
419                 </CreateItem>
420
421                 <CreateItem Include="@(ResourcesWithCulture)" Condition="'%(Extension)' == '.resx'">
422                         <Output TaskParameter="Include" ItemName="ResxWithCulture"/>
423                 </CreateItem>
424
425                 <CreateItem Include="@(ResourcesWithCulture)" Condition="'%(Extension)' != '.resx'">
426                         <Output TaskParameter="Include" ItemName="NonResxWithCulture"/>
427                 </CreateItem>
428         </Target>
429
430         <!-- Copy non-resx resources to their manifest resource names, this is what the compiler expects -->
431         <Target Name = "CopyNonResxEmbeddedResources"
432                 Condition = "'@(NonResxWithCulture)' != '' or '@(NonResxWithNoCulture)' != '' or '@(ManifestNonResxWithCulture)' != '' or '@(ManifestNonResxWithNoCulture)' != ''">
433
434                 <MakeDir Directories="$(IntermediateOutputPath)%(ManifestNonResxWithCulture.Culture)"/>
435                 <Copy SourceFiles = "@(NonResxWithCulture)"
436                         DestinationFiles = "@(ManifestNonResxWithCulture->'$(IntermediateOutputPath)%(Identity)')"
437                         SkipUnchangedFiles="$(SkipCopyUnchangedFiles)">
438                         <Output TaskParameter = "DestinationFiles" ItemName = "ManifestNonResxWithCultureOnDisk"/>
439                         <Output TaskParameter = "DestinationFiles" ItemName = "FileWrites"/>
440                 </Copy>
441
442                 <Copy SourceFiles = "@(NonResxWithNoCulture)"
443                         DestinationFiles = "@(ManifestNonResxWithNoCulture->'$(IntermediateOutputPath)%(Identity)')"
444                         SkipUnchangedFiles="$(SkipCopyUnchangedFiles)">
445                         <Output TaskParameter = "DestinationFiles" ItemName = "ManifestNonResxWithNoCultureOnDisk"/>
446                         <Output TaskParameter = "DestinationFiles" ItemName = "FileWrites"/>
447                 </Copy>
448         </Target>
449
450         <Target Name = "GenerateResources">
451                 <GenerateResource
452                         Sources = "@(ResxWithNoCulture)"
453                         UseSourcePath = "true"
454                         OutputResources = "@(ManifestResourceWithNoCultureName->'$(IntermediateOutputPath)%(Identity).resources')"
455                         Condition = "'@(ResxWithNoCulture)' != '' ">
456
457                         <Output TaskParameter = "OutputResources" ItemName = "ManifestResourceWithNoCulture"/>
458                         <Output TaskParameter = "FilesWritten" ItemName = "FileWrites"/>
459                 </GenerateResource>
460
461                 <GenerateResource
462                         Sources = "@(ResxWithCulture)"
463                         UseSourcePath = "true"
464                         OutputResources = "@(ManifestResourceWithCultureName->'$(IntermediateOutputPath)%(Identity).resources')"
465                         Condition = "'@(ResxWithCulture)' != '' ">
466
467                         <Output TaskParameter = "OutputResources" ItemName = "ManifestResourceWithCulture"/>
468                         <Output TaskParameter = "FilesWritten" ItemName = "FileWrites"/>
469                 </GenerateResource>
470         </Target>
471
472         <Target Name="GenerateSatelliteAssemblies"
473                 Inputs="@(ManifestResourceWithCulture);@(ManifestNonResxWithCultureOnDisk)"
474                 Outputs="$(IntermediateOutputPath)%(Culture)\$(AssemblyName).resources.dll" >
475                 <!-- @(NonResxWithCulture) - rename files to ManifestNon.. and then use for AL -->
476                 <MakeDir Directories = "$(IntermediateOutputPath)%(ManifestResourceWithCulture.Culture)" Condition = "'@(ManifestResourceWithCulture)' != ''" />
477                 <MakeDir Directories = "$(IntermediateOutputPath)%(ManifestNonResxWithCultureOnDisk.Culture)" Condition = "'@(ManifestNonResxWithCultureOnDisk)' != ''" />
478
479                 <AL
480                         Culture = "%(Culture)"
481                         DelaySign="$(DelaySign)"
482                         EmbedResources = "@(ManifestResourceWithCulture);@(ManifestNonResxWithCultureOnDisk)"
483                         KeyFile="$(KeyOriginatorFile)"
484                         ToolExe="$(AlToolExe)"
485                         ToolPath="$(AlToolPath)"
486                         OutputAssembly = "$(IntermediateOutputPath)%(Culture)\$(AssemblyName).resources.dll" >
487                         <Output TaskParameter="OutputAssembly" ItemName="FileWrites"/>
488                 </AL>
489
490
491                 <CreateItem
492                         Include = "$(IntermediateOutputPath)%(Culture)\$(AssemblyName).resources.dll"
493                         AdditionalMetadata = "Culture=%(Culture)"
494                         Condition = "'@(ManifestResourceWithCulture)' != '' or '@(ManifestNonResxWithCultureOnDisk)' != ''">
495                         <Output TaskParameter = "Include" ItemName = "IntermediateSatelliteAssemblies" />
496                 </CreateItem>
497         </Target>
498
499         <PropertyGroup>
500                 <CompileLicxFilesDependsOn></CompileLicxFilesDependsOn>
501         </PropertyGroup>
502
503         <Target Name = "CompileLicxFiles"
504                 Condition = "'@(LicxFiles)' != ''"
505                 DependsOnTargets = "$(CompileLicxFilesDependsOn)"
506                 Outputs = "$(IntermediateOutputPath)$(TargetFileName).licenses">
507                 <LC
508                         Sources = "@(LicxFiles)"
509                         LicenseTarget = "$(TargetFileName)"
510                         OutputDirectory = "$(IntermediateOutputPath)"
511                         OutputLicense = "$(IntermediateOutputPath)$(TargetFileName).licenses"
512                         ReferencedAssemblies = "@(ReferencePath);@(_ResolvedDependencyFiles)"
513                         ToolPath = "$(LCToolPath)"
514                         ToolExe = "$(LCToolExe)">
515
516                         <Output TaskParameter="OutputLicense" ItemName="CompiledLicenseFile"/>
517                         <Output TaskParameter="OutputLicense" ItemName="FileWrites"/>
518                 </LC>
519         </Target>
520
521         <!-- Assign target paths to files that will need to be copied along with the project -->
522         <Target Name = "AssignTargetPaths">
523                 <AssignTargetPath Files="@(None)" RootFolder="$(MSBuildProjectDirectory)">
524                         <Output TaskParameter="AssignedFiles" ItemName="NoneWithTargetPath"/>
525                 </AssignTargetPath>
526
527                 <AssignTargetPath Files="@(Content)" RootFolder="$(MSBuildProjectDirectory)">
528                         <Output TaskParameter="AssignedFiles" ItemName="ContentWithTargetPath"/>
529                 </AssignTargetPath>
530
531                 <AssignTargetPath Files="@(EmbeddedResource)" RootFolder="$(MSBuildProjectDirectory)">
532                         <Output TaskParameter="AssignedFiles" ItemName="EmbeddedResourceWithTargetPath"/>
533                 </AssignTargetPath>
534         </Target>
535
536         <Target Name="DeployOutputFiles"
537                 DependsOnTargets="PrepareResources;CoreCompile;_CopyDeployFilesToOutputDirectory;_CopyAppConfigFile">
538
539                 <Copy 
540                         SourceFiles="$(IntermediateOutputPath)$(AssemblyName)$(TargetExt).mdb"
541                         Condition="'$(OutDir)' != '' and Exists('$(IntermediateOutputPath)$(AssemblyName)$(TargetExt).mdb')"
542                         DestinationFolder="$(OutDir)"
543                         SkipUnchangedFiles="$(SkipCopyUnchangedFiles)" >
544                         <Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
545                 </Copy>
546
547                 <Copy SourceFiles="@(IntermediateAssembly)" Condition="'$(OutDir)' != '' and Exists ('@(IntermediateAssembly)')" DestinationFolder="$(OutDir)" SkipUnchangedFiles="$(SkipCopyUnchangedFiles)">
548                         <Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
549                 </Copy>
550
551                 <Copy
552                         SourceFiles = "@(IntermediateSatelliteAssemblies)"
553                         DestinationFiles = "@(IntermediateSatelliteAssemblies->'$(OutDir)\%(Culture)\$(AssemblyName).resources.dll')"
554                         Condition = "'@(IntermediateSatelliteAssemblies)' != ''"
555                         SkipUnchangedFiles="$(SkipCopyUnchangedFiles)">
556                         <Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
557                 </Copy>
558         </Target>
559
560         <Target Name="_CopyDeployFilesToOutputDirectory"
561                 DependsOnTargets="GetCopyToOutputDirectoryItems;
562                         _CopyDeployFilesToOutputDirectoryAlways;
563                         _CopyDeployFilesToOutputDirectoryPreserveNewest"/>
564
565         <Target Name="_CopyDeployFilesToOutputDirectoryPreserveNewest"
566                 Condition="'@(ItemsToCopyToOutputDirectoryPreserveNewest)' != ''"
567                 Inputs="@(ItemsToCopyToOutputDirectoryPreserveNewest)"
568                 Outputs="@(ItemsToCopyToOutputDirectoryPreserveNewest->'$(OutDir)%(TargetPath)')">
569
570                 <Copy SourceFiles="@(ItemsToCopyToOutputDirectoryPreserveNewest)"
571                         DestinationFiles="@(ItemsToCopyToOutputDirectoryPreserveNewest->'$(OutDir)%(TargetPath)')"
572                         SkipUnchangedFiles="$(SkipCopyUnchangedFiles)"> 
573                         <Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
574                 </Copy>
575         </Target>
576
577         <!-- Copy if newer -->
578         <Target Name="_CopyDeployFilesToOutputDirectoryAlways"
579                 Condition="'@(ItemsToCopyToOutputDirectoryAlways)' != ''">
580
581                 <Copy SourceFiles="@(ItemsToCopyToOutputDirectoryAlways)"
582                         DestinationFiles="@(ItemsToCopyToOutputDirectoryAlways->'$(OutDir)%(TargetPath)')">
583                         <Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
584                 </Copy>
585         </Target>
586
587
588         <Target Name="_CopyAppConfigFile" Condition="'@(AppConfigWithTargetPath)' != ''"
589                 Inputs="@(AppConfigWithTargetPath)"
590                 Outputs="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')">
591
592                 <Copy SourceFiles="@(AppConfigWithTargetPath)"
593                         DestinationFiles="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')">
594                         <Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
595                 </Copy>
596         </Target>
597
598         <Target Name="GetTargetPath" Outputs="$(TargetPath)"/>
599
600         <Target Name="GetCopyToOutputDirectoryItems"
601                 Outputs="@(AllItemsFullPathWithTargetPath)"
602                 DependsOnTargets="AssignTargetPaths;SplitProjectReferencesByExistent">
603
604                 <!-- FIXME: handle .vcproj
605                      FIXME: Private ProjectReferences are honored only in 3.5
606                 -->
607                 <MSBuild
608                         Projects="@(ProjectReferenceWithConfigurationExistent)"
609                         Targets="GetCopyToOutputDirectoryItems"
610                         Condition="'@(ProjectReferenceWithConfigurationExistent)' != '' and '%(ProjectReferenceWithConfigurationExistent.Private)' != 'false'">
611
612                         <Output TaskParameter="TargetOutputs" ItemName="AllChildProjectItemsWithTargetPath"/>
613                 </MSBuild>
614
615                 <!-- Process items from child project. The outputs need to have full path
616                      as they'll be used from other projects -->
617
618                 <CreateItem
619                         Include="@(AllChildProjectItemsWithTargetPath->'%(FullPath)')"
620                         Condition="'%(AllChildProjectItemsWithTargetPath.CopyToOutputDirectory)' == 'Always' or '%(AllChildProjectItemsWithTargetPath.CopyToOutputDirectory)' == 'PreserveNewest'">
621
622                         <Output TaskParameter="Include" ItemName="AllItemsFullPathWithTargetPath"/>
623                         <Output TaskParameter="Include" ItemName="ItemsToCopyToOutputDirectoryAlways"
624                                 Condition="'%(AllChildProjectItemsWithTargetPath.CopyToOutputDirectory)'=='Always'"/>
625                         <Output TaskParameter="Include" ItemName="ItemsToCopyToOutputDirectoryPreserveNewest"
626                                 Condition="'%(AllChildProjectItemsWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest'"/>
627
628                 </CreateItem>
629
630                 <!-- Process _this_ project's items -->
631
632                 <CreateItem
633                         Include="@(NoneWithTargetPath->'%(FullPath)')"
634                         Condition="'%(NoneWithTargetPath.CopyToOutputDirectory)' == 'Always' or '%(NoneWithTargetPath.CopyToOutputDirectory)' == 'PreserveNewest'">
635                         <Output TaskParameter="Include" ItemName="AllItemsFullPathWithTargetPath"/>
636                         <Output TaskParameter="Include" ItemName="ItemsToCopyToOutputDirectoryAlways"
637                                 Condition="'%(NoneWithTargetPath.CopyToOutputDirectory)'=='Always'"/>
638                         <Output TaskParameter="Include" ItemName="ItemsToCopyToOutputDirectoryPreserveNewest"
639                                 Condition="'%(NoneWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest'"/>
640                 </CreateItem>
641
642                 <CreateItem
643                         Include="@(ContentWithTargetPath->'%(FullPath)')"
644                         Condition="'%(ContentWithTargetPath.CopyToOutputDirectory)' == 'Always' or '%(ContentWithTargetPath.CopyToOutputDirectory)' == 'PreserveNewest'">
645                         <Output TaskParameter="Include" ItemName="AllItemsFullPathWithTargetPath"/>
646                         <Output TaskParameter="Include" ItemName="ItemsToCopyToOutputDirectoryAlways"
647                                 Condition="'%(ContentWithTargetPath.CopyToOutputDirectory)'=='Always'"/>
648                         <Output TaskParameter="Include" ItemName="ItemsToCopyToOutputDirectoryPreserveNewest"
649                                 Condition="'%(ContentWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest'"/>
650                 </CreateItem>
651
652                 <CreateItem
653                         Include="@(EmbeddedResourceWithTargetPath->'%(FullPath)')"
654                         Condition="'%(EmbeddedResourceWithTargetPath.CopyToOutputDirectory)' == 'Always' or '%(EmbeddedResourceWithTargetPath.CopyToOutputDirectory)' == 'PreserveNewest'">
655                         <Output TaskParameter="Include" ItemName="AllItemsFullPathWithTargetPath"/>
656                         <Output TaskParameter="Include" ItemName="ItemsToCopyToOutputDirectoryAlways"
657                                 Condition="'%(EmbeddedResourceWithTargetPath.CopyToOutputDirectory)'=='Always'"/>
658                         <Output TaskParameter="Include" ItemName="ItemsToCopyToOutputDirectoryPreserveNewest"
659                                 Condition="'%(EmbeddedResourceWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest'"/>
660                 </CreateItem>
661
662         </Target>
663
664         <!-- Pre/Post BuildEvents -->
665         <PropertyGroup>
666                 <PreBuildEventDependsOn />
667         </PropertyGroup>
668
669         <Target Name="PreBuildEvent"
670                 Condition="'$(PreBuildEvent)' != ''"
671                 DependsOnTargets="$(PreBuildEventDependsOn)">
672
673                 <Exec WorkingDirectory="$(OutDir)" Command="$(PreBuildEvent)" />
674         </Target>
675
676         <!-- PostBuildEvent depends on $(RunPostBuildEvent)
677
678                 Default: OnBuildSuccess
679                 OnBuildSuccess: Run after a successful build
680                 OnOutputUpdated: Run only if the output assembly got updates
681                 Always: Run always
682         -->
683         <PropertyGroup>
684                 <PostBuildEventDependsOn />
685         </PropertyGroup>
686
687         <!-- this gets invoked in two cases, from CoreBuildDependsOn, if the build completes
688              successfully, OR from OnError in CoreBuild, if the build failed and $(RunPostBuildEvent)
689              is 'Always' or 'OnOutputUpdated'. Invoke $(PostBuildEvent) if its either Empty (== OnBuildSuccess)
690              or OnBuildSuccess or Always OR (OnOutputUpdated and output assembly got updated) -->
691         <Target Name="PostBuildEvent"
692                 Condition="'$(PostBuildEvent)' != '' and
693                         ('$(RunPostBuildEvent)' != 'OnOutputUpdated' or
694                           '$(_AssemblyModifiedTimeBeforeCompile)' != '$(_AssemblyModifiedTimeAfterCompile)')"
695                 DependsOnTargets="$(PostBuildEventDependsOn)">
696
697                 <Exec WorkingDirectory="$(OutDir)" Command="$(PostBuildEvent)" />
698         </Target>
699
700         <!-- Timestamp the output assemblies, required for PostBuildEvent -->
701         <Target Name="_TimestampBeforeCompile" Condition="'$(RunPostBuildEvent)' == 'OnOutputUpdated'">
702                 <CreateItem Include="%(IntermediateAssembly.ModifiedTime)">
703                         <Output TaskParameter="Include" PropertyName="_AssemblyModifiedTimeBeforeCompile" />
704                 </CreateItem>
705         </Target>
706         <Target Name="_TimestampAfterCompile" Condition="'$(RunPostBuildEvent)' == 'OnOutputUpdated'">
707                 <CreateItem Include="%(IntermediateAssembly.ModifiedTime)">
708                         <Output TaskParameter="Include" PropertyName="_AssemblyModifiedTimeAfterCompile" />
709                 </CreateItem>
710         </Target>
711
712         <!-- Rebuild -->
713         <PropertyGroup>
714                 <RebuildDependsOn>
715                         BeforeRebuild;
716                         Clean;
717                         $(MSBuildProjectDefaultTargets);
718                         AfterRebuild;
719                 </RebuildDependsOn>
720
721                 <RebuildDependsOn Condition="'$(MSBuildProjectDefaultTargets)' == 'Rebuild'">
722                         BeforeRebuild;
723                         Clean;
724                         Build;
725                         AfterRebuild;
726                 </RebuildDependsOn>
727         </PropertyGroup>
728
729         <Target Name="BeforeRebuild" />
730         <Target Name="AfterRebuild" />
731
732         <Target Name="Rebuild"
733                 DependsOnTargets="$(RebuildDependsOn)"
734                 Outputs="$(TargetPath)"/>
735
736         <!-- Clean -->
737         <Target Name="_RecordCleanFile"
738                 DependsOnTargets="_GetCompileOutputsForClean">
739
740                 <!-- add to list of previous writes for this platform/config -->
741
742                 <ReadLinesFromFile File="$(IntermediateOutputPath)$(CleanFile)">
743                         <Output TaskParameter="Lines" ItemName="PreviousFileWrites"/>
744                 </ReadLinesFromFile>
745
746                 <RemoveDuplicates Inputs="@(PreviousFileWrites);@(FileWrites->'%(FullPath)')">
747                         <Output TaskParameter="Filtered" ItemName="CombinedFileWrites"/>
748                 </RemoveDuplicates>
749
750                 <!-- CopyLocal files: In case all the projects build to common output
751                      directory, then other projects might depend on some of these
752                      CopyLocal files, so delete only the ones under *this* project
753                      directory -->
754                 <FindUnderPath Path="$(MSBuildProjectDirectory)" Files="@(FileWritesShareable)">
755                         <Output TaskParameter="InPath" ItemName="FileWrites"/>
756                 </FindUnderPath>
757
758                 <WriteLinesToFile
759                         File="$(IntermediateOutputPath)$(CleanFile)"
760                         Lines="@(CombinedFileWrites)"
761                         Overwrite="true"/>
762         </Target>
763
764         <PropertyGroup>
765                 <CleanDependsOn>
766                         BeforeClean;
767                         CleanReferencedProjects;
768                         CoreClean;
769                         AfterClean
770                 </CleanDependsOn>
771         </PropertyGroup>
772
773         <Target Name="_GetCompileOutputsForClean">
774                 <!-- assembly and debug file in the *intermediate output path* -->
775                 <CreateItem Include="@(IntermediateAssembly)" Condition="Exists('@(IntermediateAssembly)')">
776                         <Output TaskParameter="Include" ItemName="FileWrites"/>
777                 </CreateItem>
778
779                 <CreateItem Include="$(IntermediateOutputPath)$(AssemblyName)$(TargetExt).mdb"
780                         Condition="Exists('$(IntermediateOutputPath)$(AssemblyName)$(TargetExt).mdb')">
781                         <Output TaskParameter="Include" ItemName="FileWrites"/>
782                 </CreateItem>
783         </Target>
784
785         <!-- Get the list of files written, for clean -->
786         <Target Name="_GetCleanFileWrites"
787                 DependsOnTargets="_GetCompileOutputsForClean">
788                 <ReadLinesFromFile File="$(IntermediateOutputPath)$(CleanFile)">
789                         <Output TaskParameter="Lines" ItemName="PreviousFileWrites"/>
790                 </ReadLinesFromFile>
791         </Target>
792
793         <Target Name="CleanReferencedProjects"
794                 DependsOnTargets="AssignProjectConfigurations">
795
796                 <!-- If building from .sln.proj or from IDE, clean will get handled by them,
797                      else we are building a project directly, from the command line, so
798                      clean the referenced projects -->
799                 <MSBuild Projects="@(ProjectReferenceWithConfigurationExistent)"
800                         Targets="Clean"
801                         Condition=" '$(BuildingSolutionFile)' != 'true' and '$(BuildingInsideVisualStudio)' != 'true' and '@(ProjectReferenceWithConfigurationExistent)' != ''" />
802
803         </Target>
804
805         <Target Name="Clean" DependsOnTargets="$(CleanDependsOn)"/>
806
807         <!-- Override in project to run before/after clean tasks -->
808         <Target Name="BeforeClean" />
809         <Target Name="AfterClean" />
810
811         <Target Name="CoreClean" DependsOnTargets="_GetCleanFileWrites">
812                 <Delete Files="@(PreviousFileWrites);@(FileWrites)" TreatErrorsAsWarnings="true"/>
813
814                 <!-- all previous files written for this platform/config have been deleted,
815                      we can safely remove the file list now -->
816                 <Delete Files="$(IntermediateOutputPath)$(CleanFile)" TreatErrorsAsWarnings="true" />
817         </Target>
818
819         <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\$(MSBuildThisFile)\ImportAfter\*"
820                 Condition="'$(ImportByWildcardAfterMicrosoftCommonTargets)' == 'true' and Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\$(MSBuildThisFile)\ImportAfter')"/>
821 </Project>