<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="SetupDebProps"
          DependsOnTargets="Init;
                            CalculateLinuxNativeInstallerDependencyVersions">
    <!-- dotnet deb-tool -->
    <PropertyGroup>
      <DotnetDebToolDir>$(MSBuildThisFileDirectory)/dotnet-deb-tool-consumer</DotnetDebToolDir>
      <PackageTool>$(NuGetPackagesDir)/dotnet-deb-tool/$(DotnetDebToolVersion)/lib/netcoreapp2.0/tool/package_tool</PackageTool>
    </PropertyGroup>

    <!-- constants -->
    <PropertyGroup>
      <DebianInstalledDirectory>/usr/share/dotnet</DebianInstalledDirectory>

      <LayoutPackageRootDirName>package_root</LayoutPackageRootDirName>
      <LayoutAbsolutePlacementDirName>$</LayoutAbsolutePlacementDirName>
      <LayoutSamplesDirName>samples</LayoutSamplesDirName>
      <LayoutDocsDirName>docs</LayoutDocsDirName>
      <LayoutDebianFilesDirName>debian</LayoutDebianFilesDirName>
    </PropertyGroup>

    <!-- Package Identities -->
    <PropertyGroup>
      <RuntimeDepsPackageVersion>$(MicrosoftNETCoreAppMajorMinorVersion)</RuntimeDepsPackageVersion>
      <RuntimeDepsPackageName>dotnet-runtime-deps-$(RuntimeDepsPackageVersion)</RuntimeDepsPackageName>
      <SdkDebianPackageVersion>$(MajorMinorVersion)</SdkDebianPackageVersion>
      <SdkDebianPackageName>dotnet-sdk-$(SdkDebianPackageVersion)</SdkDebianPackageName>
      <SharedFxDebianPackageFileVersion>$(MicrosoftNETCoreAppPackageVersion)</SharedFxDebianPackageFileVersion>
      <SharedFxDebianPackageVersion>$(MicrosoftNETCoreAppMajorMinorVersion)</SharedFxDebianPackageVersion>
      <SharedFxDebianPackageFileName>dotnet-runtime-$(SharedFxDebianPackageFileVersion)</SharedFxDebianPackageFileName>
      <SharedFxDebianPackageFileName>$(SharedFxDebianPackageFileName.ToLower())</SharedFxDebianPackageFileName>
      <SharedFxDebianPackageName>dotnet-runtime-$(SharedFxDebianPackageVersion)</SharedFxDebianPackageName>
      <SharedFxDebianPackageName>$(SharedFxDebianPackageName.ToLower())</SharedFxDebianPackageName>
      <HostFxrDebianPackageFileName>dotnet-hostfxr-$(HostFxrVersion)</HostFxrDebianPackageFileName>
      <HostFxrDebianPackageFileName>$(HostFxrDebianPackageFileName.ToLower())</HostFxrDebianPackageFileName>
      <HostFxrDebianPackageName>dotnet-hostfxr-$(HostFxrMajorMinorVersion)</HostFxrDebianPackageName>
      <HostFxrDebianPackageName>$(HostFxrDebianPackageName.ToLower())</HostFxrDebianPackageName>
      <HostDebianPackageName>dotnet-host</HostDebianPackageName>
      <AspNetCoreSharedFxDebianPackageFileName>aspnetcore-runtime-$(AspNetCoreVersion)</AspNetCoreSharedFxDebianPackageFileName>
      <AspNetCoreSharedFxDebianPackageFileName>$(AspNetCoreSharedFxDebianPackageFileName.ToLower())</AspNetCoreSharedFxDebianPackageFileName>
      <AspNetCoreSharedFxDebianPackageName>aspnetcore-runtime-$(AspNetCoreMajorMinorVersion)</AspNetCoreSharedFxDebianPackageName>
      <AspNetCoreSharedFxDebianPackageName>$(AspNetCoreSharedFxDebianPackageName.ToLower())</AspNetCoreSharedFxDebianPackageName>
    </PropertyGroup>

    <!-- Inputs -->
    <PropertyGroup>
      <ManpagesDirectory>$(RepoRoot)/Documentation/manpages</ManpagesDirectory>
      <EndToEndTestProject>$(RepoRoot)/test/EndToEnd/EndToEnd.csproj</EndToEndTestProject>
      <CLISdkRoot>$(OutputDirectory)/sdk</CLISdkRoot>
    </PropertyGroup>

    <ItemGroup>
      <CLISdkFiles Include="$(CLISdkRoot)/**/*" />
      <SdkDebManPageFiles Include="$(ManpagesDirectory)/**/*" />
    </ItemGroup>

    <!-- Output Directories -->
    <PropertyGroup>
      <InstallerOutputDirectory>$(PackagesDirectory)</InstallerOutputDirectory>
      <SdkInstallerFile>$(InstallerOutputDirectory)/$(DistroSpecificArtifactNameWithVersionCombinedHostHostFxrFrameworkSdk)$(InstallerExtension)</SdkInstallerFile>
      <SdkDebianIntermediateDirectory>$(IntermediateDirectory)/debian/sdk</SdkDebianIntermediateDirectory>
      <DotNetDebToolOutputDirectory>$(SdkDebianIntermediateDirectory)/deb-tool-output</DotNetDebToolOutputDirectory>
      <DebianTestResultsXmlFile>$(SdkDebianIntermediateDirectory)/debian-testResults.xml</DebianTestResultsXmlFile>
    </PropertyGroup>

    <!-- Layout Directories -->
    <PropertyGroup>
      <LayoutDirectory>$(SdkDebianIntermediateDirectory)/debianLayoutDirectory</LayoutDirectory>
      <LayoutPackageRootDir>$(LayoutDirectory)/$(LayoutPackageRootDirName)</LayoutPackageRootDir>
      <LayoutAbsolutePlacementDir>$(LayoutDirectory)/$(LayoutAbsolutePlacementDirName)</LayoutAbsolutePlacementDir>
      <LayoutSamplesDir>$(LayoutDirectory)/$(LayoutSamplesDirName)</LayoutSamplesDir>
      <LayoutDocsDir>$(LayoutDirectory)/$(LayoutDocsDirName)</LayoutDocsDir>
      <LayoutDebianFilesDir>$(LayoutDirectory)/$(LayoutDebianFilesDirName)</LayoutDebianFilesDir>
    </PropertyGroup>

    <!-- debian_config.json -->
    <PropertyGroup>
      <DebianConfigTemplateFile>$(RepoRoot)/packaging/deb/dotnet-debian_config.json</DebianConfigTemplateFile>
      <DebianConfigJsonFile>$(LayoutDirectory)/debian_config.json</DebianConfigJsonFile>
    </PropertyGroup>

    <PropertyGroup>
      <DebianPostinstTemplateFile>$(RepoRoot)/packaging/deb/postinst</DebianPostinstTemplateFile>
      <DebianPostinstFile>$(LayoutDirectory)/debian/postinst</DebianPostinstFile>
    </PropertyGroup>

    <ItemGroup>
      <DebianConfigTokenValues Include="%SHARED_FRAMEWORK_DEBIAN_PACKAGE_NAME%">
        <ReplacementString>$(SharedFxDebianPackageName)</ReplacementString>
      </DebianConfigTokenValues>
      <DebianConfigTokenValues Include="%ASPNETCORE_SHAREDFX_DEBIAN_PACKAGE_NAME%">
        <ReplacementString>$(AspNetCoreSharedFxDebianPackageName)</ReplacementString>
      </DebianConfigTokenValues>
      <DebianConfigTokenValues Include="%SHARED_FRAMEWORK_DEBIAN_PACKAGE_ADDITIONAL_DEPENDENCY%"
                               Condition="'$(IncludeAdditionalSharedFrameworks)' == 'true'">
        <ReplacementString>,
        "$(AdditionalSharedFxDebianPackageName)" : {}</ReplacementString>
      </DebianConfigTokenValues>
      <DebianConfigTokenValues Include="%SHARED_FRAMEWORK_DEBIAN_PACKAGE_ADDITIONAL_DEPENDENCY%"
                               Condition="'$(IncludeAdditionalSharedFrameworks)' != 'true'">
        <ReplacementString></ReplacementString>
      </DebianConfigTokenValues>
      <DebianConfigTokenValues Include="%SDK_NUGET_VERSION%">
        <ReplacementString>$(MajorMinorVersion)</ReplacementString>
      </DebianConfigTokenValues>
      <DebianConfigTokenValues Include="%CLI_SDK_BRAND_NAME%">
        <ReplacementString>$(SdkBrandName)</ReplacementString>
      </DebianConfigTokenValues>
      <DebianConfigTokenValues Include="%SHARED_FRAMEWORK_DEBIAN_PACKAGE_VERSIONS%">
        <ReplacementString>$(MicrosoftNETCoreAppPackageVersionWithTilda)</ReplacementString>
      </DebianConfigTokenValues>
      <DebianConfigTokenValues Include="%ASPNETCORE_SHAREDFX_DEBIAN_PACKAGE_VERSION%">
        <ReplacementString>$(AspNetCoreVersionWithTilda)</ReplacementString>
      </DebianConfigTokenValues>

      <DebianPostInstTokenValues Include="%SDK_VERSION%">
        <ReplacementString>$(SdkVersion)</ReplacementString>
      </DebianPostInstTokenValues>
    </ItemGroup>

    <ItemGroup>
      <TestSdkDebTaskEnvironmentVariables Include="PATH=$(DebianInstalledDirectory)$(PathListSeparator)$(PATH)" />
      <TestSdkDebTaskEnvironmentVariables Include="TEST_ARTIFACTS=$(TestArtifactsDir)" />
      <TestSdkDebTaskEnvironmentVariables Include="TEST_PACKAGES=$(TestPackagesDir)" />
      <TestSdkDebTaskEnvironmentVariables Include="PreviousStageProps=$(NextStagePropsPath)" />

      <!-- Consumed By Publish -->
      <GeneratedInstallers Include="$(SdkInstallerFile)" />
    </ItemGroup>
  </Target>
</Project>
