<Project Sdk="Microsoft.NET.Sdk">
  <Import Project="$(RepoRoot)\src\Layout\redist\targets\PublishDotnetWatch.targets" />

  <PropertyGroup>
    <TargetFramework>$(SdkTargetFramework)</TargetFramework>
    <OutputType>exe</OutputType>
    <Description>Command line tool to watch for source file changes during development and restart the dotnet command.</Description>
    <RootNamespace>Microsoft.DotNet.Watcher.Tools</RootNamespace>
    <StrongNameKeyId>MicrosoftAspNetCore</StrongNameKeyId>
    <UseAppHost>false</UseAppHost>
    <RuntimeIdentifier />
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="..\..\Common\EnvironmentVariableNames.cs" Link="Common\EnvironmentVariableNames.cs" />
  </ItemGroup>

  <ItemGroup>
    <EmbeddedResource Update="**\*.resx" GenerateSource="true" />
    <Content Include="DotNetWatch.targets" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
  </ItemGroup>

  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="System.CommandLine" />
    <PackageReference Include="Microsoft.Build" ExcludeAssets="runtime" PrivateAssets="All" />
    <PackageReference Include="Microsoft.Build.Framework" ExcludeAssets="runtime" PrivateAssets="All" />
    <PackageReference Include="Microsoft.Build.Tasks.Core" ExcludeAssets="runtime" PrivateAssets="All" />
    <PackageReference Include="Microsoft.Build.Utilities.Core" ExcludeAssets="runtime" PrivateAssets="All" />
    <PackageReference Include="Microsoft.Build.Locator" />
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Features" />
    <PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" />
    <PackageReference Include="Microsoft.NET.StringTools" ExcludeAssets="runtime" PrivateAssets="All" />

    <!--
      Explicit System.Text.Json package reference is required for source-build to pick up the live package.
      Avoids picking up an old version via transitive dependency from Microsoft.Build or Microsoft.CodeAnalysis.Workspaces.MSBuild.
    -->
    <PackageReference Include="System.Text.Json" />

    <Compile Include="$(RepoRoot)src\Common\PathUtilities.cs" LinkBase="Common" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\BrowserRefresh\Microsoft.AspNetCore.Watch.BrowserRefresh.csproj"
                      PrivateAssets="All"
                      ReferenceOutputAssembly="false"
                      SkipGetTargetFrameworkProperties="true"
                      UndefineProperties="TargetFramework;TargetFrameworks"
                      OutputItemType="Content"
                      TargetPath="middleware\Microsoft.AspNetCore.Watch.BrowserRefresh.dll"
                      CopyToOutputDirectory="PreserveNewest"/>

    <ProjectReference Include="..\DotNetDeltaApplier\Microsoft.Extensions.DotNetDeltaApplier.csproj"
                      PrivateAssets="All"
                      ReferenceOutputAssembly="false"
                      SkipGetTargetFrameworkProperties="true"
                      UndefineProperties="TargetFramework;TargetFrameworks"
                      OutputItemType="Content"
                      TargetPath="hotreload\Microsoft.Extensions.DotNetDeltaApplier.dll"
                      CopyToOutputDirectory="PreserveNewest"/>

    <ProjectReference Include="..\DotNetWatchTasks\DotNetWatchTasks.csproj"
                      PrivateAssets="All"
                      ReferenceOutputAssembly="false"
                      SkipGetTargetFrameworkProperties="true"
                      UndefineProperties="TargetFramework;TargetFrameworks"
                      OutputItemType="Content"
                      CopyToOutputDirectory="PreserveNewest"/>
  </ItemGroup>

  <!--
    Publish the dotnet-watch binaries to the redist directory (artifacts\bin\redist\{config}\dotnet\sdk\{version}\DotnetTools).
    These files are used for layout generation in redist project.
    Tests are also running dotnet.exe from redist artifacts.
  -->
  <Target Name="PublishToRedist"
          DependsOnTargets="PublishDotnetWatchToRedist"
          BeforeTargets="AfterBuild" />
</Project>
