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.07k forks source link

Preview 2 regression: UWP target not restoring #1335

Closed clairernovotny closed 7 years ago

clairernovotny commented 7 years ago

Moved from https://github.com/dotnet/cli/issues/6829

Steps to reproduce

Try to build in VS 2017 15.3 with preview2 and today's nightly .NET Core 2 tooling:

Clone https://github.com/Reactive-Extensions/Rx.NET checkout develop Open Rx.NET/Source/System.Reactive.sln

This worked with the .NET Core 2 preview 1 tooling.

Expected behavior

Restore and build should work

Actual behavior

Severity    Code    Description Project File    Line    Suppression State
Error       Assets file 'C:\dev\RxNET\Rx.NET\Source\src\System.Reactive\obj\project.assets.json' doesn't have a target for '.NETCore,Version=v5.0'. Ensure you have included 'netcore50' in the TargetFrameworks for your project.  System.Reactive C:\Program Files\dotnet\sdk\2.0.0-preview2-006391\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets    164 

Environment data

dotnet --info output:

.NET Command Line Tools (2.0.0-preview2-006391)

Product Information:
 Version:            2.0.0-preview2-006391
 Commit SHA-1 hash:  ef5d4b47c3

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.16215
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.0.0-preview2-006391\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.0-preview2-25407-01
  Build    : 40c565230930ead58a50719c0ec799df77bddee9
clairernovotny commented 7 years ago

Here is the project.assets.json file that was created. It does have a UAP,Version=v10.0 section in it. project.assets.json.txt

clairernovotny commented 7 years ago

Removing the MSBuild.Sdk.Extras package and manually adding the following properties at the end of the System.Reactive.csproj

  <PropertyGroup Condition="'$(TargetFramework)' == 'uap10.0'">
    <NugetTargetMoniker>UAP,Version=v10.0</NugetTargetMoniker>
    <TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
    <DefineConstants Condition="'$(DisableImplicitFrameworkDefines)' != 'true'">$(DefineConstants);NETFX_CORE;WINDOWS_UWP</DefineConstants>
    <CopyLocalLockFileAssemblies Condition="'$(CopyLocalLockFileAssemblies)' == ''">false</CopyLocalLockFileAssemblies>
    <TargetPlatformVersion Condition="'$(TargetPlatformVersion)' == ''">10.0.10240.0</TargetPlatformVersion>
    <TargetPlatformMinVersion Condition="'$(TargetPlatformMinVersion)' == ''">10.0.10240.0</TargetPlatformMinVersion>
    <TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
    <LanguageTargets>$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v15.0\Microsoft.Windows.UI.Xaml.CSharp.targets</LanguageTargets>

    <!-- Need to override the built-in implicit defines for UAP or it'll be NETCORE5_0 -->
    <!-- this makes it UAP10_0_10240_0 to match the rest -->
    <ImplicitFrameworkDefine Condition="'$(DisableImplicitFrameworkDefines)' != 'true'">UAP$(TargetPlatformMinVersion.Replace('.', '_'))</ImplicitFrameworkDefine>
    <DisableImplicitFrameworkDefines Condition="'$(DisableImplicitFrameworkDefines)' != 'true'">true</DisableImplicitFrameworkDefines>
  </PropertyGroup>
  <!--<Import Project="$(MSBuildSDKExtrasTargets)" Condition="Exists('$(MSBuildSDKExtrasTargets)')" />-->

Does not help either. So it's not a case of the props being missing on initial restore before the package exists to import the targets that define the props. Putting them in manually does not help.

nguerrera commented 7 years ago

We need to deal with case where nugettargetmoniker != targetframeworkmoniker in assets file check

nguerrera commented 7 years ago

Fixed by #1344

clairernovotny commented 7 years ago

This needs to be reopened.... the NuGet check prevents .NET Framework libraries from being referenced by .NET Core App 2 and .NET Standard 2 libraries.

https://ci.appveyor.com/project/onovotny/refit/build/1.0.99#L232

"C:\projects\refit\Refit.sln" (restore target) (1) ->
(Restore target) -> 
MSBUILD : error NU1202: Package Nustache 1.16.0.4 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package Nustache 1.16.0.4 supports: net20 (.NETFramework,Version=v2.0) [C:\projects\refit\Refit.sln]
MSBUILD : error NU1202: Package Nustache 1.16.0.4 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package Nustache 1.16.0.4 supports: net20 (.NETFramework,Version=v2.0) [C:\projects\refit\Refit.sln]
0 Warning(s)
2 Error(s)
nguerrera commented 7 years ago

That looks like a completely different issue, related to https://github.com/dotnet/sdk/pull/1326 not this.

I believe the issue is that VS 15.3 Preview 2 does not have a NuGet version that can handle AssetTargetFallback.

If I'm right:

  1. VS 15.3 Preview 3 will fix it
  2. Building and restoring using dotnet (CLI) instead of msbuild (VS) should work
  3. You can workaround the VS/CLI version incompatibility by forcing the older PackageTargetFallback always:
<PropertyGroup>
  <DisableImplicitPackageTargetFallback>true</DisableImplicitPackageTargetFallback>
  <DisableImplicitAssetTargetFallback>true</DisableImplicitAssetTargetFallback>
  <PackageTargetFallback>net461</PackageTargetFallback>
</PropertyGroup>
clairernovotny commented 7 years ago

If I use dotnet to restore and build, I see this warning:

C:\dev\refit\InterfaceStubGenerator [netcore2 ≡ +0 ~2 -1 !]> dotnet build
C:\dev\refit\InterfaceStubGenerator\InterfaceStubGenerator.csproj : warning NU1701: Package 'Nustache 1.16.0.4' was rest
ored using '.NETFramework,Version=v4.6.1' instead the project target framework '.NETCoreApp,Version=v2.0'. This may caus
e compatibility problems.
nguerrera commented 7 years ago

That is expected and something that was designed to happen as part of the move to AssetTargetFallback. It is telling you something true: the .NETFramework library pulled in by the .NETCoreApp project might not actually work at runtime on .NET Core.

There's a way to suppress this on the individual package reference, but I'm having trouble locating the syntax. @rrelyea, @emgarten, @terrajobst Are there docs for this that we can point folks to?

srivatsn commented 7 years ago

You can add a NoWarn to the PackageRef now like this:

<PackageReference Include="Nustache" Version="1.16.0.4" NoWarn="NU1701" />