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

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <!-- Indicate the assembly is providing a COM server -->
	  <EnableComHosting>True</EnableComHosting>
	  <PlatformTarget>x86</PlatformTarget>
  </PropertyGroup>

  <ItemGroup>
    <Reference Include="itextsharp">
      <HintPath>..\itextsharp.dll</HintPath>
      <CopyLocal>True</CopyLocal>
    </Reference>
    <!-- Used in lieu of a Primary Interop Assembly (PIA) -->
	  <Compile Include="../COMContract/*.cs" />
  </ItemGroup>
<Target Name="ServerUsage" Condition="'$(RegFree)' != 'True'" AfterTargets="Build">
		<Message Importance="High" Text="%0a************************************%0a*** $(MSBuildProjectName) usage instructions ***%0a************************************" />
		<Message Importance="High" Text="The server must be COM registered in order to activate.%0aThe following commands must be executed from an elevated command prompt." />
		<Message Importance="High" Text="Register:%0a    regsvr32.exe &quot;$(ProjectDir)$(OutputPath)$(ComHostFileName)&quot;" />
		<Message Importance="High" Text="Unregister:%0a    regsvr32.exe /u &quot;$(ProjectDir)$(OutputPath)$(ComHostFileName)&quot;" />
	</Target>

	<Target Name="ServerUsage_RegFree" Condition="'$(RegFree)' == 'True'" AfterTargets="Build">
		<Message Importance="High" Text="%0a************************************%0a*** $(MSBuildProjectName) usage instructions ***%0a************************************" />
		<Message Importance="High" Text="A RegFree COM manifest has been created for the server.%0aThe manifest '@(RegFreeComManifest->'%(Filename)%(Extension)')' must be included during server deployment.%0aThe COMServer project will copy all required outputs to the COMClient output directory." />

		<ItemGroup>
			<ServerOutput Include="$(OutputPath)*.dll" />
			<ServerOutput Include="$(OutputPath)*.runtimeconfig.json" />
			<ServerOutput Include="$(OutputPath)*.deps.json" />
			<ServerOutput Include="$(OutputPath)*.manifest" />
		</ItemGroup>

		<!-- Deploy all required server outputs -->
		<Copy SourceFiles="@(ServerOutput)" DestinationFolder="../COMClient/$(OutputPath)" />
	</Target>

	<Target Name="Clean_RegFree" AfterTargets="Clean">
		<ItemGroup>
			<ServerOutputToDelete Include="../COMClient/$(OutputPath)COMServer.*" />
		</ItemGroup>

		<!-- Cleanup deployed server outputs -->
		<Delete Files="@(ServerOutputToDelete)" />
	</Target>
</Project>
