<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
	<!-- Properties that must be set for these targets to function:
	        $(BranchName): The name of the branch being built.  Used to determine the web subdirectory for publishing.
          
          For creating web sites:
          $(PublishDocsWebSiteName): The name of the web site under which the documentation web applications will be created/deleted.

          For creating or publishing to web sites:
	        $(DocWebRoot): the full physical path to where documentation should be copied to, excluding $(BranchName)
	-->
	<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.props))\EnlistmentInfo.props" Condition=" '$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.props))' != '' " />
	<Import Project="..\tools\DotNetOpenAuth.automated.props"/>
	
	<Target Name="Build" DependsOnTargets="BuildUnifiedProduct;Chm" Condition=" '$(NoDocumentation)' != 'true' " />

	<Target Name="Prepare">
		<Error Text="The BranchName property must be set." Condition=" '$(BranchName)' == '' " />
		<Error Text="The DocWebRoot property must be set." Condition=" '$(DocWebRoot)' == '' " />
		<PropertyGroup>
			<PublishDocsWebSiteVirtualPath>/$(BranchName)</PublishDocsWebSiteVirtualPath>
		</PropertyGroup>
	</Target>
	
	<Target Name="PrepareForPublish" DependsOnTargets="BuildProduct;Html">
		<PropertyGroup>
			<DocZip>$(DropDirectoryNoSlash)-htmldoc$(ZipFormat)</DocZip>
		</PropertyGroup>

		<ItemGroup>
			<DocSources Include="$(ProjectRoot)doc\api\**\*" />
		</ItemGroup>
	</Target>

	<Target Name="DeployableArchive"
					DependsOnTargets="PrepareForPublish"
					Inputs="@(DocSources)"
					Outputs="$(DocZip)">
		<Delete Files="$(DocZip)" />
		<AddFilesTo7Zip
			Files="@(DocSources)"
			ZipFileName="$(DocZip)"
			WorkingDirectory="$(ProjectRoot)doc\api\"
			ToolPath="$(Zip7ToolPath)" />
	</Target>

	<Target Name="Publish"
					DependsOnTargets="DeployableArchive" />

	<Target Name="CreateSiteOnIis" DependsOnTargets="Prepare">
		<Error Text="The PublishDocsWebSiteName property must be set." Condition=" '$(PublishDocsWebSiteName)' == '' "/>
		<CreateWebApplication
			WebSiteName="$(PublishDocsWebSiteName)"
			PhysicalPaths="$(DocWebRoot)\$(BranchName)"
			VirtualPaths="$(PublishDocsWebSiteVirtualPath)"
			/>
	</Target>

	<Target Name="DeleteSiteOnIis" DependsOnTargets="Prepare">
		<Error Text="The PublishDocsWebSiteName property must be set." Condition=" '$(PublishDocsWebSiteName)' == '' "/>
		<DeleteWebApplication
			WebSiteName="$(PublishDocsWebSiteName)"
			VirtualPaths="$(PublishDocsWebSiteVirtualPath)"
			/>
	</Target>

	<Import Project="$(ProjectRoot)tools\Documentation.targets"/>
	<Import Project="$(ProjectRoot)tools\DotNetOpenAuth.automated.targets"/>
	<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.targets))\EnlistmentInfo.targets" Condition=" '$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.targets))' != '' " />
</Project>