NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 253 forks source link

Respect UndefineProperties on ProjRefs - MSBuild-based package restore fails when /p:TargetFramework is set but only applies to leaf project #7278

Open AArnott opened 6 years ago

AArnott commented 6 years ago

Details about Problem

NuGet product used (NuGet.exe | VS UI | Package Manager Console | dotnet.exe): msbuild.exe /restore

MSBuild version: 15.9.10.28431

dotnet.exe --version (if appropriate): 2.1.500-preview-009266

VS version (if appropriate): 15.9.0 preview 2.0 (28029.51.d15.9)

OS version (i.e. win10 v1607 (14393.321)): 17134.rs4_release.180410-1804

Worked before? If so, with which NuGet version: Not sure.

Detailed repro steps so we can see the same problem

  1. Create two .NET class libraries. One targets .netstandard1.0 and the other targets .netstandard2.0 and references the first.
  2. Try to restore and build the latter project, specifying the target framework as a global property (as one might if it was a multitargeting project and only wanted to build one framework):
msbuild ns2proj.csproj /restore /p:targetframework=netstandard2.0

Expected

Both projects have their packages restored and build.

Actual

Package restore errors out because the P2P references that restore follows does not suppress the TargetFramework global property as necessary and as the regular build does.

msbuild /restore /p:targetframework=netstandard2.0 lib2
  Restoring packages for D:\temp\bug7278\lib2\lib2.csproj...
  Restore completed in 69.47 ms for D:\temp\bug7278\lib1\lib1.csproj.
  Generating MSBuild file D:\temp\bug7278\lib2\obj\lib2.csproj.nuget.g.props.
  Restore completed in 601.43 ms for D:\temp\bug7278\lib2\lib2.csproj.
C:\Program Files\dotnet\sdk\2.1.500-preview-009266\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Run
timeIdentifierInference.targets(143,5): message NETSDK1057: You are working with a preview version
of the .NET Core SDK. You can define the SDK version via a global.json file in the current project.
 More at https://go.microsoft.com/fwlink/?linkid=869452 [D:\temp\bug7278\lib2\lib2.csproj]
C:\Program Files\dotnet\sdk\2.1.500-preview-009266\Sdks\Microsoft.NET.Sdk\targets\Microsoft.Package
DependencyResolution.targets(198,5): error NETSDK1005: Assets file 'D:\temp\bug7278\lib1\obj\projec
t.assets.json' doesn't have a target for '.NETStandard,Version=v1.0'. Ensure that restore has run a
nd that you have included 'netstandard1.0' in the TargetFrameworks for your project. [D:\temp\bug72
78\lib1\lib1.csproj]

As a workaround, and a demonstration that P2P references generally work for this and it's just package restore that's broken, the following succeeds:

msbuild ns2proj.csproj /t:restore
msbuild ns2proj.csproj /p:targetframework=win8

Repro project: bug7278.zip

rrelyea commented 5 years ago

Appears to be a dupe of #7286 One issue is complaining about RID. The other is complaining about TFM.