sdk: "dotnet build" fails on non-Windows for projects that multi-target where Desktop is one of the targets frameworks.

Issue

If you have a project that multi-targets where one of Desktop is one of the target frameworks (such as <TargetFrameworks>net46;netcoreapp1.0</TargetFrameworks>), then the project will fail to build on non-windows with an error similar to:

Microsoft.Common.CurrentVersion.targets(1110,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.6" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.

Expected Result

The Desktop framework should be ignored and a warning should be printed indicated the framework in question could not be built.

This is a reasonable solution since the Desktop framework is not to be available on non-Windows.

Additional Details

This also impacts solutions where some projects target Desktop and some target .NETStandard or .NETCore and projects that only target Desktop.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 30
  • Comments: 19 (10 by maintainers)

Commits related to this issue

Most upvoted comments

@piotrpMSFT, that works for singular projects. That does not work when targeting an entire solution (which is perhaps a separate issue) where not every project targets the desired framework.

The command will fail with project.assets.json' doesn't have a target for '.NETStandard,Version=v1.6'. Ensure you have restored this project for TargetFramework='netstandard1.6' and RuntimeIdentifier=''. (or equivalent for whatever framework you built for).

The workaround would be to build all netstandard projects first, then to build all netcore or net projects, but that quickly becomes untenable.

ReferenceAssemblies are available on nuget.org now. You can add it like this:

<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0-preview.2" PrivateAssets="All" />

With that you don’t need to hack paths for the Mono ReferenceAssemblies:

image

@piotrpMSFT, Do you have a link?

Is it something akin to --skip-framework so that you can tell a build to explicitly skip a particular framework?

@RehanSaeed Yes, starting in the .NET 5 SDK they should be added automatically if you need them: https://github.com/dotnet/sdk/pull/10981