<Project Sdk="Microsoft.Build.NoTargets">
    <PropertyGroup>
        <TargetFramework>$(SdkTargetFramework)</TargetFramework>
        <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
        <IsPackable>true</IsPackable>
        <IsShipping>true</IsShipping>
        <IsShippingPackage>true</IsShippingPackage>
        <NoWarn>NU5100;NU5128</NoWarn>
        <VSCompatTargetFramework>net472</VSCompatTargetFramework>

        <!-- MSBuild tasks shouldn't be referenced. This is by design. -->
        <NoWarn>NU5100;NU5128;NU1507</NoWarn>
        <Authors>Microsoft</Authors>
        <Company>Microsoft</Company>
        <PackageId>Microsoft.NET.Build.Containers</PackageId>
        <Description>Tasks and targets to natively publish .NET applications as containers.</Description>
        <Copyright>&#169; Microsoft Corporation. All rights reserved.</Copyright>
        <PackageLicenseExpression>MIT</PackageLicenseExpression>
        <PackageProjectUrl>https://github.com/dotnet/sdk-container-builds</PackageProjectUrl>
        <RepositoryUrl>https://github.com/dotnet/sdk-container-builds</RepositoryUrl>
        <RepositoryType>git</RepositoryType>
        <PackageTags>containers;docker;Microsoft.NET.Build.Containers</PackageTags>
        <PackageReadmeFile>README.md</PackageReadmeFile>
    </PropertyGroup>

    <ItemGroup>
        <ProjectReference Include="../Microsoft.NET.Build.Containers/Microsoft.NET.Build.Containers.csproj"
                          SetTargetFramework="TargetFramework=$(TargetFramework)"
                          OutputItemType="ContainerLibraryOutput"/>

        <ProjectReference Include="../../Cli/Microsoft.DotNet.Cli.Utils/Microsoft.DotNet.Cli.Utils.csproj"
                          SetTargetFramework="TargetFramework=$(ResolverTargetFramework)"
                          OutputItemType="DotNetCliUtilsLibraryOutput"/>

        <ProjectReference Include="../Microsoft.NET.Build.Containers/Microsoft.NET.Build.Containers.csproj"
                          SetTargetFramework="TargetFramework=$(VSCompatTargetFramework)"
                          OutputItemType="ContainerLibraryOutputNet472" Condition="'$(DotNetBuildSourceOnly)' != 'true'" />

        <ProjectReference Include="../containerize/containerize.csproj" PrivateAssets="all" IncludeAssets="runtime" ReferenceOutputAssembly="true" Condition="'$(DotNetBuildSourceOnly)' != 'true'" />
    </ItemGroup>

    <Target Name="PreparePackageReleaseNotesFromFile" BeforeTargets="GenerateNuspec">
        <PropertyGroup>
            <PackageReleaseNotesFile>../docs/ReleaseNotes/v8.0.300.md</PackageReleaseNotesFile>
            <PackageReleaseNotes>$([System.IO.File]::ReadAllText($(PackageReleaseNotesFile)))</PackageReleaseNotes>
        </PropertyGroup>
    </Target>

    <Target Name="AddItemsForPackaging" AfterTargets="Build">
        <MSBuild Projects="../Microsoft.NET.Build.Containers/Microsoft.NET.Build.Containers.csproj" Properties="TargetFramework=$(VSCompatTargetFramework)" Targets="ResolveAssemblyReferences" Condition="'$(DotNetBuildSourceOnly)' != 'true'">
            <Output TaskParameter="TargetOutputs" ItemName="_AllNet472ContainerTaskDependencies" />
        </MSBuild>
        <ItemGroup Condition="'$(DotNetBuildSourceOnly)' != 'true'">
            <NecessaryNet472ContainerTaskDependencies Include="@(_AllNet472ContainerTaskDependencies)" Condition="(
                                $([MSBuild]::ValueOrDefault('%(_AllNet472ContainerTaskDependencies.NuGetPackageId)', '').Contains('NuGet')) or
                                $([MSBuild]::ValueOrDefault('%(_AllNet472ContainerTaskDependencies.NuGetPackageId)', '').Contains('Newtonsoft')) or
                                $([MSBuild]::ValueOrDefault('%(_AllNet472ContainerTaskDependencies.NuGetPackageId)', '').Contains('Microsoft.Extensions'))
                            ) and
                            %(_AllNet472ContainerTaskDependencies.NuGetIsFrameworkReference) != true" />
            
            <!-- containerize folder -->
            <Content Include="$(OutDir)containerize.dll" Pack="true" PackagePath="containerize/" />
            <Content Include="$(OutDir)containerize.runtimeconfig.json" Pack="true" PackagePath="containerize/" />
            <Content Include="$(OutDir)Newtonsoft.Json.dll" Pack="true" PackagePath="containerize/" />
            <Content Include="$(OutDir)NuGet.*.dll" Pack="true" PackagePath="containerize/" />
            <Content Include="$(OutDir)Microsoft.DotNet.Cli.Utils.dll" Pack="true" PackagePath="containerize/" />
            <Content Include="$(OutDir)System.CommandLine.dll" Pack="true" PackagePath="containerize/" />
            <Content Include="$(OutDir)Valleysoft.DockerCredsProvider.dll" Pack="true" PackagePath="containerize/" />
            <Content Include="$(OutDir)Microsoft.Extensions.*.dll" Pack="true" PackagePath="containerize/" />
            <Content Include="@(ContainerLibraryOutput)" Pack="true" PackagePath="containerize/" />

            <!-- net472 tasks -->
            <!-- dependencies -->
            <Content Include="@(NecessaryNet472ContainerTaskDependencies)" Pack="true" PackagePath="tasks/$(VSCompatTargetFramework)/" />
            <!-- actual DLL  -->
            <Content Include="@(ContainerLibraryOutputNet472)" Pack="true" PackagePath="tasks/$(VSCompatTargetFramework)/" />
        </ItemGroup>
        <MSBuild Projects="../Microsoft.NET.Build.Containers/Microsoft.NET.Build.Containers.csproj" Properties="TargetFramework=$(TargetFramework)" Targets="ResolveAssemblyReferences">
            <Output TaskParameter="TargetOutputs" ItemName="_AllNetContainerTaskDependencies" />
        </MSBuild>
        <ItemGroup>
             <NecessaryNetContainerTaskDependencies Include="@(_AllNetContainerTaskDependencies)" Condition="(
                                $([MSBuild]::ValueOrDefault('%(_AllNetContainerTaskDependencies.NuGetPackageId)', '').Contains('NuGet')) or
                                $([MSBuild]::ValueOrDefault('%(_AllNetContainerTaskDependencies.NuGetPackageId)', '').Contains('Newtonsoft')) or
                                $([MSBuild]::ValueOrDefault('%(_AllNetContainerTaskDependencies.NuGetPackageId)', '').Contains('Valleysoft')) or
                                $([MSBuild]::ValueOrDefault('%(_AllNetContainerTaskDependencies.NuGetPackageId)', '').Contains('Microsoft.Extensions'))
                            ) and
                            %(_AllNetContainerTaskDependencies.NuGetIsFrameworkReference) != true" />

            <!-- root folder -->
            <Content Include="README.md" Pack="true" PackagePath="" />

            <!-- tasks folder -->
            <!-- net7.0 tasks -->
            <!-- dependencies -->
            <Content Include="@(NecessaryNetContainerTaskDependencies)" Pack="true" PackagePath="tasks/$(TargetFramework)/" />
            <Content Include="@(DotNetCliUtilsLibraryOutput)" Pack="true" PackagePath="tasks/$(TargetFramework)/" />

            <!-- runtime deps json -->
            <Content Include="$(ArtifactsDir)bin/Microsoft.NET.Build.Containers/$(Configuration)/$(TargetFramework)/Microsoft.NET.Build.Containers.deps.json" Pack="true" PackagePath="tasks/$(TargetFramework)" />
            <!-- actual DLL  -->
            <Content Include="@(ContainerLibraryOutput)" Pack="true" PackagePath="tasks/$(TargetFramework)/" />

            <!-- build folder -->
            <Content Include="build/**" Pack="true" PackagePath="build/" />
        </ItemGroup>
    </Target>

    <!-- Hacky workaround for the fact that we don't publish the package yet. -->
    <Target Name="CopyNupkgToCustomFolder" AfterTargets="Pack">
        <Copy SourceFiles="$(ArtifactsDir)packages/$(Configuration)/Shipping/Microsoft.NET.Build.Containers.$(Version).nupkg"
            DestinationFiles="$(ArtifactsTmpDir)Container/package/Microsoft.NET.Build.Containers.$(Version).nupkg" />
    </Target>

    <!-- Copy files that are needed by Integration tests. -->
    <Target Name="CopyPropsAndTargets" AfterTargets="Pack">
      <Copy SourceFiles="./build/Microsoft.NET.Build.Containers.props"
          DestinationFiles="$(ArtifactsTmpDir)Container/packaging/Microsoft.NET.Build.Containers.props" />
      <Copy SourceFiles="./build/Microsoft.NET.Build.Containers.targets"
          DestinationFiles="$(ArtifactsTmpDir)Container/packaging/Microsoft.NET.Build.Containers.targets" />
    </Target>
</Project>
