Bug 59605 - 15.4 nuget breaks compilation of any mixed project
Summary: 15.4 nuget breaks compilation of any mixed project
Status: CONFIRMED
Alias: None
Product: Tools
Classification: Mono
Component: msbuild ()
Version: 5.4 (2017-06)
Hardware: PC Mac OS
: --- major
Target Milestone: ---
Assignee: Ankit Jain
URL:
Depends on:
Blocks:
 
Reported: 2017-09-20 14:34 UTC by Marek Safar
Modified: 2017-09-25 10:37 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: Yes
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 59605 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Marek Safar 2017-09-20 14:34:21 UTC
1. clone e.g. cecil from https://github.com/jbevain/cecil
2. cd cecil
3. nuget restore
4. msbuild

Super unhelpful message shows up

>/NuGet/Microsoft.NuGet.targets(178,5): error : Your project is not referencing the ".NETFramework,Version=v4.0" framework. Add a reference to ".NETFramework,Version=v4.0" in the "frameworks" section of your project.json, and then re-run NuGet restore. [cecil/Mono.Cecil.csproj]


The problem seems to be in Nuget or msbuild because Nuget creates obj/project.assets.json file which msbuild chokes on, manually removing the file fixes the build.

So far I found only similar complains here https://github.com/dotnet/sdk/issues/1321 with no solution.
Comment 1 Matt Ward 2017-09-25 10:37:59 UTC
VS Mac does not run any restore when the Mono.Cecil.sln is opened. So the build works there with the default configuration selected.

NuGet restore and msbuild /t:restore both generate restore files (project.assets.json, nuget.g.targets, nuget.g.props) for several projects. (Mono  5.4.0.174 (2017-06/1afb931de69 Mon Aug 28 08:21:28 EDT 2017)).

Looking at the diagnostic restore output it looks like it is treating the various projects as .NET Standard. The Mono.Cecil.csproj defines a NetStandard property:

    <NetStandard Condition=" $(Configuration.StartsWith('netstandard')) Or '$(NuGetRestoreTargets)' != '' ">true</NetStandard>
    <NetStandard Condition=" '$(NetStandard)' == '' ">false</NetStandard>

https://gist.github.com/mrward/7e771c33bb72731fd8e1ed15952f0a21

NetStandard seems to be true in the restore output since NuGetRestoreTargets is defined. This setting then causes msbuild to import the NetStandard.props file which sets the TargetFramework to be .NETStandard. Then when you build and do not use the netstandard configuration the build then fails.

Testing this on Windows with NuGet 4.3.3.exe. If a normal command prompt is opened so MSBuild 14 is used no restore occurs and NuGet outputs a message:

Nothing to do. None of the projects in this solution specify any packages for NuGet to restore.

If you open a VS 2017 command prompt so MSBuild 15 is used then NuGet restores the various restore files the same as Mono's MSBuild. Then building the solution fails in the same way.

So this seems to suggest that it is an MSBuild 15 problem which affects both Windows and Mono or maybe even a Mono.Cecil project problem.