Bug 57229 - Windows runtimes added to generated project.assets.json
Summary: Windows runtimes added to generated project.assets.json
Status: NEW
Alias: None
Product: Tools
Classification: Mono
Component: msbuild ()
Version: 5.2 (2017-04)
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Ankit Jain
Depends on:
Reported: 2017-06-07 11:12 UTC by Matt Ward
Modified: 2018-01-04 21:06 UTC (History)
3 users (show)

Tags: vs-sync
Is this bug a regression?: ---
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 57229 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:

Description Matt Ward 2017-06-07 11:12:15 UTC
Using Mono JIT compiler version (2017-04/2ad9ba1 Fri Jun  2 10:35:50 EDT 2017)

To repro:

1) With .NET Core 1.0.4 SDK installed and Mono installed create a new dotnet console project: dotnet new console
2) Restore using msbuild: msbuild /t:restore /v:diag > msbuild.log
3) Look at generated obj/project.assets.json and see runtimes section added at the end of the file:

    "runtimes": {
      "win": {
        "#import": []
      "win-x64": {
        "#import": []
      "win-x86": {
        "#import": []

4) Restore using dotnet: dotnet msbuild /t:restore /v:diag > dotnet-msbuild.log
5) Look at the generated obj/project.assets.json and see no runtimes section.

The runtimes section affects what NuGet packages are restored so with msbuild we end up restoring windows NuGet packages.
This also happens with .NET Core 2.0 preview 1 or 2 installed.

Looking at the MSBuild output the RuntimeIdentifiers property = win;win-x86;win-x64
The RuntimeIdentifiers property is used by NuGet to generate the runtimes section in the project.assets.json file as far as I am aware.

Not sure where these runtime identifiers are from. The RuntimeIdentifiers property is not defined when using dotnet restore.

Created some diagnostic msbuild outputs for Mono and dotnet cli:

MSBuild (Mono): https://gist.github.com/mrward/64b3d0b18f97a630b009930fadf3d7d2
dotnet cli: https://gist.github.com/mrward/9c974a207c0bcdf1862aa2e1bbf3ff4f
Comment 1 Matt Ward 2017-06-07 11:27:36 UTC
Searching around the RuntimeIdentifiers seem to be defined in the file: 


In here I can see:

    <BaseNuGetRuntimeIdentifier Condition="'$(BaseNuGetRuntimeIdentifier)' == ''">win</BaseNuGetRuntimeIdentifier>


  <PropertyGroup Condition="'$(BaseNuGetRuntimeIdentifier)' == 'win' and '$(NuGetRuntimeIdentifier)' != '' and '$(RuntimeIdentifiers)' == '' and '$(RuntimeIdentifier)' == ''">
Comment 2 Matt Ward 2017-06-07 12:45:40 UTC
Testing MSBuild that ships with VS 2017 15.3 preview on Windows, which ships with .NET Core 2.0 preview sdk, I see that the Microsoft.NuGet.targets file is not imported. It does not seem to be included in the MSBuildAllProjects. So no runtime section is generated for a .NET Core console project on Windows.

Looking a bit further it seems that the Microsoft.NET.Sdk.props file that ships with MSBuild sets a SkipImportNuGetBuildTargets to true. This prevents the Microsoft.NuGet.targets file from being imported. The Microsoft.NuGet.ImportAfter.targets file has:

<Import Condition="Exists('$(NuGetTargets)') and '$(SkipImportNuGetBuildTargets)' != 'true'" Project="$(NuGetTargets)" />

NuGetTargets here is: c:\Program files (x86)\Microsoft Visual Studio\Preview\Community\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.targets

Which explains why the runtimes section is not added on Windows by VS 2017.

A quick look at Mono's Microsoft.NuGet.targets and that seems to have the same condition:

  <Import Condition="Exists('$(NuGetTargets)') and '$(SkipImportNuGetBuildTargets)' != 'true'" Project="$(NuGetTargets)" />

And the .NET Core 1.0.4 sdk Microsoft.NET.Sdk.prop sets SkipImportNuGetBuildTargets to true as does the Microsoft.NET.Sdk.prop that ships with Mono. So not sure why this is not working.
Comment 3 Vincent Dondain [MSFT] 2018-01-04 21:06:00 UTC
We're also experiencing this issue in https://github.com/xamarin/xamarin-macios/issues/3138.

'System.Threading.Overlapped' has both /runtimes/win and /runtimes/unix but unix will never be used (maybe it should have /mac, /macos or /osx but that wouldn't be used either.