<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Go" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="$(MSBuildProjectDirectory)\Build.tasks" />

    <!-- Setup configuration variables -->
    <PropertyGroup>
        <Configuration Condition="'$(OS)' == 'Windows_NT' And '$(Configuration)' == ''">Debug</Configuration>
        <Configuration Condition="'$(OS)' != 'Windows_NT' And '$(Configuration)' == ''">Mono Debug</Configuration>
        <ConfigFolderPath>$(Configuration)</ConfigFolderPath>
        <ConfigFolderPath Condition="'$(Configuration)' == 'Mono Debug'">Debug</ConfigFolderPath>
        <ConfigFolderPath Condition="'$(Configuration)' == 'Mono Release'">Release</ConfigFolderPath>
    </PropertyGroup>

    <!-- Set MonoBuild to true so we can distinguish building for mono -->
    <PropertyGroup Condition=" '$(Configuration)' == 'Mono Debug' Or '$(Configuration)' == 'Mono Release' Or '$(OS)' != 'Windows_NT'">
        <MonoBuild>true</MonoBuild>
    </PropertyGroup>

    <PropertyGroup>
        <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
        <NuGetRoot>$(MSBuildProjectDirectory)\..</NuGetRoot>
        <NuGetTestRoot>$(NuGetRoot)\test</NuGetTestRoot>
        <NuGetSrcRoot>$(NuGetRoot)\src</NuGetSrcRoot>
        <DropDirectory>$(NuGetRoot)\bin</DropDirectory>
        <ArtifactDropDirectory>$(DropDirectory)\artifacts</ArtifactDropDirectory>
        <NuGetDropDirectory>$(DropDirectory)\NuGet</NuGetDropDirectory>
        <ExeBuildDirectory>$(NuGetSrcRoot)\CommandLine\bin\$(ConfigFolderPath)</ExeBuildDirectory>
        <ExeDropDirectory>$(NuGetDropDirectory)\Console</ExeDropDirectory>
        <ServerExtensionsBuildDirectory>$(NuGetSrcRoot)\CommandLine.ServerExtensions\bin\$(ConfigFolderPath)</ServerExtensionsBuildDirectory>
        <ServerExtensionsDropDirectory>$(NuGetDropDirectory)\CommandLine.ServerExtensions</ServerExtensionsDropDirectory>
        <VisualStudioAddInBuildDirectory>$(NuGetSrcRoot)\VsExtension\bin\$(ConfigFolderPath)</VisualStudioAddInBuildDirectory>
        <VisualStudioAddInDropDirectory>$(NuGetDropDirectory)\VisualStudioAddIn</VisualStudioAddInDropDirectory>
        <EndToEndTestsDirectory>$(NuGetTestRoot)\EndToEnd</EndToEndTestsDirectory>
        <EndToEndTestsDropDirectory>$(NuGetDropDirectory)\EndToEnd\Artifacts</EndToEndTestsDropDirectory>
        <ServerBuildDirectory>$(NuGetSrcRoot)\Server</ServerBuildDirectory>
        <ServerDropDirectory>$(NuGetDropDirectory)\Server</ServerDropDirectory>
        <NuGetCoreBuildDirectory>$(NuGetSrcRoot)\Core</NuGetCoreBuildDirectory>
        <NuGetCoreDropDirectory>$(NuGetDropDirectory)\Core</NuGetCoreDropDirectory>
        <NuGetBuildDropDirectory>$(NuGetDropDirectory)\Build</NuGetBuildDropDirectory>
        <NuGetVisualStudioBuildDirectory>$(NuGetSrcRoot)\VisualStudio</NuGetVisualStudioBuildDirectory>
        <NuGetVisualStudioDropDirectory>$(NuGetDropDirectory)\VisualStudio</NuGetVisualStudioDropDirectory>
        <GenerateTestPackageProjectDirectory>$(NuGetRoot)\Tools\NuGet\GenerateTestPackages</GenerateTestPackageProjectDirectory>
        <GenerateTestPackageExe>$(GenerateTestPackageProjectDirectory)\bin\$(ConfigFolderPath)\GenerateTestPackages.exe</GenerateTestPackageExe>
        <ZipExe>$(NuGetRoot)\Tools\7za920\7za.exe</ZipExe>
        <ILMergeExe>$(NuGetRoot)\Tools\ILMerge\ILMerge.exe</ILMergeExe>
        <ILMergeArtifactDirectory>$(ArtifactDropDirectory)\ILMerge</ILMergeArtifactDirectory>
        <ILMergeInternalizeIgnoreFile>$(NuGetRoot)\Build\ilmerge.internalize.ignore.txt</ILMergeInternalizeIgnoreFile>
    </PropertyGroup>

    <PropertyGroup>
        <!-- Specifiy the NuGet release version. When make changes here, please also change the version numbers
             in Common\CommonAssemblyInfo.cs so the version numbers are consistent between binaries built on
             build servers and those built locally. -->
        <MajorVersion>2</MajorVersion>
        <MinorVersion>14</MinorVersion>
        <Patch>0</Patch>
        <Revision>$(BUILD_NUMBER)</Revision>

        <!-- This is the file version of the DLLs/EXE produced. It's also the version of the vsix -->
        <Version>$(MajorVersion).$(MinorVersion).$(Patch).$(Revision)</Version>

        <PrereleaseTag Condition=" '$(PrereleaseTag)' == '' "></PrereleaseTag>

        <!-- This is the version number of nupkg files produced. vsix -->
        <PackageVersion>$(MajorVersion).$(MinorVersion).$(Patch)</PackageVersion>
        <PackageVersion Condition="'$(PrereleaseTag)' != ''">$(PackageVersion)-$(PrereleaseTag)</PackageVersion>
    </PropertyGroup>

    <PropertyGroup>
        <!-- Team City under-reports tests when they're run in parallel. We'll specifically disable it in there -->
        <BuildTestsInParallel Condition=" '$(TEAMCITY_VERSION)' == '' ">true</BuildTestsInParallel>
        <BuildTestsInParallel Condition=" '$(TEAMCITY_VERSION)' != '' ">false</BuildTestsInParallel>
    </PropertyGroup>

    <ItemGroup>
        <RegexTransform Include="$(NuGetSrcRoot)\VsExtension\*.vsixmanifest">
            <Find><![CDATA[<Version>\d+\.\d+\.\d+\.\d+</Version>]]></Find>
            <ReplaceWith><![CDATA[<Version>$(Version)</Version>]]></ReplaceWith>
        </RegexTransform>
        <RegexTransform Include="$(NuGetSrcRoot)\VsExtension\*.vsixmanifest">
            <Find><![CDATA[<AllUsers>false</AllUsers>]]></Find>
            <ReplaceWith><![CDATA[<AllUsers>true</AllUsers>]]></ReplaceWith>
        </RegexTransform>
        <RegexTransform Include="$(NuGetRoot)\Common\CommonAssemblyInfo.cs">
            <Find>AssemblyVersion\("\d+\.\d+\.\d+\.\d+"\)</Find>
            <ReplaceWith>AssemblyVersion("$(Version)")</ReplaceWith>
        </RegexTransform>
        <RegexTransform Include="$(NuGetRoot)\Common\CommonAssemblyInfo.cs">
            <Find>AssemblyInformationalVersion\("\d+\.\d+\.\d+"\)</Find>
            <ReplaceWith>AssemblyInformationalVersion("$(PackageVersion)")</ReplaceWith>
        </RegexTransform>
        <RegexTransform Include="$(NuGetSrcRoot)\VsConsole\PowerShellHost\Scripts\nuget.psd1">
            <Find><![CDATA[ModuleVersion = '\d+\.\d+\.\d+\.\d+']]></Find>
            <ReplaceWith><![CDATA[ModuleVersion = '$(Version)']]></ReplaceWith>
        </RegexTransform>
        <RegexTransform Include="$(NuGetSrcRoot)\VsExtension\NuGetPackage.cs">
            <Find><![CDATA[ProductVersion = "\d+\.\d+\.\d+\.\d+"]]></Find>
            <ReplaceWith><![CDATA[ProductVersion = "$(Version)"]]></ReplaceWith>
        </RegexTransform>
        <RegexTransform Include="$(NuGetSrcRoot)\**\*.nuspec">
            <Find><![CDATA[<version>\d+\.\d+\.\d+\.\d+</version>]]></Find>
            <ReplaceWith><![CDATA[<version>$(PackageVersion)</version>]]></ReplaceWith>
        </RegexTransform>
    </ItemGroup>

    <ItemGroup>
        <TestProjects Include="$(NuGetTestRoot)\CommandLine.Test\CommandLine.Test.csproj" Condition="'$(MonoBuild)' == ''" />
        <TestProjects Include="$(NuGetTestRoot)\Core.Test\Core.Test.csproj" Condition="'$(MonoBuild)' == ''" />
        <TestProjects Include="$(NuGetTestRoot)\Server.Test\Server.Test.csproj" Condition="'$(MonoBuild)' == ''" />
        <TestProjects Include="$(NuGetTestRoot)\Dialog.Test\Dialog.Test.csproj" Condition="'$(MonoBuild)' == ''" />
        <TestProjects Include="$(NuGetTestRoot)\VisualStudio.Test\VisualStudio.Test.csproj" Condition="'$(MonoBuild)' == ''" />
        <TestProjects Include="$(NuGetTestRoot)\VisualStudio11.Test\VisualStudio11.Test.csproj"
                      Condition="'$(MonoBuild)' == '' and $(VisualStudioVersion) != '10.0'" />
        <TestProjects Include="$(NuGetTestRoot)\PowerShellCmdlets.Test\PowerShellCmdlets.Test.csproj" Condition="'$(MonoBuild)' == ''" />
        <TestProjects Include="$(NuGetTestRoot)\PowerShellHost.Test\PowerShellHost.Test.csproj" Condition="'$(MonoBuild)' == ''" />
        <TestProjects Include="$(NuGetTestRoot)\TeamFoundationServer.Test\TeamFoundationServer.Test.csproj" Condition="'$(MonoBuild)' == ''" />
        <TestProjects Include="$(NuGetTestRoot)\Test.Integration\Test.Integration.csproj" Condition="'$(MonoBuild)' == ''" />
    </ItemGroup>

    <ItemGroup>
        <MonoProjects Include="$(NuGetSrcRoot)\Core\Core.csproj"/>
        <MonoProjects Include="$(NuGetSrcRoot)\CommandLine\CommandLine.csproj"/>
        <MonoProjects Include="@(TestProjects)" />
    </ItemGroup>

    <Target Name="Go"
        DependsOnTargets="CheckFxCop; UpdateVsixVersion; RestorePackages; Build; ReportFxCopResults;
                                    VerifyAssembliesInVsix; RunTests; CreateDropDirectories; CopyExecutableOutputToDropDirectory;
                                    CopyServerExtensionsOutputToDropDirectory;
                                    CopyVisualStudioAddInOutputToDropDirectory; CopyEndToEndTestsToDropDirectory;
                                    CopyServerOutputToDropDirectory; CopyLicenseToAllDirectories; BuildPackages">
    </Target>

    <Target Name="GoMono" DependsOnTargets="RestorePackages; BuildMono; RunTests" />
    <Target Name="GoMonoNoTests" DependsOnTargets="RestorePackages; BuildMono" />

    <Target Name="CheckFxCop">
        <Error
            Condition="!Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\CodeAnalysis\fxcoptask.dll') And !Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v11.0\CodeAnalysis\fxcoptask.dll') And !Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v12.0\CodeAnalysis\fxcoptask.dll') And !Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v14.0\CodeAnalysis\fxcoptask.dll')"
            Text="FxCop not found at $(MSBuildExtensionsPath)\Microsoft\VisualStudio\[v10.0|v11.0|v12.0|v14.0]\CodeAnalysis\fxcoptask.dll. Cannot proceed." />
    </Target>

    <!-- Task to update the vsix and DLLs/EXE. This task is run only when BUILD_NUMBER exists, which is
         the case on CI. -->
    <Target Name="UpdateVsixVersion" Condition="'$(BUILD_NUMBER)' != ''">
        <RegexTransform Items="@(RegexTransform)" />
    </Target>

    <Target Name="RestorePackages">
        <MsBuild Projects="$(NuGetRoot)\src\Core\Core.csproj"
                 Targets="Build"
                 Properties="DefineConstants=IS_NET40_CLIENT;NUGET_FRAMEWORKS_INTERNAL;CODE_ANALYSIS" />
        <MsBuild Projects="$(NuGetRoot)\src\CommandLine\CommandLine.csproj"
                 Targets="Build"
                 Properties="DefineConstants=CODE_ANALYSIS" />

        <PropertyGroup>
            <PackageSources>https://www.nuget.org/api/v2/</PackageSources>
        </PropertyGroup>

        <Message Text="Restoring NuGet packages" Importance="High" />
        <Exec Command="&quot;$(ExeBuildDirectory)\NuGet.exe&quot; restore -source &quot;$(PackageSources)&quot;" WorkingDirectory="$(NuGetRoot)" Condition="'$(MonoBuild)' == ''" />
        <Exec Command="mono $(ExeBuildDirectory)\NuGet.exe restore -source &quot;$(PackageSources)&quot;" WorkingDirectory="$(NuGetRoot)" Condition="'$(MonoBuild)' == 'true'"/>
    </Target>

    <Target Name="Build">
        <PropertyGroup>
            <EnableCodeAnalysis Condition="'$(EnableCodeAnalysis)' == ''" >true</EnableCodeAnalysis>
        </PropertyGroup>
        <MSBuild Projects="$(NuGetRoot)\NuGet.sln" Targets="Build" Properties="EnableCodeAnalysis=$(EnableCodeAnalysis);DeployExtension=false" />
    </Target>

    <Target Name="BuildMono">
        <MSBuild Projects="@(MonoProjects)"
                 Targets="Build" />
    </Target>

    <Target Name="VerifyAssembliesInVSIX">
        <PropertyGroup>
            <VsixFileLocation>$(VisualStudioAddInBuildDirectory)\NuGet.Tools.vsix</VsixFileLocation>
            <TempVsixDirectory>$(DropDirectory)\Temp</TempVsixDirectory>
        </PropertyGroup>

        <RemoveDir Directories="$(TempVsixDirectory)" Condition="Exists($(TempVsixDirectory))" />

        <Exec Command="&quot;$(ZipExe)&quot; x -o&quot;$(TempVsixDirectory)&quot; &quot;$(VsixFileLocation)&quot;" />

        <ItemGroup>
            <VsixAssemblies Include="$(TempVsixDirectory)\*.dll" />
        </ItemGroup>

        <CheckUnexpectedAssemblies Items="@(VsixAssemblies)">
            <Output TaskParameter="InvalidItems" ItemName="InvalidFiles" />
        </CheckUnexpectedAssemblies>

        <ItemGroup Condition=" $(VisualStudioVersion) == '14.0' ">
            <UnwantedAssembly Include="$(TempVsixDirectory)\NuGet.VisualStudio10.dll" />
            <UnwantedAssembly Include="$(TempVsixDirectory)\NuGet.VisualStudio12.dll" />
        </ItemGroup>

        <ItemGroup Condition=" $(VisualStudioVersion) == '12.0' ">
            <UnwantedAssembly Include="$(TempVsixDirectory)\NuGet.Dialog10.dll" />
            <UnwantedAssembly Include="$(TempVsixDirectory)\NuGet.Dialog11.dll"></UnwantedAssembly>
            <UnwantedAssembly Include="$(TempVsixDirectory)\NuGet.VisualStudio10.dll"></UnwantedAssembly>
            <UnwantedAssembly Include="$(TempVsixDirectory)\NuGet.VisualStudio14.dll" />
            <UnwantedAssembly Include="$(TempVsixDirectory)\NuGet.TeamFoundationServer10.dll"></UnwantedAssembly>
            <UnwantedAssembly Include="$(TempVsixDirectory)\NuGet.TeamFoundationServer11.dll"></UnwantedAssembly>
        </ItemGroup>

        <ItemGroup Condition=" $(VisualStudioVersion) == '11.0' or $(VisualStudioVersion) == '10.0' ">
            <UnwantedAssembly Include="$(TempVsixDirectory)\NuGet.Dialog.dll"></UnwantedAssembly>
            <UnwantedAssembly Include="$(TempVsixDirectory)\NuGet.VisualStudio12.dll"></UnwantedAssembly>
            <UnwantedAssembly Include="$(TempVsixDirectory)\NuGet.VisualStudio14.dll" />
            <UnwantedAssembly Include="$(TempVsixDirectory)\NuGet.TeamFoundationServer.dll"></UnwantedAssembly>
        </ItemGroup>

        <Delete Files="@(InvalidFiles)" />
        <Delete Files="@(UnwantedAssembly)" />

        <Exec Command="&quot;$(ZipExe)&quot; a -r &quot;$(VisualStudioAddInBuildDirectory)\NuGet.Tools.zip&quot; &quot;$(TempVsixDirectory)\*.*&quot;" />

        <Delete Files="$(VsixFileLocation)" />
        <Move SourceFiles="$(VisualStudioAddInBuildDirectory)\NuGet.Tools.zip" DestinationFiles="$(VisualStudioAddInBuildDirectory)\NuGet.Tools.vsix" />

        <RemoveDir Directories="$(TempVsixDirectory)" ContinueOnError="true" />
    </Target>

    <Target Name="RunTests" Condition=" '$(DisableRunningUnitTests)' != 'true' ">
        <MsBuild Projects="@(TestProjects)"
                 Targets="RunTests"
                 BuildInParallel="$(BuildTestsInParallel)" />
    </Target>

    <Target Name="ReportFxCopResults">
        <ItemGroup>
            <FxCopOutputItems Include="$(NuGetRoot)\**\*.dll.CodeAnalysisLog.xml" />
        </ItemGroup>
        <Message Text="##teamcity[importData type='FxCop' path='%(FxCopOutputItems.Identity)']" />
    </Target>

    <Target Name="CreateDropDirectories">
        <Message Text="Making the output directories for the compiled output at '$(DropDirectory)'." />
        <RemoveDir Directories="$(DropDirectory)" Condition="Exists('$(DropDirectory)')" ContinueOnError="True" />
        <MakeDir Directories="$(DropDirectory)" Condition="!Exists('$(DropDirectory)')" />
        <MakeDir Directories="$(ArtifactDropDirectory)" Condition="!Exists('$(ArtifactDropDirectory)')" />
        <MakeDir Directories="$(NuGetDropDirectory)" Condition="!Exists('$(NuGetDropDirectory)')" />
        <MakeDir Directories="$(ExeDropDirectory)" Condition="!Exists('$(ExeDropDirectory)')" />
        <MakeDir Directories="$(ExeDropDirectory)\Signed" Condition="!Exists('$(ExeDropDirectory)\Signed')" />
        <MakeDir Directories="$(VisualStudioAddInDropDirectory)" Condition="!Exists('$(VisualStudioAddInDropDirectory)')" />
        <MakeDir Directories="$(ServerDropDirectory)" Condition="!Exists('$(ServerDropDirectory)')" />
        <MakeDir Directories="$(NuGetCoreDropDirectory)" Condition="!Exists('$(NuGetCoreDropDirectory)')" />
        <MakeDir Directories="$(NuGetVisualStudioDropDirectory)" Condition="!Exists('$(NuGetVisualStudioDropDirectory)')" />
        <MakeDir Directories="$(ExtensionsDropDirectory)" Condition="!Exists('$(ExtensionsDropDirectory)')" />
        <MakeDir Directories="$(ServerExtensionsBuildDirectory)" Condition="!Exists('$(ServerExtensionsBuildDirectory)')" />
        <MakeDir Directories="$(NuGetBuildDropDirectory)" Condition="!Exists('$(NuGetBuildDropDirectory)')" />
    </Target>

    <Target Name="CopyExecutableOutputToDropDirectory">
        <ItemGroup>
            <ExecutableFiles Include="$(ExeBuildDirectory)\Merged\NuGet.exe;$(ExeBuildDirectory)\Merged\NuGet.pdb;$(NuGetSrcRoot)\CommandLine\Properties\*.nuspec" />
        </ItemGroup>
        <Message Text="Copying the NuGet Console output to $(ExeDropDirectory)" />
        <Copy ContinueOnError="false" SourceFiles="@(ExecutableFiles)" DestinationFolder="$(ExeDropDirectory)" />
        <Copy Condition="Exists('$(ExeBuildDirectory)\Signed\NuGet.exe')" ContinueOnError="false" SourceFiles="$(ExeBuildDirectory)\Signed\NuGet.exe;$(ExeBuildDirectory)\Signed\NuGet.pdb" DestinationFolder="$(ExeDropDirectory)\Signed" />
    </Target>

    <Target Name="CopyServerExtensionsOutputToDropDirectory">
        <Message Text="Rebuilding server extensions" />
        <MSBuild Projects="$(NuGetSrcRoot)\CommandLine.ServerExtensions\CommandLine.ServerExtensions.csproj" Properties="CIBuild=true;SignAssembly=false" Targets="Clean;Build" />
        <!-- Since this is an extension, it needs to be compiled against the IL Merged nuget.exe. So we rebuild it with the magic flag that tells it to be compiled -->
        <ItemGroup>
            <ServerExtensionsOutputItems Include="$(ServerExtensionsBuildDirectory)\NuGet.ServerExtensions.dll" />
        </ItemGroup>

        <Message Text="Copying Server extensions output from $(ServerExtensionsBuildDirectory) to $(ServerExtensionsDropDirectory): @(ServerExtensionsOutputItems) " />
        <Copy ContinueOnError="false"
              SourceFiles="@(ServerExtensionsOutputItems)"
              DestinationFolder="$(ServerExtensionsDropDirectory)" />

        <!-- Delete the source file for good measure -->
        <Delete Files="@(ServerExtensionsOutputItems)" />
        <!-- also delete the output file in obj folder so that it won't interfere with the next build -->
        <Delete Files="$(NuGetSrcRoot)\CommandLine.ServerExtensions\obj\$(ConfigFolderPath)\NuGet.ServerExtensions.dll" />
    </Target>

    <Target Name="CopyVisualStudioAddInOutputToDropDirectory">
        <ItemGroup>
            <VisualStudioAddInOutputItems Include="$(VisualStudioAddInBuildDirectory)\**\*.vsix" />
            <VisualStudioAddInOutputItems Include="$(VisualStudioAddInBuildDirectory)\**\NuGet.VisualStudio.dll" />
            <VisualStudioAddInOutputItems Include="$(VisualStudioAddInBuildDirectory)\**\NuGet.VisualStudio.pdb" />
            <VisualStudioAddInOutputItems Include="$(VisualStudioAddInBuildDirectory)\**\NuGet.VisualStudio.Interop.dll" />
            <VisualStudioAddInOutputItems Include="$(VisualStudioAddInBuildDirectory)\**\NuGet.VisualStudio.Interop.pdb" />
            <VisualStudioAddInOutputItems Include="$(VisualStudioAddInBuildDirectory)\**\NuGetConsole.Host.PowerShell.dll" />
            <VisualStudioAddInOutputItems Include="$(VisualStudioAddInBuildDirectory)\**\NuGetConsole.Host.PowerShell.pdb" />
            <VisualStudioAddInOutputItems Include="$(VisualStudioAddInBuildDirectory)\**\NuGetConsole.Host.PowerShellProvider.dll" />
            <VisualStudioAddInOutputItems Include="$(VisualStudioAddInBuildDirectory)\**\NuGetConsole.Host.PowerShellProvider.pdb" />
        </ItemGroup>
        <Message Text="Copying the NuGet Visual Studio Add-In output to $(VisualStudioAddInDropDirectory)" />
        <Copy ContinueOnError="false" SourceFiles="@(VisualStudioAddInOutputItems)" DestinationFiles="@(VisualStudioAddInOutputItems ->'$(VisualStudioAddInDropDirectory)\%(RecursiveDir)%(Filename)%(Extension)')" />
    </Target>

    <Target Name="CopyEndToEndTestsToDropDirectory" Condition=" '$(ProduceEndToEndTest)' == 'true' ">
        <ItemGroup>
            <EndToEndTestItems Include="$(EndToEndTestsDirectory)\**\*.*" />
            <EndToEndTestItems Remove="$(EndToEndTestsDirectory)\bin\**\*.*" />
        </ItemGroup>

        <Copy ContinueOnError="false" SourceFiles="@(EndToEndTestItems)" DestinationFiles="@(EndToEndTestItems ->'$(EndToEndTestsDropDirectory)\%(RecursiveDir)%(Filename)%(Extension)')" />

        <Message Text="Zipping the EndToEnd directory..." Importance="high" />
        <Exec Command="&quot;$(ZipExe)&quot; a ..\EndToEnd.zip" WorkingDirectory="$(EndToEndTestsDropDirectory)" />
    </Target>

    <Target Name="CopyServerOutputToDropDirectory">
        <ItemGroup>
            <ServerOutputItems Include="$(ServerBuildDirectory)\**\*.*" Exclude="$(ServerBuildDirectory)\**\*.cs;$(ServerBuildDirectory)\**\*.csp*;$(ServerBuildDirectory)\obj\**\*.*;$(ServerBuildDirectory)\Packages\**\*.*;$(ServerBuildDirectory)\App_Data\**"/>
        </ItemGroup>
        <Message Text="Copying the NuGet Server output to $(ServerDropDirectory)" />
        <Copy ContinueOnError="false" SourceFiles="@(ServerOutputItems)" DestinationFiles="@(ServerOutputItems ->'$(ServerDropDirectory)\www\%(RecursiveDir)%(Filename)%(Extension)')" />
        <Exec Command="&quot;$(ZipExe)&quot; a ..\server.zip" WorkingDirectory="$(ServerDropDirectory)\www" />
        <RemoveDir Directories="$(ServerDropDirectory)\www" />
    </Target>

    <Target Name="CopyLicenseToAllDirectories">
        <ItemGroup>
            <LicenseFileItems Include="$(MSBuildProjectDirectory)\..\LICENSE.txt" />
        </ItemGroup>
        <Message Text="Copying the License to all drop directories" />
        <Copy ContinueOnError="false" SourceFiles="@(LicenseFileItems)" DestinationFiles="@(LicenseFileItems -&gt;'$(ExeDropDirectory)\%(RecursiveDir)%(Filename)%(Extension)')" />
        <Copy ContinueOnError="false" SourceFiles="@(LicenseFileItems)" DestinationFiles="@(LicenseFileItems -&gt;'$(VisualStudioAddInDropDirectory)\%(RecursiveDir)%(Filename)%(Extension)')" />
        <Copy ContinueOnError="false" SourceFiles="@(LicenseFileItems)" DestinationFiles="@(LicenseFileItems -&gt;'$(ServerDropDirectory)\%(RecursiveDir)%(Filename)%(Extension)')" />
    </Target>

    <Target Name="BuildPackages" Condition="$(VisualStudioVersion)=='10.0' Or $(VisualStudioVersion) == '11.0' ">
        <PropertyGroup>
            <NuGetExe>$(ExeDropDirectory)\NuGet.exe</NuGetExe>
        </PropertyGroup>

        <Exec Command="&quot;$(NuGetExe)&quot; pack NuGet.CommandLine.nuspec -NoPackageAnalysis -Version $(PackageVersion)" WorkingDirectory="$(ExeDropDirectory)" />
        <Exec Command="&quot;$(NuGetExe)&quot; pack -NoPackageAnalysis -Version $(PackageVersion) -o &quot;$(ServerDropDirectory)&quot; -Build -p AdditionalSettingsImport=$(AdditionalSettingsImport) -p Configuration=Release -Symbols -exclude **\NuGet.Core.*" WorkingDirectory="$(ServerBuildDirectory)" />
        <Exec Command="&quot;$(NuGetExe)&quot; pack -NoPackageAnalysis -Version $(PackageVersion) -o &quot;$(NuGetCoreDropDirectory)&quot; -Build -Symbols -p AdditionalSettingsImport=$(AdditionalSettingsImport)" WorkingDirectory="$(NuGetCoreBuildDirectory)" />
        <Exec Command="&quot;$(NuGetExe)&quot; pack -NoPackageAnalysis -Version $(PackageVersion) -o &quot;$(NuGetBuildDropDirectory)&quot;" WorkingDirectory="$(NuGetSrcRoot)\Build" />
        <Exec Command="&quot;$(NuGetExe)&quot; pack -NoPackageAnalysis -Version $(PackageVersion) -o &quot;$(NuGetVisualStudioDropDirectory)&quot; -Build -p AdditionalSettingsImport=$(AdditionalSettingsImport) -p Configuration=Release -exclude **\NuGet.Core.*" WorkingDirectory="$(NuGetVisualStudioBuildDirectory)" />
    </Target>

    <Target Name="BuildPackages" Condition="$(VisualStudioVersion)=='12.0' ">
        <PropertyGroup>
            <NuGetExe>$(ExeDropDirectory)\NuGet.exe</NuGetExe>
        </PropertyGroup>

        <Exec Command="&quot;$(NuGetExe)&quot; pack NuGet.CommandLine.nuspec -NoPackageAnalysis -Version $(PackageVersion)" WorkingDirectory="$(ExeDropDirectory)" />
        <Exec Command="&quot;$(NuGetExe)&quot; pack -NoPackageAnalysis -Version $(PackageVersion) -o &quot;$(NuGetCoreDropDirectory)&quot; -Build -Symbols -p AdditionalSettingsImport=$(AdditionalSettingsImport)" WorkingDirectory="$(NuGetCoreBuildDirectory)" />
        <Exec Command="&quot;$(NuGetExe)&quot; pack -NoPackageAnalysis -Version $(PackageVersion) -o &quot;$(NuGetBuildDropDirectory)&quot;" WorkingDirectory="$(NuGetSrcRoot)\Build" />
    </Target>
</Project>
