<Project DefaultTargets="Build" InitialTargets="_CheckForInvalidConfigurationAndPlatform" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
	<PropertyGroup>
		<ImportByWildcardBeforeMicrosoftCommonTargets Condition="'$(ImportByWildcardBeforeMicrosoftCommonTargets)' == ''">true</ImportByWildcardBeforeMicrosoftCommonTargets>
		<ImportByWildcardAfterMicrosoftCommonTargets Condition="'$(ImportByWildcardAfterMicrosoftCommonTargets)' == ''">true</ImportByWildcardAfterMicrosoftCommonTargets>
	</PropertyGroup>

	<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\$(MSBuildThisFile)\ImportBefore\*"
		Condition="'$(ImportByWildcardBeforeMicrosoftCommonTargets)' == 'true' and Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\$(MSBuildThisFile)\ImportBefore')"/>

	<Import Project="$(MSBuildProjectFullPath).user" Condition="Exists('$(MSBuildProjectFullPath).user')"/>

	<PropertyGroup>
		<OutputType Condition="'$(OutputType)' == ''">Exe</OutputType>
		<TargetExt Condition="'$(OutputType)' == 'Winexe'">.exe</TargetExt>
		<TargetExt Condition="'$(OutputType)' == 'Exe'">.exe</TargetExt>
		<TargetExt Condition="'$(OutputType)' == 'Library'">.dll</TargetExt>
		<TargetExt Condition="'$(OutputType)' == 'Netmodule'">.netmodule</TargetExt>
	</PropertyGroup>

	<PropertyGroup>
		<ProjectDir Condition="'$(ProjectDir)' == ''">$(MSBuildProjectDirectory)\</ProjectDir>
	</PropertyGroup>

	<!-- MSBuild defines this even outside of VS, and F# projects depend on it -->
	<PropertyGroup>
		<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">11.0</VisualStudioVersion>
	</PropertyGroup>

	<PropertyGroup>
		<AssemblyName Condition="'$(AssemblyName)' == ''">$(MSBuildProjectName)</AssemblyName>
		<OutputPath Condition="'$(OutputPath)' != '' and !HasTrailingSlash('$(OutputPath)')">$(OutputPath)\</OutputPath>
		<OutputPath Condition=" '$(Platform)'=='' and '$(Configuration)'=='' and '$(OutputPath)'=='' ">bin\Debug\</OutputPath>

		<TargetFrameworkIdentifier Condition="'$(TargetFrameworkIdentifier)' == ''">.NETFramework</TargetFrameworkIdentifier>
		<TargetFrameworkVersion Condition="'$(TargetFrameworkVersion)' == ''">v4.0</TargetFrameworkVersion>

		<TargetFrameworkMoniker Condition="'$(TargetFrameworkMoniker)' == '' and '$(TargetFrameworkProfile)' != ''">$(TargetFrameworkIdentifier),Version=$(TargetFrameworkVersion),Profile=$(TargetFrameworkProfile)</TargetFrameworkMoniker>
	        <TargetFrameworkMoniker Condition="'$(TargetFrameworkMoniker)' == ''">$(TargetFrameworkIdentifier),Version=$(TargetFrameworkVersion)</TargetFrameworkMoniker>
	</PropertyGroup>

	<PropertyGroup>
		<OutDir Condition="'$(OutDir)' == ''">$(OutputPath)</OutDir>
		<OutDir Condition="'$(OutDir)' != '' and !HasTrailingSlash('$(OutDir)')">$(OutDir)\</OutDir>

		<_OriginalConfiguration>$(Configuration)</_OriginalConfiguration>
		<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
		<ConfigurationName Condition="'$(ConfigurationName)' == ''">$(Configuration)</ConfigurationName>

		<_OriginalPlatform>$(Platform)</_OriginalPlatform>
		<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
		<PlatformName Condition="'$(PlatformName)' == ''">$(Platform)</PlatformName>
	</PropertyGroup>

	<!-- in MSBuild, these properties are set in a separate file that is only imported for .NETFramework -->
	<PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
		<AddAdditionalExplicitAssemblyReferences Condition="'$(AddAdditionalExplicitAssemblyReferences)' == ''">true</AddAdditionalExplicitAssemblyReferences>
		<AdditionalExplicitAssemblyReferences Condition="'$(AddAdditionalExplicitAssemblyReferences)' == 'true' and '$(TargetFrameworkVersion)' != 'v2.0' and '$(TargetFrameworkVersion)' != 'v3.0'">System.Core;$(AdditionalExplicitAssemblyReferences)</AdditionalExplicitAssemblyReferences>
	</PropertyGroup>

	<PropertyGroup>
		<SkipCopyUnchangedFiles Condition="'$(SkipCopyUnchangedFiles)' == ''">true</SkipCopyUnchangedFiles>
	</PropertyGroup>

	<PropertyGroup>
		<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)' == ''">obj\</BaseIntermediateOutputPath>
		<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)' != '' and !HasTrailingSlash('$(BaseIntermediateOutputPath)')">$(BaseIntermediateOutputPath)\</BaseIntermediateOutputPath>
		<CleanFile Condition="'$(CleanFile)'==''">$(MSBuildProjectFile).FilesWrittenAbsolute.txt</CleanFile>
	</PropertyGroup>

	<PropertyGroup Condition="'$(IntermediateOutputPath)' == ''">
		<IntermediateOutputPath Condition=" '$(PlatformName)' == 'AnyCPU'">$(BaseIntermediateOutputPath)$(Configuration)\</IntermediateOutputPath>
		<IntermediateOutputPath Condition=" '$(PlatformName)' != 'AnyCPU'">$(BaseIntermediateOutputPath)$(PlatformName)\$(Configuration)\</IntermediateOutputPath>
	</PropertyGroup>

	<PropertyGroup>
		<IntermediateOutputPath Condition="'$(IntermediateOutputPath)' != '' and !HasTrailingSlash('$(IntermediateOutputPath)')">$(IntermediateOutputPath)\</IntermediateOutputPath>
	</PropertyGroup>

	<ItemGroup>
		<IntermediateAssembly Include="$(IntermediateOutputPath)$(AssemblyName)$(TargetExt)" />

		<!-- creating this as a item to use FullPath on it, to build TargetPath -->
		<_OutDirItem Include="$(OutDir)"/>
	</ItemGroup>

	<PropertyGroup>
		<TargetName Condition="'$(TargetName)' == '' ">$(AssemblyName)</TargetName>
		<TargetFileName Condition="'$(TargetFileName)' == '' ">$(TargetName)$(TargetExt)</TargetFileName>
		<TargetDir Condition=" '$(TargetDir)' == '' ">@(_OutDirItem->'%(FullPath)')</TargetDir>
		<TargetPath Condition=" '$(TargetPath)' == '' ">@(_OutDirItem->'%(FullPath)\$(TargetFileName)')</TargetPath>
		<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildProjectFullPath);$(MSBuildToolsPath)\Microsoft.Common.targets</MSBuildAllProjects>
		<KeyOriginatorFile Condition=" '$(SignAssembly)' == 'true' ">$(AssemblyOriginatorKeyFile)</KeyOriginatorFile>
		<TargetingClr2Framework Condition="('$(TargetFrameworkIdentifier)' == '.NETFramework') and ('$(TargetFrameworkVersion)' == 'v2.0' or '$(TargetFrameworkVersion)' == 'v3.0' or '$(TargetFrameworkVersion)' == 'v3.5')">true</TargetingClr2Framework>
	</PropertyGroup>

	<Target Name="_CheckForInvalidConfigurationAndPlatform">
		<Error Condition=" '$(OutputPath)' == '' and '$(SkipInvalidConfigurations)' != 'true'"
			Text="'OutputPath' property is not set for this project. Usually this is caused by invalid Configuration/Platform combination. Original values: Configuration: $(_OriginalConfiguration) Platform: $(_OriginalPlatform)."/>

		<Warning Condition=" '$(OutputPath)' == '' and '$(SkipInvalidConfigurations)' == 'true'"
			Text="'OutputPath' property is not set for this project. Usually this is caused by invalid Configuration/Platform combination. Original values: Configuration: $(_OriginalConfiguration) Platform: $(_OriginalPlatform)."/>

		<!-- If OutDir is specified via the command line, then the earlier check
		     to add a trailing slash won't have any affect, so error here. -->
		<Error
			Condition="'$(OutDir)' != '' and !HasTrailingSlash('$(OutDir)')"
			Text="OutDir property must end with a slash."/>
	</Target>

	<PropertyGroup>
		<PrepareForBuildDependsOn>AssignLinkMetadata</PrepareForBuildDependsOn>
	</PropertyGroup>
	<Target Name="PrepareForBuild" DependsOnTargets="$(PrepareForBuildDependsOn)">
		<Message Importance="High" Text="Configuration: $(Configuration) Platform: $(Platform)"/>

		<!-- Look for app.config, if $(AppConfig) is specified, then use that. Else look in
		     @(None) and @(Content) -->
		<CreateItem Include="$(AppConfig)" Condition="'$(AppConfig)' != ''"
			AdditionalMetadata="TargetPath=$(TargetFileName).config">
			<Output TaskParameter="Include" ItemName="AppConfigWithTargetPath" />
		</CreateItem>

		<FindAppConfigFile PrimaryList="@(None)" SecondaryList="@(Content)" TargetPath="$(TargetFileName).config"
			Condition="'$(AppConfig)' == ''">
			<Output TaskParameter="AppConfigFile" ItemName="AppConfigWithTargetPath"/>
		</FindAppConfigFile>

		<MakeDir
			Directories="$(OutDir);$(IntermediateOutputPath);@(DocFileItem->'%(RelativeDir)')"
		/>
	</Target>

	<Target Name="AssignLinkMetadata">
	    <AssignLinkMetadata Items="@(EmbeddedResource)" Condition="'@(EmbeddedResource)' != '' and '%(EmbeddedResource.DefiningProjectFullPath)' != '$(MSBuildProjectFullPath)'">
	      <Output TaskParameter="OutputItems" ItemName="_EmbeddedResourceWithLinkAssigned" />
	    </AssignLinkMetadata>

	    <ItemGroup>
			<EmbeddedResource Remove="@(_EmbeddedResourceWithLinkAssigned)" />
			<EmbeddedResource Include="@(_EmbeddedResourceWithLinkAssigned)" />
			<_EmbeddedResourceWithLinkAssigned Remove="@(_EmbeddedResourceWithLinkAssigned)" />
	    </ItemGroup>
	</Target>

	<PropertyGroup>
		<GetFrameworkPathsDependsOn />
	</PropertyGroup>
	<Target Name="GetFrameworkPaths"
		Condition="'$(TargetFrameworkIdentifier)' == '' or '$(TargetFrameworkIdentifier)' == '.NETFramework'"
		DependsOnTargets="$(GetFrameworkPathsDependsOn)">
		<GetFrameworkPath>
			<Output Condition="'$(TargetFrameworkVersion)' == 'v4.5'"
				TaskParameter="FrameworkVersion45Path"
				ItemName="_CombinedTargetFrameworkDirectoriesItem"/>
			<Output Condition="'$(TargetFrameworkVersion)' == 'v4.0'"
				TaskParameter="FrameworkVersion40Path"
				ItemName="_CombinedTargetFrameworkDirectoriesItem"/>
			<Output Condition="'$(TargetFrameworkVersion)' == 'v3.5'"
				TaskParameter="FrameworkVersion35Path"
				ItemName="_CombinedTargetFrameworkDirectoriesItem"/>
			<Output Condition="'$(TargetFrameworkVersion)' == 'v3.0' or '$(TargetFrameworkVersion)' == 'v3.5'"
				TaskParameter="FrameworkVersion30Path"
				ItemName="_CombinedTargetFrameworkDirectoriesItem"/>
			<Output Condition="'$(TargetFrameworkVersion)' == 'v2.0' or '$(TargetFrameworkVersion)' == 'v3.0' or '$(TargetFrameworkVersion)' == 'v3.5'"
				TaskParameter="FrameworkVersion20Path"
				ItemName="_CombinedTargetFrameworkDirectoriesItem"/>
		</GetFrameworkPath>
		<CreateProperty Value="@(_CombinedTargetFrameworkDirectoriesItem)">
			<Output TaskParameter="Value" PropertyName="TargetFrameworkDirectory"/>
		</CreateProperty>

		<Warning Text="TargetFrameworkVersion '$(TargetFrameworkVersion)' not supported by this toolset (ToolsVersion: $(MSBuildToolsVersion))."
			Condition="'$(TargetFrameworkVersion)' != 'v4.5' and '$(TargetFrameworkVersion)' != 'v4.0' and '$(TargetFrameworkVersion)' != 'v3.5' and '$(TargetFrameworkVersion)' != 'v3.0' and '$(TargetFrameworkVersion)' != 'v2.0'"/>
	</Target>

	<PropertyGroup>
		<GetReferenceAssemblyPathsDependsOn />
	</PropertyGroup>
	<Target Name="GetReferenceAssemblyPaths" DependsOnTargets="$(GetReferenceAssemblyPathsDependsOn)">
		<!-- in case of .NETFramework, $(TargetFrameworkDirectory) would have been set by
		GetFrameworkPaths, if it hasn't been changed, then clear it, to avoid duplicates -->
		<CreateProperty Value="" Condition="'@(_CombinedTargetFrameworkDirectoriesItem)' == '$(TargetFrameworkDirectory)'">
			<Output TaskParameter="Value" PropertyName="TargetFrameworkDirectory"/>
		</CreateProperty>

		<GetReferenceAssemblyPaths
			Condition="'$(TargetFrameworkMoniker)' != '' and '$(_TargetFrameworkDirectories)' == ''"
			TargetFrameworkMoniker="$(TargetFrameworkMoniker)"
			RootPath="$(TargetFrameworkRootPath)">

			<Output TaskParameter="ReferenceAssemblyPaths" PropertyName="_TargetFrameworkDirectories"/>
			<Output TaskParameter="FullFrameworkReferenceAssemblyPaths" PropertyName="_FullFrameworkReferenceAssemblyPaths"/>
			<Output TaskParameter="TargetFrameworkMonikerDisplayName" PropertyName="TargetFrameworkMonikerDisplayName"/>
		</GetReferenceAssemblyPaths>


		<!-- Remove duplicates. -->
		<ItemGroup>
			<_TargetFrameworkDirectories Include="$(_TargetFrameworkDirectories);$(TargetFrameworkDirectory)" KeepDuplicates="false" />
		</ItemGroup>
		<PropertyGroup>
			<TargetFrameworkDirectory>@(_TargetFrameworkDirectories)</TargetFrameworkDirectory>
		</PropertyGroup>

		<ItemGroup Condition="'$(ImplicitlyExpandDesignTimeFacades)' == 'true'">
			<DesignTimeFacadeDirectoryRoots Include="$(TargetFrameworkDirectory)" />
			<DesignTimeFacadeDirectories Include="%(DesignTimeFacadeDirectoryRoots.Identity)\Facades\" Condition="Exists('%(DesignTimeFacadeDirectoryRoots.Identity)\Facades\')" />
			<_DesignTimeFacadeAssemblies Include="%(DesignTimeFacadeDirectories.Identity)\*.dll"/>
		</ItemGroup>

		<PropertyGroup Condition="'@(DesignTimeFacadeDirectories)' != ''">
			<TargetFrameworkDirectory>$(TargetFrameworkDirectory);@(DesignTimeFacadeDirectories)</TargetFrameworkDirectory>
		</PropertyGroup>

	</Target>

	<PropertyGroup>
		<AllowedReferenceAssemblyFileExtensions Condition=" '$(AllowedReferenceAssemblyFileExtensions)' == '' ">
			.exe;
			.dll
		</AllowedReferenceAssemblyFileExtensions>

		<AllowedReferenceRelatedFileExtensions Condition=" '$(AllowedReferenceRelatedFileExtensions)' == '' ">
			.exe.mdb;
			.dll.mdb;
			.pdb;
			.xml
		</AllowedReferenceRelatedFileExtensions>

		<AssemblySearchPaths Condition="'$(AssemblySearchPaths)' == ''">
			{CandidateAssemblyFiles};
			$(ReferencePath);
			@(AdditionalReferencePath);
			{HintPathFromItem};
			{TargetFrameworkDirectory};
			{PkgConfig};
			{GAC};
			{RawFileName};
			$(OutDir)
		</AssemblySearchPaths>

		<ResolveReferencesDependsOn>
			BeforeResolveReferences;
			ResolveProjectReferences;
			ResolveAssemblyReferences;
			AfterResolveReferences
		</ResolveReferencesDependsOn>

		<ResolveAssemblyReferencesDependsOn>
			GetFrameworkPaths;
			GetReferenceAssemblyPaths;
			PrepareForBuild
		</ResolveAssemblyReferencesDependsOn>
	</PropertyGroup>

	<PropertyGroup Condition="'$(TargetFrameworkMoniker)' != ''">
		<TargetFrameworkMonikerAssemblyAttributesPath Condition="'$(TargetFrameworkMonikerAssemblyAttributesPath)' == ''">$(IntermediateOutputPath)$(TargetFrameworkMoniker).AssemblyAttribute$(DefaultLanguageSourceExtension)</TargetFrameworkMonikerAssemblyAttributesPath>
		<GenerateTargetFrameworkAttribute Condition="'$(GenerateTargetFrameworkAttribute)' == '' and '$(TargetFrameworkMoniker)'
	!= '' and '$(TargetingClr2Framework)' != 'true'">true</GenerateTargetFrameworkAttribute>
	</PropertyGroup>

	<ItemGroup Condition="'$(GenerateTargetFrameworkAttribute)' == 'true'">
		<FileWrites Include="$(TargetFrameworkMonikerAssemblyAttributesPath)" />
	</ItemGroup>

	<Target Name="_GenerateTargetFrameworkMonikerAttribute"
		DependsOnTargets="PrepareForBuild;GetReferenceAssemblyPaths"
		Inputs="$(MSBuildToolsPath)\Microsoft.Common.targets"
		Outputs="$(TargetFrameworkMonikerAssemblyAttributesPath)">

		<WriteLinesToFile
			File="$(TargetFrameworkMonikerAssemblyAttributesPath)"
			Lines="$(TargetFrameworkMonikerAssemblyAttributeText)"
			Overwrite="true"
			ContinueOnError="true"
			Condition="'@(Compile)' != '' and '$(TargetFrameworkMonikerAssemblyAttributeText)' != ''"
		/>
	</Target>

	<Target Name="GenerateTargetFrameworkMonikerAttribute"
		DependsOnTargets="_GenerateTargetFrameworkMonikerAttribute"
		Condition="'$(GenerateTargetFrameworkAttribute)' == 'true'">

		<ItemGroup Condition="'@(Compile)' != '' and '$(TargetFrameworkMonikerAssemblyAttributeText)' != ''">
			<Compile Include="$(TargetFrameworkMonikerAssemblyAttributesPath)"/>
		</ItemGroup>
	</Target>

	<Target Name="ResolveReferences" DependsOnTargets="$(ResolveReferencesDependsOn)"/>

	<Target Name="BeforeResolveReferences" />
	<Target Name="AfterResolveReferences" />

	<Target Name="ResolveAssemblyReferences" DependsOnTargets="$(ResolveAssemblyReferencesDependsOn)">
		<CreateItem Include="@(Reference)" Exclude="$(AdditionalExplicitAssemblyReferences)">
			<Output TaskParameter="Include" ItemName="_Reference"/>
		</CreateItem>

		<CreateItem Include="$(AdditionalExplicitAssemblyReferences)">
			<Output TaskParameter="Include" ItemName="_Reference"/>
		</CreateItem>

		<ResolveAssemblyReference
			Assemblies="@(_Reference)"
			AssemblyFiles="@(ChildProjectReferences);@(_ExplicitReference)"
			SearchPaths="$(AssemblySearchPaths)"
			CandidateAssemblyFiles="@(Content);@(None)"
			TargetFrameworkDirectories="$(TargetFrameworkDirectory)"
			AllowedAssemblyExtensions="$(AllowedReferenceAssemblyFileExtensions)"
			AllowedRelatedFileExtensions="$(AllowedReferenceRelatedFileExtensions)"
			FindDependencies="true"
			FindSatellites="true"
			FindRelatedFiles="true"
			TargetFrameworkMoniker="$(TargetFrameworkMoniker)"
			TargetFrameworkMonikerDisplayName="$(TargetFrameworkMonikerDisplayName)"
			TargetFrameworkVersion="$(TargetFrameworkVersion)"
		>
			<Output TaskParameter="ResolvedFiles" ItemName="ResolvedFiles"/>
			<Output TaskParameter="ResolvedFiles" ItemName="ReferencePath"/>
			<Output TaskParameter="ResolvedDependencyFiles" ItemName="ReferenceDependencyPaths"/>
			<Output TaskParameter="RelatedFiles" ItemName="_ReferenceRelatedPaths"/>
			<Output TaskParameter="SatelliteFiles" ItemName="ReferenceSatellitePaths"/>
			<Output TaskParameter="CopyLocalFiles" ItemName="ReferenceCopyLocalPaths"/>

			<!-- FIXME: backwards compatibility -->
			<Output TaskParameter="ResolvedDependencyFiles" ItemName="_ResolvedDependencyFiles"/>
		</ResolveAssemblyReference>
	</Target>

	<Target
		Name="AssignProjectConfiguration"
		Condition="'@(ProjectReference)' != ''">

		<!-- assign configs if building a solution file -->
		<AssignProjectConfiguration
			ProjectReferences = "@(ProjectReference)"
			SolutionConfigurationContents = "$(CurrentSolutionConfigurationContents)"
			Condition="$(CurrentSolutionConfigurationContents) != '' and ('$(BuildingSolutionFile)' == 'true' or '$(BuildingInsideVisualStudio)' == 'true')">

			<Output TaskParameter = "AssignedProjects" ItemName = "ProjectReferenceWithConfiguration"/>
		</AssignProjectConfiguration>

		<!-- Else, just -->
		<CreateItem Include="@(ProjectReference)" Condition="$(CurrentSolutionConfigurationContents) == '' or ('$(BuildingSolutionFile)' != 'true' and '$(BuildingInsideVisualStudio)' != 'true')">
			<Output TaskParameter="Include" ItemName="ProjectReferenceWithConfiguration"/>
		</CreateItem>

	</Target>

	<!-- Split projects into 2 lists
		ProjectReferenceWithConfigurationExistent: Projects existent on disk
		ProjectReferenceWithConfigurationNonExistent: Projects non-existent on disk -->

	<Target Name="SplitProjectReferencesByExistent"
		DependsOnTargets="AssignProjectConfiguration">

		<CreateItem Include="@(ProjectReferenceWithConfiguration)" Condition="'@(ProjectReferenceWithConfiguration)' != ''">
			<Output TaskParameter="Include" ItemName="ProjectReferenceWithConfigurationExistent"
				Condition="Exists ('%(ProjectReferenceWithConfiguration.Identity)')"/>

			<Output TaskParameter="Include" ItemName="ProjectReferenceWithConfigurationNonExistent"
				Condition="!Exists ('%(ProjectReferenceWithConfiguration.Identity)')"/>
		</CreateItem>
	</Target>

	<Target
		Name="ResolveProjectReferences"
		DependsOnTargets="SplitProjectReferencesByExistent"
	>
		<!-- If building from a .sln.proj or from IDE, then referenced projects have already
		     been built, so just get the target paths -->
		<MSBuild
			Projects="@(ProjectReferenceWithConfigurationExistent)"
			Targets="GetTargetPath"
			Properties="%(ProjectReferenceWithConfigurationExistent.SetConfiguration); %(ProjectReferenceWithConfigurationExistent.SetPlatform)"
			Condition="'@(ProjectReferenceWithConfigurationExistent)' != '' and ('$(BuildingSolutionFile)' == 'true' or '$(BuildingInsideVisualStudio)' == 'true')">

			<Output TaskParameter="TargetOutputs" ItemName="ChildProjectReferences" Condition="'%(ProjectReferenceWithConfigurationExistent.ReferenceOutputAssembly)' != 'false'"/>
		</MSBuild>

		<!-- Building a project directly, build the referenced the projects also -->
		<MSBuild
			Projects="@(ProjectReferenceWithConfigurationExistent)"
			Properties="%(ProjectReferenceWithConfigurationExistent.SetConfiguration); %(ProjectReferenceWithConfigurationExistent.SetPlatform)"
			Condition="'@(ProjectReferenceWithConfigurationExistent)' != '' and '$(BuildingSolutionFile)' != 'true' and '$(BuildingInsideVisualStudio)' != 'true' ">

			<Output TaskParameter="TargetOutputs" ItemName="ChildProjectReferences" Condition="'%(ProjectReferenceWithConfigurationExistent.ReferenceOutputAssembly)' != 'false'"/>
		</MSBuild>

		<Warning Text="Referenced Project %(ProjectReferenceWithConfigurationNonExistent.Identity) not found, ignoring."
			 Condition="'@(ProjectReferenceWithConfigurationNonExistent)' != ''"/>
	</Target>

	<Target Name = "CopyFilesMarkedCopyLocal">
		<Copy
			SourceFiles="@(ReferenceCopyLocalPaths)"
			DestinationFiles="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')"
			SkipUnchangedFiles="$(SkipCopyUnchangedFiles)">
			<Output TaskParameter = "DestinationFiles" ItemName = "FileWritesShareable"/>
		</Copy>
	</Target>

	<Target Name="_ComputeNonExistentFileProperty" Condition='false'>
		<CreateProperty Value="__NonExistentSubDir__\__NonExistentFile__">
			<Output TaskParameter="Value" PropertyName="NonExistentFile"/>
		</CreateProperty>
	</Target>

	<PropertyGroup>
		<BuildDependsOn>
			BuildOnlySettings;
			BeforeBuild;
			CoreBuild;
			AfterBuild
		</BuildDependsOn>
	</PropertyGroup>

	<Target Name="BuildOnlySettings"/>
	<Target Name="BeforeBuild"/>
	<Target Name="AfterBuild"/>

	<Target Name="Build" DependsOnTargets="$(BuildDependsOn)" Outputs="$(TargetPath)"/>

	<PropertyGroup>
		<CoreBuildDependsOn>
			PrepareForBuild;
			GetFrameworkPaths;
			GetReferenceAssemblyPaths;
			PreBuildEvent;
			ResolveReferences;
			CopyFilesMarkedCopyLocal;
			PrepareResources;
			Compile;
			PrepareForRun;
			DeployOutputFiles;
			_RecordCleanFile;
			PostBuildEvent
		</CoreBuildDependsOn>
	</PropertyGroup>

	<Target
		Name="CoreBuild"
		DependsOnTargets="$(CoreBuildDependsOn)"
		Outputs="$(OutDir)$(AssemblyName)$(TargetExt)">

		<OnError ExecuteTargets="_TimestampAfterCompile;PostBuildEvent"
			Condition=" '$(RunPostBuildEvent)' == 'Always' or '$(RunPostBuildEvent)' == 'OnOutputUpdated'"/>

		<OnError ExecuteTargets="_RecordCleanFile" />
	</Target>

	<PropertyGroup>
		<CompileDependsOn>
			ResolveReferences;
			GenerateTargetFrameworkMonikerAttribute;
			BeforeCompile;
			_TimestampBeforeCompile;
			CoreCompile;
			_TimestampAfterCompile;
			AfterCompile
		</CompileDependsOn>
	</PropertyGroup>

	<Target Name="BeforeCompile" />
	<Target Name="AfterCompile" />

	<Target Name="Compile" DependsOnTargets="$(CompileDependsOn)"/>

	<PropertyGroup>
		<PrepareForRunDependsOn>
			DeployOutputFiles
		</PrepareForRunDependsOn>
	</PropertyGroup>
	<Target Name="PrepareForRun" DependsOnTargets="$(PrepareForRunDependsOn)"/>

	<PropertyGroup>
		<PrepareResourcesDependsOn>
			AssignTargetPaths;
			SplitResourcesByCulture;
			CreateManifestResourceNames;
			CopyNonResxEmbeddedResources;
			GenerateResources;
			GenerateSatelliteAssemblies;
			CompileLicxFiles
		</PrepareResourcesDependsOn>
	</PropertyGroup>
	<Target Name="PrepareResources" DependsOnTargets="$(PrepareResourcesDependsOn)" />

	<Target Name="SplitResourcesByCulture" DependsOnTargets="AssignTargetPaths">
		<!-- Extract .licx files into @(LicxFiles) -->
		<CreateItem Include="@(EmbeddedResourceWithTargetPath)" Condition="'%(Extension)' == '.licx'">
			<Output TaskParameter="Include" ItemName="LicxFiles"/>
		</CreateItem>

		<!-- Split *remaining* resource files into various groups.. -->
		<AssignCulture Files="@(EmbeddedResourceWithTargetPath)" Condition="'%(Extension)' != '.licx'">
			<Output TaskParameter="AssignedFilesWithNoCulture" ItemName="ResourcesWithNoCulture"/>
			<Output TaskParameter="AssignedFilesWithCulture" ItemName="ResourcesWithCulture"/>
		</AssignCulture>

		<CreateItem Include="@(ResourcesWithNoCulture)" Condition="'%(Extension)' == '.resx'">
			<Output TaskParameter="Include" ItemName="ResxWithNoCulture"/>
		</CreateItem>

		<CreateItem Include="@(ResourcesWithNoCulture)" Condition="'%(Extension)' != '.resx'">
			<Output TaskParameter="Include" ItemName="NonResxWithNoCulture"/>
		</CreateItem>

		<CreateItem Include="@(ResourcesWithCulture)" Condition="'%(Extension)' == '.resx'">
			<Output TaskParameter="Include" ItemName="ResxWithCulture"/>
		</CreateItem>

		<CreateItem Include="@(ResourcesWithCulture)" Condition="'%(Extension)' != '.resx'">
			<Output TaskParameter="Include" ItemName="NonResxWithCulture"/>
		</CreateItem>
	</Target>

	<!-- Copy non-resx resources to their manifest resource names, this is what the compiler expects -->
	<Target Name = "CopyNonResxEmbeddedResources"
		Condition = "'@(NonResxWithCulture)' != '' or '@(NonResxWithNoCulture)' != '' or '@(ManifestNonResxWithCulture)' != '' or '@(ManifestNonResxWithNoCulture)' != ''">

		<MakeDir Directories="$(IntermediateOutputPath)%(ManifestNonResxWithCulture.Culture)"/>
		<Copy SourceFiles = "@(NonResxWithCulture)"
			DestinationFiles = "@(ManifestNonResxWithCulture->'$(IntermediateOutputPath)%(Identity)')"
			SkipUnchangedFiles="$(SkipCopyUnchangedFiles)">
			<Output TaskParameter = "DestinationFiles" ItemName = "ManifestNonResxWithCultureOnDisk"/>
			<Output TaskParameter = "DestinationFiles" ItemName = "FileWrites"/>
		</Copy>

		<Copy SourceFiles = "@(NonResxWithNoCulture)"
			DestinationFiles = "@(ManifestNonResxWithNoCulture->'$(IntermediateOutputPath)%(Identity)')"
			SkipUnchangedFiles="$(SkipCopyUnchangedFiles)">
			<Output TaskParameter = "DestinationFiles" ItemName = "ManifestNonResxWithNoCultureOnDisk"/>
			<Output TaskParameter = "DestinationFiles" ItemName = "FileWrites"/>
		</Copy>
	</Target>

	<Target Name = "GenerateResources">
		<GenerateResource
			Sources = "@(ResxWithNoCulture)"
			UseSourcePath = "true"
			OutputResources = "@(ManifestResourceWithNoCultureName->'$(IntermediateOutputPath)%(Identity).resources')"
			Condition = "'@(ResxWithNoCulture)' != '' ">

			<Output TaskParameter = "OutputResources" ItemName = "ManifestResourceWithNoCulture"/>
			<Output TaskParameter = "FilesWritten" ItemName = "FileWrites"/>
		</GenerateResource>

		<GenerateResource
			Sources = "@(ResxWithCulture)"
			UseSourcePath = "true"
			OutputResources = "@(ManifestResourceWithCultureName->'$(IntermediateOutputPath)%(Identity).resources')"
			Condition = "'@(ResxWithCulture)' != '' ">

			<Output TaskParameter = "OutputResources" ItemName = "ManifestResourceWithCulture"/>
			<Output TaskParameter = "FilesWritten" ItemName = "FileWrites"/>
		</GenerateResource>
	</Target>

	<Target Name="GenerateSatelliteAssemblies"
		Inputs="@(ManifestResourceWithCulture);@(ManifestNonResxWithCultureOnDisk)"
		Outputs="$(IntermediateOutputPath)%(Culture)\$(AssemblyName).resources.dll" >
		<!-- @(NonResxWithCulture) - rename files to ManifestNon.. and then use for AL -->
		<MakeDir Directories = "$(IntermediateOutputPath)%(ManifestResourceWithCulture.Culture)" Condition = "'@(ManifestResourceWithCulture)' != ''" />
		<MakeDir Directories = "$(IntermediateOutputPath)%(ManifestNonResxWithCultureOnDisk.Culture)" Condition = "'@(ManifestNonResxWithCultureOnDisk)' != ''" />

		<AL
			Culture = "%(Culture)"
			DelaySign="$(DelaySign)"
			EmbedResources = "@(ManifestResourceWithCulture);@(ManifestNonResxWithCultureOnDisk)"
			KeyFile="$(KeyOriginatorFile)"
			ToolExe="$(AlToolExe)"
			ToolPath="$(AlToolPath)"
			OutputAssembly = "$(IntermediateOutputPath)%(Culture)\$(AssemblyName).resources.dll" >
			<Output TaskParameter="OutputAssembly" ItemName="FileWrites"/>
		</AL>


		<CreateItem
			Include = "$(IntermediateOutputPath)%(Culture)\$(AssemblyName).resources.dll"
			AdditionalMetadata = "Culture=%(Culture)"
			Condition = "'@(ManifestResourceWithCulture)' != '' or '@(ManifestNonResxWithCultureOnDisk)' != ''">
			<Output TaskParameter = "Include" ItemName = "IntermediateSatelliteAssemblies" />
		</CreateItem>
	</Target>

	<PropertyGroup>
		<CompileLicxFilesDependsOn></CompileLicxFilesDependsOn>
	</PropertyGroup>

	<Target Name = "CompileLicxFiles"
		Condition = "'@(LicxFiles)' != ''"
		DependsOnTargets = "$(CompileLicxFilesDependsOn)"
		Outputs = "$(IntermediateOutputPath)$(TargetFileName).licenses">
		<LC
			Sources = "@(LicxFiles)"
			LicenseTarget = "$(TargetFileName)"
			OutputDirectory = "$(IntermediateOutputPath)"
			OutputLicense = "$(IntermediateOutputPath)$(TargetFileName).licenses"
			ReferencedAssemblies = "@(ReferencePath);@(ReferenceDependencyPaths)"
			ToolPath = "$(LCToolPath)"
			ToolExe = "$(LCToolExe)">

			<Output TaskParameter="OutputLicense" ItemName="CompiledLicenseFile"/>
			<Output TaskParameter="OutputLicense" ItemName="FileWrites"/>
		</LC>
	</Target>

	<!-- Assign target paths to files that will need to be copied along with the project -->
	<Target Name = "AssignTargetPaths">
		<AssignTargetPath Files="@(None)" RootFolder="$(MSBuildProjectDirectory)">
			<Output TaskParameter="AssignedFiles" ItemName="NoneWithTargetPath"/>
		</AssignTargetPath>

		<AssignTargetPath Files="@(Content)" RootFolder="$(MSBuildProjectDirectory)">
			<Output TaskParameter="AssignedFiles" ItemName="ContentWithTargetPath"/>
		</AssignTargetPath>

		<AssignTargetPath Files="@(EmbeddedResource)" RootFolder="$(MSBuildProjectDirectory)">
			<Output TaskParameter="AssignedFiles" ItemName="EmbeddedResourceWithTargetPath"/>
		</AssignTargetPath>
	</Target>

	<Target Name="DeployOutputFiles"
		DependsOnTargets="PrepareResources;CoreCompile;_CopyDeployFilesToOutputDirectory;_CopyAppConfigFile">

		<Copy
			SourceFiles="$(IntermediateOutputPath)$(AssemblyName)$(TargetExt).mdb"
			Condition="'$(OutDir)' != '' and Exists('$(IntermediateOutputPath)$(AssemblyName)$(TargetExt).mdb')"
			DestinationFolder="$(OutDir)"
			SkipUnchangedFiles="$(SkipCopyUnchangedFiles)" >
			<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
		</Copy>

		<Copy
			SourceFiles="$(IntermediateOutputPath)$(AssemblyName).pdb"
			Condition="'$(OutDir)' != '' and Exists('$(IntermediateOutputPath)$(AssemblyName).pdb')"
			DestinationFolder="$(OutDir)"
			SkipUnchangedFiles="$(SkipCopyUnchangedFiles)" >
			<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
		</Copy>

		<Copy SourceFiles="@(IntermediateAssembly)" Condition="'$(OutDir)' != '' and Exists ('@(IntermediateAssembly)')" DestinationFolder="$(OutDir)" SkipUnchangedFiles="$(SkipCopyUnchangedFiles)">
			<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
		</Copy>

		<Copy
			SourceFiles = "@(IntermediateSatelliteAssemblies)"
			DestinationFiles = "@(IntermediateSatelliteAssemblies->'$(OutDir)\%(Culture)\$(AssemblyName).resources.dll')"
			Condition = "'@(IntermediateSatelliteAssemblies)' != ''"
			SkipUnchangedFiles="$(SkipCopyUnchangedFiles)">
			<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
		</Copy>
	</Target>

	<Target Name="_CopyDeployFilesToOutputDirectory"
		DependsOnTargets="GetCopyToOutputDirectoryItems;
			_CopyDeployFilesToOutputDirectoryAlways;
			_CopyDeployFilesToOutputDirectoryPreserveNewest"/>

	<Target Name="_CopyDeployFilesToOutputDirectoryPreserveNewest"
		Condition="'@(ItemsToCopyToOutputDirectoryPreserveNewest)' != ''"
		Inputs="@(ItemsToCopyToOutputDirectoryPreserveNewest)"
		Outputs="@(ItemsToCopyToOutputDirectoryPreserveNewest->'$(OutDir)%(TargetPath)')">

		<Copy SourceFiles="@(ItemsToCopyToOutputDirectoryPreserveNewest)"
			DestinationFiles="@(ItemsToCopyToOutputDirectoryPreserveNewest->'$(OutDir)%(TargetPath)')"
			SkipUnchangedFiles="$(SkipCopyUnchangedFiles)">
			<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
		</Copy>
	</Target>

	<!-- Copy if newer -->
	<Target Name="_CopyDeployFilesToOutputDirectoryAlways"
		Condition="'@(ItemsToCopyToOutputDirectoryAlways)' != ''">

		<Copy SourceFiles="@(ItemsToCopyToOutputDirectoryAlways)"
			DestinationFiles="@(ItemsToCopyToOutputDirectoryAlways->'$(OutDir)%(TargetPath)')">
			<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
		</Copy>
	</Target>


	<Target Name="_CopyAppConfigFile" Condition="'@(AppConfigWithTargetPath)' != ''"
		Inputs="@(AppConfigWithTargetPath)"
		Outputs="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')">

		<Copy SourceFiles="@(AppConfigWithTargetPath)"
			DestinationFiles="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')">
			<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
		</Copy>
	</Target>

	<Target Name="GetTargetPath" Outputs="$(TargetPath)"/>

	<Target Name="GetCopyToOutputDirectoryItems"
		Outputs="@(AllItemsFullPathWithTargetPath)"
		DependsOnTargets="AssignTargetPaths;SplitProjectReferencesByExistent">

		<!-- FIXME: handle .vcproj
		     FIXME: Private ProjectReferences are honored only in 3.5
		-->
		<MSBuild
			Projects="@(ProjectReferenceWithConfigurationExistent)"
			Targets="GetCopyToOutputDirectoryItems"
			Condition="'@(ProjectReferenceWithConfigurationExistent)' != '' and '%(ProjectReferenceWithConfigurationExistent.Private)' != 'false'">

			<Output TaskParameter="TargetOutputs" ItemName="AllChildProjectItemsWithTargetPath"/>
		</MSBuild>

		<!-- Process items from child project. The outputs need to have full path
		     as they'll be used from other projects -->

		<CreateItem
			Include="@(AllChildProjectItemsWithTargetPath->'%(FullPath)')"
			Condition="'%(AllChildProjectItemsWithTargetPath.CopyToOutputDirectory)' == 'Always' or '%(AllChildProjectItemsWithTargetPath.CopyToOutputDirectory)' == 'PreserveNewest'">

			<Output TaskParameter="Include" ItemName="AllItemsFullPathWithTargetPath"/>
			<Output TaskParameter="Include" ItemName="ItemsToCopyToOutputDirectoryAlways"
				Condition="'%(AllChildProjectItemsWithTargetPath.CopyToOutputDirectory)'=='Always'"/>
			<Output TaskParameter="Include" ItemName="ItemsToCopyToOutputDirectoryPreserveNewest"
				Condition="'%(AllChildProjectItemsWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest'"/>

		</CreateItem>

		<!-- Process _this_ project's items -->

		<CreateItem
			Include="@(NoneWithTargetPath->'%(FullPath)')"
			Condition="'%(NoneWithTargetPath.CopyToOutputDirectory)' == 'Always' or '%(NoneWithTargetPath.CopyToOutputDirectory)' == 'PreserveNewest'">
			<Output TaskParameter="Include" ItemName="AllItemsFullPathWithTargetPath"/>
			<Output TaskParameter="Include" ItemName="ItemsToCopyToOutputDirectoryAlways"
				Condition="'%(NoneWithTargetPath.CopyToOutputDirectory)'=='Always'"/>
			<Output TaskParameter="Include" ItemName="ItemsToCopyToOutputDirectoryPreserveNewest"
				Condition="'%(NoneWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest'"/>
		</CreateItem>

		<CreateItem
			Include="@(ContentWithTargetPath->'%(FullPath)')"
			Condition="'%(ContentWithTargetPath.CopyToOutputDirectory)' == 'Always' or '%(ContentWithTargetPath.CopyToOutputDirectory)' == 'PreserveNewest'">
			<Output TaskParameter="Include" ItemName="AllItemsFullPathWithTargetPath"/>
			<Output TaskParameter="Include" ItemName="ItemsToCopyToOutputDirectoryAlways"
				Condition="'%(ContentWithTargetPath.CopyToOutputDirectory)'=='Always'"/>
			<Output TaskParameter="Include" ItemName="ItemsToCopyToOutputDirectoryPreserveNewest"
				Condition="'%(ContentWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest'"/>
		</CreateItem>

		<CreateItem
			Include="@(EmbeddedResourceWithTargetPath->'%(FullPath)')"
			Condition="'%(EmbeddedResourceWithTargetPath.CopyToOutputDirectory)' == 'Always' or '%(EmbeddedResourceWithTargetPath.CopyToOutputDirectory)' == 'PreserveNewest'">
			<Output TaskParameter="Include" ItemName="AllItemsFullPathWithTargetPath"/>
			<Output TaskParameter="Include" ItemName="ItemsToCopyToOutputDirectoryAlways"
				Condition="'%(EmbeddedResourceWithTargetPath.CopyToOutputDirectory)'=='Always'"/>
			<Output TaskParameter="Include" ItemName="ItemsToCopyToOutputDirectoryPreserveNewest"
				Condition="'%(EmbeddedResourceWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest'"/>
		</CreateItem>

	</Target>

	<!-- Pre/Post BuildEvents -->
	<PropertyGroup>
		<PreBuildEventDependsOn />
	</PropertyGroup>

	<Target Name="PreBuildEvent"
		Condition="'$(PreBuildEvent)' != ''"
		DependsOnTargets="$(PreBuildEventDependsOn)">

		<Exec WorkingDirectory="$(OutDir)" Command="$(PreBuildEvent)" />
	</Target>

	<!-- PostBuildEvent depends on $(RunPostBuildEvent)

		Default: OnBuildSuccess
		OnBuildSuccess: Run after a successful build
		OnOutputUpdated: Run only if the output assembly got updates
		Always: Run always
	-->
	<PropertyGroup>
		<PostBuildEventDependsOn />
	</PropertyGroup>

	<!-- this gets invoked in two cases, from CoreBuildDependsOn, if the build completes
	     successfully, OR from OnError in CoreBuild, if the build failed and $(RunPostBuildEvent)
	     is 'Always' or 'OnOutputUpdated'. Invoke $(PostBuildEvent) if its either Empty (== OnBuildSuccess)
	     or OnBuildSuccess or Always OR (OnOutputUpdated and output assembly got updated) -->
	<Target Name="PostBuildEvent"
		Condition="'$(PostBuildEvent)' != '' and
			('$(RunPostBuildEvent)' != 'OnOutputUpdated' or
			  '$(_AssemblyModifiedTimeBeforeCompile)' != '$(_AssemblyModifiedTimeAfterCompile)')"
		DependsOnTargets="$(PostBuildEventDependsOn)">

		<Exec WorkingDirectory="$(OutDir)" Command="$(PostBuildEvent)" />
	</Target>

	<!-- Timestamp the output assemblies, required for PostBuildEvent -->
	<Target Name="_TimestampBeforeCompile" Condition="'$(RunPostBuildEvent)' == 'OnOutputUpdated'">
		<CreateItem Include="%(IntermediateAssembly.ModifiedTime)">
			<Output TaskParameter="Include" PropertyName="_AssemblyModifiedTimeBeforeCompile" />
		</CreateItem>
	</Target>
	<Target Name="_TimestampAfterCompile" Condition="'$(RunPostBuildEvent)' == 'OnOutputUpdated'">
		<CreateItem Include="%(IntermediateAssembly.ModifiedTime)">
			<Output TaskParameter="Include" PropertyName="_AssemblyModifiedTimeAfterCompile" />
		</CreateItem>
	</Target>

	<!-- Rebuild -->
	<PropertyGroup>
		<RebuildDependsOn>
			BeforeRebuild;
			Clean;
			$(MSBuildProjectDefaultTargets);
			AfterRebuild;
		</RebuildDependsOn>

		<RebuildDependsOn Condition="'$(MSBuildProjectDefaultTargets)' == 'Rebuild'">
			BeforeRebuild;
			Clean;
			Build;
			AfterRebuild;
		</RebuildDependsOn>
	</PropertyGroup>

	<Target Name="BeforeRebuild" />
	<Target Name="AfterRebuild" />

	<Target Name="Rebuild"
		DependsOnTargets="$(RebuildDependsOn)"
		Outputs="$(TargetPath)"/>

	<!-- Clean -->
	<Target Name="_RecordCleanFile"
		DependsOnTargets="_GetCompileOutputsForClean">

		<!-- add to list of previous writes for this platform/config -->

		<ReadLinesFromFile File="$(IntermediateOutputPath)$(CleanFile)">
			<Output TaskParameter="Lines" ItemName="PreviousFileWrites"/>
		</ReadLinesFromFile>

		<!-- CopyLocal files: In case all the projects build to common output
		     directory, then other projects might depend on some of these
		     CopyLocal files, so delete only the ones under *this* project
		     directory -->
		<FindUnderPath Path="$(MSBuildProjectDirectory)" Files="@(FileWritesShareable)">
			<Output TaskParameter="InPath" ItemName="FileWrites"/>
		</FindUnderPath>

		<RemoveDuplicates Inputs="@(PreviousFileWrites);@(FileWrites->'%(FullPath)')">
			<Output TaskParameter="Filtered" ItemName="CombinedFileWrites"/>
		</RemoveDuplicates>

		<WriteLinesToFile
			File="$(IntermediateOutputPath)$(CleanFile)"
			Lines="@(CombinedFileWrites)"
			Overwrite="true"/>
	</Target>

	<PropertyGroup>
		<CleanDependsOn>
			BeforeClean;
			CleanReferencedProjects;
			CoreClean;
			AfterClean
		</CleanDependsOn>
	</PropertyGroup>

	<Target Name="_GetCompileOutputsForClean">
		<!-- assembly and debug file in the *intermediate output path* -->
		<CreateItem Include="@(IntermediateAssembly)" Condition="Exists('@(IntermediateAssembly)')">
			<Output TaskParameter="Include" ItemName="FileWrites"/>
		</CreateItem>

		<CreateItem Include="$(IntermediateOutputPath)$(AssemblyName)$(TargetExt).mdb"
			Condition="Exists('$(IntermediateOutputPath)$(AssemblyName)$(TargetExt).mdb')">
			<Output TaskParameter="Include" ItemName="FileWrites"/>
		</CreateItem>

		<CreateItem Include="$(IntermediateOutputPath)$(AssemblyName).pdb"
			Condition="Exists('$(IntermediateOutputPath)$(AssemblyName).pdb')">
			<Output TaskParameter="Include" ItemName="FileWrites"/>
		</CreateItem>
	</Target>

	<!-- Get the list of files written, for clean -->
	<Target Name="_GetCleanFileWrites"
		DependsOnTargets="_GetCompileOutputsForClean">
		<ReadLinesFromFile File="$(IntermediateOutputPath)$(CleanFile)">
			<Output TaskParameter="Lines" ItemName="PreviousFileWrites"/>
		</ReadLinesFromFile>
	</Target>

	<Target Name="CleanReferencedProjects"
		DependsOnTargets="AssignProjectConfiguration">

		<!-- If building from .sln.proj or from IDE, clean will get handled by them,
		     else we are building a project directly, from the command line, so
		     clean the referenced projects -->
		<MSBuild Projects="@(ProjectReferenceWithConfigurationExistent)"
			Targets="Clean"
			Condition=" '$(BuildingSolutionFile)' != 'true' and '$(BuildingInsideVisualStudio)' != 'true' and '@(ProjectReferenceWithConfigurationExistent)' != ''" />

	</Target>

	<Target Name="Clean" DependsOnTargets="$(CleanDependsOn)"/>

	<!-- Override in project to run before/after clean tasks -->
	<Target Name="BeforeClean" />
	<Target Name="AfterClean" />

	<Target Name="CoreClean" DependsOnTargets="_GetCleanFileWrites">
		<Delete Files="@(PreviousFileWrites);@(FileWrites)" TreatErrorsAsWarnings="true"/>

		<!-- all previous files written for this platform/config have been deleted,
		     we can safely remove the file list now -->
		<Delete Files="$(IntermediateOutputPath)$(CleanFile)" TreatErrorsAsWarnings="true" />
	</Target>

	<PropertyGroup>
		<ImplicitlyExpandDesignTimeFacades>true</ImplicitlyExpandDesignTimeFacades>

		<ResolveReferencesDependsOn>
			$(ResolveReferencesDependsOn);
			ImplicitlyExpandDesignTimeFacades
		</ResolveReferencesDependsOn>

		<ImplicitlyExpandDesignTimeFacadesDependsOn>
			$(ImplicitlyExpandDesignTimeFacadesDependsOn);
			GetReferenceAssemblyPaths
		</ImplicitlyExpandDesignTimeFacadesDependsOn>
	</PropertyGroup>

	<Target Name="ImplicitlyExpandDesignTimeFacades" Condition="'$(ImplicitlyExpandDesignTimeFacades)' == 'true'" DependsOnTargets="$(ImplicitlyExpandDesignTimeFacadesDependsOn)">

		<PropertyGroup>
			<_HasReferenceToSystemRuntime Condition="'%(_ResolvedDependencyFiles.Filename)' == 'System.Runtime'">true</_HasReferenceToSystemRuntime>
		</PropertyGroup>

		<ItemGroup Condition="'$(_HasReferenceToSystemRuntime)' == 'true'">
			<!-- If the user has manually referenced these assemblies, remove them so we don't end up with duplicates -->
			<ReferencePath Remove="@(_DesignTimeFacadeAssemblies)"/>
			<ReferencePath Include="%(_DesignTimeFacadeAssemblies.Identity)">
				<WinMDFile>false</WinMDFile>
				<CopyLocal>false</CopyLocal>
				<ResolvedFrom>ImplicitlyExpandDesignTimeFacades</ResolvedFrom>
			</ReferencePath>
			<_ResolveAssemblyReferenceResolvedFiles Include="@(ReferencePath)" Condition="'%(ReferencePath.ResolvedFrom)' == 'ImplicitlyExpandDesignTimeFacades'" />
		</ItemGroup>

		<Message Importance="Low" Text="Including @(ReferencePath)" Condition="'%(ReferencePath.ResolvedFrom)' == 'ImplicitlyExpandDesignTimeFacades'" />

	</Target>

	<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\$(MSBuildThisFile)\ImportAfter\*"
		Condition="'$(ImportByWildcardAfterMicrosoftCommonTargets)' == 'true' and Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\$(MSBuildThisFile)\ImportAfter')"/>
</Project>
