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