dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.71k stars 1.06k forks source link

UseAppHost fails when publishing exe-exe P2P reference #2482

Open pakrym opened 6 years ago

pakrym commented 6 years ago

Repro:

lib2/lib2.csproj

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

</Project>

lib1/lib1.csproj

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="../lib2/lib2.csproj" ReferenceOutputAssembly="False" />
  </ItemGroup>
</Project>

dotnet publish /p:UseAppHost=true /p:RuntimeIdentifier=win7-x64 in lib1 directory.

Expected:

Publish succedes

Actual:

C:\Users\pakrymet\.dotnet\x64\sdk\2.1.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(119,5): error NETSDK1066: A RuntimeIdentifier must be specified to publish a framework-dependent application with an application host. [D:\temp\888\lib2\lib2.csproj]

Suspect

Microsoft.Common.CurrentVersion.targets includesTargetFramework;RuntimeIdentifier in RemoveProperties but not UseAppHost

 <!--
       Get reference target framework lists.
       Note: A future optimization could cache the closest match and set the target framework on
       this MSBuild task invocation. This would (optimistically) save an evaluation of the referenced
       project when the answer is the same.
    -->
    <MSBuild
        Projects="@(_MSBuildProjectReferenceExistent)"
        Targets="GetTargetFrameworks"
        BuildInParallel="$(BuildInParallel)"
        Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)"
        ContinueOnError="!$(BuildingProject)"
        RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove);TargetFramework;RuntimeIdentifier"
        Condition="'%(_MSBuildProjectReferenceExistent.SkipGetTargetFrameworkProperties)' != 'true'"
        SkipNonexistentTargets="true">
      <Output TaskParameter="TargetOutputs" ItemName="_ProjectReferenceTargetFrameworkPossibilities" />
    </MSBuild>
livarcocc commented 6 years ago

@peterhuene please take a look.

peterhuene commented 6 years ago

This is fundamentally the same issue as #1834, but for UseAppHost instead of SelfContained. The general problem is our reliance on global properties and how they will ultimately interact with P2P references and, in cases like RuntimeIdentifier and SelfContained, can alter what is restored against.

There should be no reason to set a global UseAppHost property; in 2.2, setting SelfContained to false is the preferred mechanism since UseAppHost defaults to true. Still, setting a global SelfContained property can cause problems for P2P references between Exe output type projects as well (see previously mentioned issue).