Sdk: Different RID behavior for multitargeted restore in VS and command line

Created on 15 Feb 2017  路  5Comments  路  Source: dotnet/sdk

If RuntimeIdentifer(s) differ between inner builds, then VS will gather the properties from each inner build and send them on to restore whereas the command line restore target only reads them from the outer evaluation context.

Repro project

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>netcoreapp1.0;netcoreapp1.1</TargetFrameworks>
    <RuntimeIdentifier Condition="'$(TargetFramework)' == 'netcoreapp1.0'">win7-x86</RuntimeIdentifier>
    <RuntimeIdentifier Condition="'$(TargetFramework)' == 'netcoreapp1.1'">win7-x64</RuntimeIdentifier>
  </PropertyGroup>
</Project>

Behavior in VS (and expected behavior)

Builds successfully

Behavior on command line (dotnet restore; dotnet build)

C:\...\Microsoft.NET.Sdk.targets(92,5): error : Assets file 'C:\...\ConsoleApp144\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v1.0/win7-x86'. Ensure you have restored this project for TargetFramework='netcoreapp1.0' and RuntimeIdentifier='win7-x86'. [C:\...\ConsoleApp144.csproj]
(and other related errors)

@emgarten @srivatsn @natidea This is causing issues for #847 in multi-targeted app case. I think the right fix would be in nuget restore targets to gather all RIDs from inner builds, but I think I can do that in SDK with a BeforeTargets="Restore"

In PR

All 5 comments

but I think I can do that in SDK with a BeforeTargets="Restore"

Looks like BeforeTargets="Restore" doesn't run for solution restores. https://github.com/dotnet/cli/issues/5683

@dasMulli Yes. Just hit this and it was also running too late. Using BeforeTargets="_GenerateRestoreProjectSpec" fixes both issues.

btw, I think this would help a lot when using native dependencies for library projects that target full fx + specific RID and netstandard. (https://github.com/dotnet/cli/issues/5241, https://github.com/dotnet/cli/issues/5241#issuecomment-271392503)

@emgarten Can you review efbcaca, which is incorporated in to the larger #847

@emgarten Can you review efbcaca, which is incorporated in to the larger #847

This change looks good to me. Restore will read this union and apply it for all TFMs.

Was this page helpful?
0 / 5 - 0 ratings