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

  <PropertyGroup>
    <!--
        COM servers must define a framework to use in situations where a CLR instance is not already present in the process.
        Note that since the COM server may be activated in a process where the CLR must be activated, both the projects
        *.runtimeconfig.json and *.deps.json files must be bundled with the server itself.

        In the following example, the following files are needed to deploy the COM server:
            COMServer.comhost.dll
            COMServer.dll
            COMServer.deps.json
            COMServer.runtimeconfig.json

        In a RegFree COM scenario, the following file must also be deployed:
            COMServer.X.manifest
    -->
    <TargetFramework>netcoreapp3.1</TargetFramework>

    <!-- Indicate the assembly is providing a COM server -->
    <EnableComHosting>True</EnableComHosting>
    
    	  <PlatformTarget>x86</PlatformTarget>

    <!-- Generate a RegFree COM manifest -->
    <!-- <EnableRegFreeCom Condition="'$(RegFree)' == 'True'">True</EnableRegFreeCom>-->
  </PropertyGroup>

  <ItemGroup>
    <!-- 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>
