<?xml version="1.0" encoding="utf-8" ?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">

	<!-- GENERAL -->

	<Target Name="Echo">
		<Message Text="Hello from $(MSBuildProjectDirectory)" />
	</Target>

	<PropertyGroup>
		<RootFolder>$(MSBuildProjectDirectory)\..</RootFolder>
		<Version Condition="'$(Version)' == ''">2.0</Version>
		<DeployPrefix>nop_$(Version)</DeployPrefix>
		<DeployFolder>$(RootFolder)\Deployable</DeployFolder>
        <PluginsFolder>$(RootFolder)\Plugins</PluginsFolder>
        <WebFolder>$(RootFolder)\Presentation\Nop.Web</WebFolder>
        <WebPluginsFolder>$(WebFolder)\Plugins</WebPluginsFolder>
		<Configuration Condition="'$(Configuration)' == ''">Release</Configuration>
		<Platform Condition="'$(Platform)' == ''">Any CPU</Platform>
		<Platform Condition="'$(Platform)' == 'MCD'">Any CPU</Platform>
		<MSBuildCommunityTasksPath>$(RootFolder)\lib</MSBuildCommunityTasksPath>
	</PropertyGroup>

	<Import Project="$(RootFolder)\build\lib\MSBuild.Community.Tasks.targets"/>
	<Import Project="nop.framework.targets"/>
    <Import Project="nop.plugins.targets"/>

	<Target Name="Build">
		<Message Text="Building Everything"/>
		<CallTarget Targets="Framework-Build"/>
        <CallTarget Targets="Plugins-CopyToWeb"/>
	</Target>

    <Target Name="Deploy" DependsOnTargets="Build">
        <!--Lets delete the old deployed files-->
        <RemoveDir Directories="$(DeployFolder)" />
        <MakeDir Directories="$(DeployFolder)" />
        <MakeDir Directories="$(DeployFolder)\$(DeployPrefix)" />

        <!--Lets publish Nop.Web-->
        <MSBuild Projects="$(RootFolder)\Presentation\Nop.Web\Nop.Web.csproj"
           Targets="ResolveReferences;_CopyWebApplication"
           Properties="WebProjectOutputDir=$(DeployFolder)\$(DeployPrefix)\;
           OutDir=$(DeployFolder)\$(DeployPrefix)\bin\" />
        
        <!--Lets copy the plugins to the deployed directory-->
        <MSBuild Projects ="$(MSBuildProjectFullPath)"
                        Targets="Plugins-CopyToWeb"
                        Properties="
                        PluginOutput=$(DeployFolder)\$(DeployPrefix)\Plugins\"/>
        
        <!--Now lets publish Nop.Admin-->
        <MSBuild Projects="$(RootFolder)\Presentation\Nop.Web\Administration\Nop.Admin.csproj"
           Targets="ResolveReferences;_CopyWebApplication"
           Properties="WebProjectOutputDir=$(DeployFolder)\$(DeployPrefix)\Administration\;
           OutDir=$(DeployFolder)\$(DeployPrefix)\Administration\bin\" />

        <!--Now lets move the Nop.Admin/bin/ to the root bin/-->
        <CreateItem Include="$(DeployFolder)\$(DeployPrefix)\Administration\bin\*.dll">
            <Output TaskParameter="Include" ItemName="CompileOutput" />
        </CreateItem>
        <Copy SourceFiles="@(CompileOutput)"
                DestinationFolder="$(DeployFolder)\$(DeployPrefix)\bin\" />


        <!--Lets move the deployable-bin directory to the /bin-->
        <CreateItem Include="$(RootFolder)\Presentation\Nop.Web\_bin_deployableAssemblies\**\*.dll">
            <Output TaskParameter="Include" ItemName="deployableAssemblies" />
        </CreateItem>
        <Copy SourceFiles="@(deployableAssemblies)"
                DestinationFolder="$(DeployFolder)\$(DeployPrefix)\bin\%(RecursiveDir)" />

        <!--Lets delete the bin in Nop.Admin-->
        <RemoveDir Directories="$(DeployFolder)\$(DeployPrefix)\Administration\bin\" />
        
        <!--Lets delete the packages.config files-->
        <Delete  Files="$(DeployFolder)\$(DeployPrefix)\Administration\packages.config;
                 $(DeployFolder)\$(DeployPrefix)\packages.config"/>
    </Target>

</Project>