<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Remove="Services\Evaluation\**" />
    <Content Remove="Services\Evaluation\**" />
    <EmbeddedResource Remove="Services\Evaluation\**" />
    <None Remove="Services\Evaluation\**" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Caching.CSRedis" Version="3.6.50" />
    <PackageReference Include="CSRedisCore" Version="3.6.5" />
    <PackageReference Include="DotNetZip" Version="1.15.0" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.6" />
    <PackageReference Include="VueCliMiddleware" Version="5.0.0" />
  </ItemGroup>
  <ItemGroup>
    <None Remove="ClientApp\src\static\BaseDataDefault.json" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="DotNetZip" Version="1.15.0" />
    <PackageReference Include="HTEXLib" Version="2.5.6" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
    <PackageReference Include="VueCliMiddleware" Version="5.0.0" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="logfile\" />
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <ItemGroup>
    <None Include="TEAMModelOS.csproj" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\TEAMModelOS.SDK\TEAMModelOS.SDK.csproj" />
  </ItemGroup>

  <PropertyGroup>
    <!-- Typescript/Javascript Client Configuration -->
    <SpaRoot>ClientApp\</SpaRoot>
    <DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
    <UserSecretsId>078b5d89-7d90-4f6a-88fc-7d96025990a8</UserSecretsId>
    <Version>5.0.0</Version>
  </PropertyGroup>
  <Target Name="DebugEnsureNodeEnv" BeforeTargets="Build">
    <!-- Build Target:  Ensure Node.js is installed -->
    <Exec Command="node --version" ContinueOnError="true">
      <Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
    </Exec>
    <Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
  </Target>

  <Target Name="DebugEnsureNpm" AfterTargets="DebugEnsureNodeEnv">
    <!-- Build Target:  Ensure Node.js is installed -->
    <Exec Command="npm --version" ContinueOnError="true">
      <Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
    </Exec>
  </Target>

  <Target Name="EnsureNodeModulesInstalled" BeforeTargets="Build" Inputs="package.json" Outputs="packages-lock.json">
    <!-- Build Target: Restore NPM packages using npm -->
    <Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />

    <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
  </Target>

  <Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
    <!-- Build Target: Run webpack dist build -->
    <Message Importance="high" Text="Running npm build..." />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build" />

    <!-- Include the newly-built files in the publish output -->
    <ItemGroup>
      <DistFiles Include="$(SpaRoot)dist\**" />
      <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
        <RelativePath>%(DistFiles.Identity)</RelativePath>
        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
      </ResolvedFileToPublish>
    </ItemGroup>
  </Target>
</Project>
