<!--
***********************************************************************************************
Microsoft.Portable.Core.targets

Contains common targets that are shared by all portable library projects regardless of version.

WARNING:  DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
          created a backup copy.  Incorrect changes to this file will make it
          impossible to load or build your projects from the command-line or the IDE.

Copyright (C) Microsoft Corporation. All rights reserved.
***********************************************************************************************
-->

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <Import Project="VisualStudio\v$(VisualStudioVersion)\Microsoft.Portable.CurrentVersion.targets" Condition="Exists('VisualStudio\v$(VisualStudioVersion)\Microsoft.Portable.CurrentVersion.targets')"/>

    <Target Name="_CheckForInvalidTargetFrameworkProfile"
            AfterTargets="_CheckForInvalidConfigurationAndPlatform">

        <Error Condition="'$(TargetFrameworkProfile)' == '' AND '$(PortableNuGetMode)' != 'true'" Text="The TargetFrameworkProfile property is not set for project '$(MSBuildProjectFile)'. Portable projects must specify a profile."/>

    </Target>

    <!-- 
        To prevent framework assembly references from being unified to the ones in the full 
        framework (for example, System.Net.Primitives, v3.9.0.0 -> System.Net.Primitives, v4.0.0.0), 
        we set the full framework folder to the profile folder so that RAR thinks that the 
        profile itself is the full framework. Given that we don't actually use our full framework,
        we do not need any of the warnings from RAR that are turned off because of this.
    -->
    <Target Name="_SetFullFrameworkFolderToProfile"
            AfterTargets="GetReferenceAssemblyPaths">

        <PropertyGroup>
            <_FullFrameworkReferenceAssemblyPaths>$(TargetFrameworkDirectory)</_FullFrameworkReferenceAssemblyPaths>
        </PropertyGroup>
    </Target>

    <PropertyGroup>
        <ResolveReferencesDependsOn>
            $(ResolveReferencesDependsOn);
            ImplicitlyExpandTargetFramework;
        </ResolveReferencesDependsOn>

        <ImplicitlyExpandTargetFrameworkDependsOn>
            $(ImplicitlyExpandTargetFrameworkDependsOn);
            GetReferenceAssemblyPaths
        </ImplicitlyExpandTargetFrameworkDependsOn>

    </PropertyGroup>

    <!--
        The ImplicitlyExpandTargetFramework target will expand all 
        of the dll reference assemblies in the TargetFrameworkDirectory 
        for the project and place the items into the ReferencePath itemgroup 
        which contains resolved items.
    -->

    <Target Name="ImplicitlyExpandTargetFramework"
        Condition="'$(ImplicitlyExpandTargetFramework)' == 'true'"
        DependsOnTargets="$(ImplicitlyExpandTargetFrameworkDependsOn)"
    >
        <ItemGroup>
            <ReferenceAssemblyPaths Include="$(_TargetFrameworkDirectories)"/>
            <ReferencePath Include="%(ReferenceAssemblyPaths.Identity)*.dll">
                <WinMDFile>false</WinMDFile>
                <CopyLocal>false</CopyLocal>
                <ReferenceGroupingDisplayName>.NET</ReferenceGroupingDisplayName>
                <ReferenceGrouping>$(TargetFrameworkIdentifier),$(TargetFrameworkVersion)</ReferenceGrouping>
                <ResolvedFrom>ImplicitlyExpandTargetFramework</ResolvedFrom>
                <IsSystemReference>True</IsSystemReference>
            </ReferencePath>
        </ItemGroup>

        <Message Importance="Low" Text="TargetMonikerDisplayName: $(TargetFrameworkMonikerDisplayName) ReferenceAssemblyPaths: @(ReferenceAssemblyPaths)"/>

        <Message Importance="Low" Text="Including @(ReferencePath)"
          Condition="'%(ReferencePath.ResolvedFrom)' == 'ImplicitlyExpandTargetFramework'"/>

        <ItemGroup>
            <_ResolveAssemblyReferenceResolvedFiles Include="@(ReferencePath)"
              Condition="'%(ReferencePath.ResolvedFrom)' == 'ImplicitlyExpandTargetFramework'"/>
        </ItemGroup>
    </Target>

</Project>
