<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.tasks" />

  <PropertyGroup>
    <VersionPrefix>$(CliVersionPrefix)</VersionPrefix>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <RuntimeFrameworkVersion>$(CLI_SharedFrameworkVersion)</RuntimeFrameworkVersion>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
    <PublishDir>$(RoslynDirectory)</PublishDir>
    <VersionSuffix>$(CommitCount)</VersionSuffix>
  </PropertyGroup>
  
  <ItemGroup>
    <PackageReference Include="Microsoft.NetCore.App" Version="$(CLI_SharedFrameworkVersion)" />
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(CLI_Roslyn_Version)" />
    <PackageReference Include="Microsoft.CodeAnalysis.Build.Tasks" Version="$(CLI_Roslyn_Version)" />
    <PackageReference Include="Microsoft.Net.Compilers.netcore" Version="$(CLI_Roslyn_Version)" />
    <PackageReference Include="Microsoft.DiaSymReader.Native" Version="1.4.1" />
  </ItemGroup>

  <ItemGroup>
    <Content Include="RunCsc.sh;RunCsc.cmd">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </Content>
  </ItemGroup>

  <Target Name="MakeCscRunnableAndMoveToPublishDir"
          AfterTargets="Publish"
          BeforeTargets="RemoveFilesAfterPublish">
    <ItemGroup>
      <AssetsToRemoveFromDeps Include="runtimes/any/native/csc.exe" 
                              SectionName="runtimeTargets" />
      <AssetsToRemoveFromDeps Include="runtimes/any/native/vbc.exe" 
                              SectionName="runtimeTargets" />
      <AssetsToRemoveFromDeps Include="tool_roslyn.dll" 
                              SectionName="runtime"/>
    </ItemGroup>
    
    <RemoveAssetFromDepsPackages DepsFile="$(PublishDir)/$(TargetName).deps.json"
                                 SectionName="%(AssetsToRemoveFromDeps.SectionName)"
                                 AssetPath="%(AssetsToRemoveFromDeps.Identity)" />
   
    <Copy SourceFiles="$(PublishDir)/runtimes/any/native/csc.exe;
                       $(PublishDir)/$(TargetName).runtimeconfig.json;
                       $(PublishDir)/$(TargetName).deps.json;"
          DestinationFiles="$(PublishDir)/csc.exe;
                            $(PublishDir)/csc.runtimeconfig.json;
                            $(PublishDir)/csc.deps.json;" />
  </Target>

  <Target Name="RemoveFilesAfterPublish"
          AfterTargets="Publish">
    <Delete Files="$(PublishDir)/$(TargetName).dll" />
    <Delete Files="$(PublishDir)/$(TargetName).pdb" />
    <Delete Files="$(PublishDir)/$(TargetName).runtimeconfig.json" />
    <Delete Files="$(PublishDir)/$(TargetName).deps.json" />
  </Target>
</Project>
