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

  <PropertyGroup>
    <NoBuild>true</NoBuild>
    <!-- prevents error `The 'NoBuild' property was set to true but the 'Build' target was invoked` -->
    <!-- will be removed after https://github.com/NuGet/Home/issues/7801 in netcore > 5 ? -->
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <CopyBuildOutputToOutputDirectory>false</CopyBuildOutputToOutputDirectory>
    <CopyOutputSymbolsToOutputDirectory>false</CopyOutputSymbolsToOutputDirectory>
    <CopyDocumentationFileToOutputDirectory>false</CopyDocumentationFileToOutputDirectory>
    <TargetFramework>netstandard2.0</TargetFramework>
    <IncludeBuildOutput>false</IncludeBuildOutput>
    <PackageId>tmp</PackageId>
    <RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
    <RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>
    <RunAnalyzers>false</RunAnalyzers>
    <NoPackageAnalysis>true</NoPackageAnalysis>
    <WarningLevel>0</WarningLevel>
  </PropertyGroup>
  <!-- Force Release Configuration build and check env variables / User.Directory.Build.props -->
  <Target Name="_CheckConfiguration" BeforeTargets="CoreBuild">
    <Error Condition="'$(Configuration)' != 'Release'" Text="You should build this project only in 'Release' configuration. Use `dotnet build -c Release`" />
    <Error Condition="'$(DoNugetFeedApiKey)' == ''" Text="You should set 'DoNugetFeedApiKey' property in User.Directory.Build.props or in env variable" />
    <Error Condition="'$(DoNugetFeedUrl)' == ''" Text="You should set 'DoNugetFeedUrl' property in User.Directory.Build.props or in env variable" />
  </Target>

  <ItemGroup Label="Build order">
    <ProjectReference Include="$(SolutionDir)\Extensions\**\*.csproj" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" />
    <ProjectReference Include="$(SolutionDir)\Orm\**\*.csproj" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" />
    <ProjectReference Include="$(SolutionDir)\Weaver\**\*.csproj" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" />
  </ItemGroup>
  <!-- You can add to this list in User.Directory.Build.props -->
  <ItemGroup>
    <NugetPublishInput Include="$(PackageOutputPath)Xtensive.Orm.$(Version).nupkg" />
    <NugetPublishInput Include="$(PackageOutputPath)Xtensive.Orm.BulkOperations.$(Version).nupkg" />
    <NugetPublishInput Include="$(PackageOutputPath)Xtensive.Orm.Firebird.$(Version).nupkg" />
    <NugetPublishInput Include="$(PackageOutputPath)Xtensive.Orm.Localization.$(Version).nupkg" />
    <NugetPublishInput Include="$(PackageOutputPath)Xtensive.Orm.Logging.log4net.$(Version).nupkg" />
    <NugetPublishInput Include="$(PackageOutputPath)Xtensive.Orm.Logging.NLog.$(Version).nupkg" />
    <NugetPublishInput Include="$(PackageOutputPath)Xtensive.Orm.MySql.$(Version).nupkg" />
    <NugetPublishInput Include="$(PackageOutputPath)Xtensive.Orm.Oracle.$(Version).nupkg" />
    <NugetPublishInput Include="$(PackageOutputPath)Xtensive.Orm.PostgreSql.$(Version).nupkg" />
    <NugetPublishInput Include="$(PackageOutputPath)Xtensive.Orm.Reprocessing.$(Version).nupkg" />
    <NugetPublishInput Include="$(PackageOutputPath)Xtensive.Orm.Security.$(Version).nupkg" />
    <NugetPublishInput Include="$(PackageOutputPath)Xtensive.Orm.Sqlite.$(Version).nupkg" />
    <NugetPublishInput Include="$(PackageOutputPath)Xtensive.Orm.SqlServer.$(Version).nupkg" />
    <NugetPublishInput Include="$(PackageOutputPath)Xtensive.Orm.Tracking.$(Version).nupkg" />
    <NugetPublishInput Include="$(PackageOutputPath)Xtensive.Orm.Web.$(Version).nupkg" />
  </ItemGroup>

  <!-- If package-lock.json has changed, perform an NPM install -->
  <Target Name="PublishToNuget" AfterTargets="Pack" DependsOnTargets="Pack">
    <Message Importance="high" Text="Publish nupkg %(NugetPublishInput.Identity) to server" />
    <Exec Command="dotnet nuget push %(NugetPublishInput.Identity) --force-english-output --timeout 60 --api-key $(DoNugetFeedApiKey) --source $(DoNugetFeedUrl)" WorkingDirectory="$(PackageOutputPath)" />
  </Target>
</Project>
