<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
	<UsingTask TaskName="Zip" AssemblyFile="$(MSBuildThisFileDirectory)target\nuget\packages\$(MSBuildTasksPackageId).$(MSBuildTasksPackageVersion)\tools\MSBuild.Community.Tasks.dll"/>
	<PropertyGroup>
		<Configuration Condition="'$(Configuration)' == ''">Release</Configuration>
		<BuildRoot>$(MSBuildThisFileDirectory)</BuildRoot>
		<NuGetExe>$(BuildRoot)target\nuget\nuget.exe</NuGetExe>
		<MSBuildTasksPackageId>MSBuildTasks</MSBuildTasksPackageId>
		<MSBuildTasksPackageVersion>1.5.0.214</MSBuildTasksPackageVersion>
	</PropertyGroup>
	<ItemGroup>
		<VisualStudioVersion Include="2012">
			<SolutionFile>$(MSBuildThisFileDirectory)..\src\Renci.SshNet.VS2012.sln</SolutionFile>
			<MSBuildToolsVersion>14.0</MSBuildToolsVersion>
			<NuGetPackageRestore>true</NuGetPackageRestore>
		</VisualStudioVersion>
		<VisualStudioVersion Include="2015">
			<SolutionFile>$(MSBuildThisFileDirectory)..\src\Renci.SshNet.VS2015.sln</SolutionFile>
			<MSBuildToolsVersion>14.0</MSBuildToolsVersion>
			<NuGetPackageRestore>true</NuGetPackageRestore>
		</VisualStudioVersion>
		<VisualStudioVersion Include="2017">
			<SolutionFile>$(MSBuildThisFileDirectory)..\src\Renci.SshNet.VS2017.sln</SolutionFile>
			<MSBuildToolsVersion>15.0</MSBuildToolsVersion>
		</VisualStudioVersion>
	</ItemGroup>
	<ItemGroup>
		<TargetFramework Include=".NET Framework 3.5">
			<OutputDirectory>Renci.SshNet.NET35\bin\$(Configuration)</OutputDirectory>
			<Moniker>net35</Moniker>
		</TargetFramework>
		<TargetFramework Include=".NET Framework 4.0">
			<OutputDirectory>Renci.SshNet\bin\$(Configuration)</OutputDirectory>
			<Moniker>net40</Moniker>
		</TargetFramework>
		<TargetFramework Include=".NETStandard 1.3">
			<OutputDirectory>Renci.SshNet.NETCore\bin\$(Configuration)\netstandard1.3</OutputDirectory>
			<Moniker>netstandard1.3</Moniker>
		</TargetFramework>
		<TargetFramework Include="Windows Phone Silverlight 7.1">
			<OutputDirectory>Renci.SshNet.WindowsPhone\bin\$(Configuration)</OutputDirectory>
			<Moniker>wp71</Moniker>
		</TargetFramework>
		<TargetFramework Include="Windows Phone Silverlight 8.0">
			<OutputDirectory>Renci.SshNet.WindowsPhone8\bin\$(Configuration)</OutputDirectory>
			<Moniker>wp8</Moniker>
		</TargetFramework>
		<TargetFramework Include="Silverlight 4">
			<OutputDirectory>Renci.SshNet.Silverlight\bin\$(Configuration)</OutputDirectory>
			<Moniker>sl4</Moniker>
		</TargetFramework>
		<TargetFramework Include="Silverlight 5">
			<OutputDirectory>Renci.SshNet.Silverlight5\bin\$(Configuration)</OutputDirectory>
			<Moniker>sl5</Moniker>
		</TargetFramework>
		<TargetFramework Include="Universal Windows Platform 10">
			<OutputDirectory>Renci.SshNet.UAP10\bin\$(Configuration)</OutputDirectory>
			<Moniker>uap10</Moniker>
		</TargetFramework>
	</ItemGroup>
	<Target Name="Clean">
		<RemoveDir Directories="$(MSBuildThisFileDirectory)target"/>
		<ItemGroup>
			<ProjectToBuild Remove="@(ProjectToBuild)"/>
			<ProjectToBuild Include="%(VisualStudioVersion.SolutionFile)" Condition="'%(VisualStudioVersion.MSBuildToolsVersion)'=='$(MSBuildToolsVersion)'">
				<Properties>Configuration=Release</Properties>
			</ProjectToBuild>
		</ItemGroup>
		<MSBuild Projects="@(ProjectToBuild)" Targets="Clean" />
	</Target>
	<Target Name="DownloadNuGet">
		<MakeDir Directories="$(MSBuildThisFileDirectory)target\nuget"/>
		<DownloadFile
			Address="https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
			FileName="$(MSBuildThisFileDirectory)target\nuget\nuget.exe"/>
	</Target>
	<Target Name="RestoreNuGetPackages" DependsOnTargets="DownloadNuGet" Outputs="%(VisualStudioVersion.Identity)">
		<Message Text="Restoring nuget packages for '%(VisualStudioVersion.SolutionFile)'..." Importance="High" Condition="'%(VisualStudioVersion.MSBuildToolsVersion)'=='$(MSBuildToolsVersion)' and '%(VisualStudioVersion.NuGetPackageRestore)'=='true'"/>
		<Exec Command="$(NuGetExe) restore &quot;%(VisualStudioVersion.SolutionFile)&quot;" Condition="'%(VisualStudioVersion.MSBuildToolsVersion)'=='$(MSBuildToolsVersion)' and '%(VisualStudioVersion.NuGetPackageRestore)'=='true'"/>
	</Target>
	<Target Name="Build" DependsOnTargets="RestoreNuGetPackages" Outputs="%(VisualStudioVersion.Identity)">
		<ItemGroup>
			<ProjectToBuild Remove="@(ProjectToBuild)"/>
			<ProjectToBuild Include="%(VisualStudioVersion.SolutionFile)" Condition="'%(VisualStudioVersion.MSBuildToolsVersion)'=='$(MSBuildToolsVersion)'">
				<Properties>Configuration=Release</Properties>
			</ProjectToBuild>
		</ItemGroup>
		<MSBuild Projects="@(ProjectToBuild)" Targets="Rebuild"/>
	</Target>
	<Target Name="Package" DependsOnTargets="CreateNuGetPackage;CreateBinPackage;GenerateHelpFile"/>
	<Target Name="CreateNuGetPackage" DependsOnTargets="CopyBuildOutputToPackage">
		<Exec Command="$(NuGetExe) pack $(MSBuildThisFileDirectory)nuget\SSH.NET.nuspec -OutputDirectory &quot;$(MSBuildThisFileDirectory)target&quot; -BasePath &quot;$(MSBuildThisFileDirectory)target\package&quot; -NonInteractive"/>
	</Target>
	<Target Name="CopyBuildOutputToPackage" Outputs="%(TargetFramework.Identity)">
		<ItemGroup>
			<BuildOutput Remove="@(BuildOutput)"/>
			<BuildOutput Include="$(MSBuildThisFileDirectory)..\src\%(TargetFramework.OutputDirectory)\Renci.SshNet.dll"/>
			<BuildOutput Include="$(MSBuildThisFileDirectory)..\src\%(TargetFramework.OutputDirectory)\Renci.SshNet.xml"/>
		</ItemGroup>
		<Copy SourceFiles="@(BuildOutput)" DestinationFolder="$(MSBuildThisFileDirectory)target\package\lib\%(TargetFramework.Moniker)"/>
	</Target>
	<Target Name="GenerateHelpFile" DependsOnTargets="CheckReleaseVersion">
		<Error Text="Please install Sandcastle, and ensure the SHFBFolder environment variable is set." Condition="'$(SHFBFolder)'==''"/>
		<MSBuild Projects="$(MSBuildThisFileDirectory)sandcastle\SSH.NET.shfbproj"/>
		<Move SourceFiles="$(MSBuildThisFileDirectory)target\help\SshNet.Help.chm" DestinationFiles="$(MSBuildThisFileDirectory)target\SSH.NET-$(ReleaseVersion)-help.chm"/>
	</Target>
	<Target Name="CopyBuildOutputToBin" Outputs="%(TargetFramework.Identity)">
		<ItemGroup>
			<BuildOutput Remove="@(BuildOutput)"/>
			<BuildOutput Include="$(MSBuildThisFileDirectory)..\src\%(TargetFramework.OutputDirectory)\*.dll"/>
			<BuildOutput Include="$(MSBuildThisFileDirectory)..\src\%(TargetFramework.OutputDirectory)\*.xml"/>
		</ItemGroup>
		<Copy SourceFiles="@(BuildOutput)" DestinationFolder="$(MSBuildThisFileDirectory)target\bin\lib\%(TargetFramework.Moniker)"/>
	</Target>
	<Target Name="CreateBinPackage" DependsOnTargets="PrepareMSBuildTasksPackage;CopyBuildOutputToBin;CheckReleaseVersion">
		<ItemGroup>
			<Files Remove="@(Files)"/>
			<Files Include="$(MSBuildThisFileDirectory)..\LICENSE"/>
		</ItemGroup>
		<Copy SourceFiles="@(Files)" DestinationFolder="$(MSBuildThisFileDirectory)target\bin\%(RecursiveDir)"/>
		<ItemGroup>
			<Files Remove="@(Files)"/>
			<Files Include="$(MSBuildThisFileDirectory)target\bin\**"/>
		</ItemGroup>
		<Zip ZipFileName="$(MSBuildThisFileDirectory)target\SSH.NET-$(ReleaseVersion)-bin.zip" Files="@(Files)" WorkingDirectory="$(MSBuildThisFileDirectory)target\bin"/>
	</Target>
	<Target Name="PrepareMSBuildTasksPackage" DependsOnTargets="DownloadNuGet">
		<Exec Command="$(NuGetExe) install $(MSBuildTasksPackageId) -Version $(MSBuildTasksPackageVersion) -OutputDirectory &quot;$(MSBuildThisFileDirectory)target\nuget\packages&quot; -Verbosity quiet"/>
	</Target>
	<Target Name="CheckReleaseVersion" Condition="'$(ReleaseVersion)'==''">
		<Error Text= "Please specify the version number of the release (using the &quot;ReleaseVersion&quot; property)."/>
	</Target>
	<UsingTask TaskName="DownloadFile" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
		<ParameterGroup>
			<Address ParameterType="System.String" Required="true"/>
			<FileName ParameterType="System.String" Required="true" />
		</ParameterGroup>
		<Task>
			<Reference Include="System" />
			<Code Type="Fragment" Language="cs">
				<![CDATA[
					new System.Net.WebClient().DownloadFile(Address, FileName);
				]]>
			</Code>
		</Task>
	</UsingTask>
</Project>