dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.21k stars 1.35k forks source link

Cannot find reference assemblies for .NET 3.5 using .NET 5.0 SDK #5985

Open ganeshnj opened 3 years ago

ganeshnj commented 3 years ago

Issue Description

Failed to build .NET Framework 3.5 targeted class library using .NET 5.0 SDK.

Steps to Reproduce

git clone https://github.com/ganeshnj/DotNet5ReferenceAssemblies
cd DotNet5ReferenceAssemblies
dotnet build

Output

C:\Program Files\dotnet\sdk\5.0.101\Microsoft.Common.CurrentVersion.targets(1180,5): error MSB3644: The reference assemblies for .NETFramework,Version=v3.5 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [C:\source\repos\DotNet5ReferenceAssemblies\DotNet5ReferenceAssemblies.csproj]

Expected Behavior

This issues existed previously also which was mitigated using this workaround.

Actual Behavior

dotnet build should build the project.

Analysis

I suspect .NET 5 CLI introduces some breaking changes that causes this behavior. If I force 3.1 version of .NET Core SDK, build succeeds.

Branch fix-35-reference-assemblies

global.json

{
  "sdk": {
    "version": "3.1.101",
    "rollForward": "latestFeature"
  }
}

Versions & Configurations

❯ dotnet --list-sdks
3.1.301 [C:\Program Files\dotnet\sdk]
5.0.101 [C:\Program Files\dotnet\sdk]
❯ [System.Environment]::OSVersion
Platform ServicePack Version      VersionString
-------- ----------- -------      -------------
 Win32NT             10.0.18363.0 Microsoft Windows NT 10.0.18363.0

Attach a binlog

msbuild.zip

alexey-gusarov commented 3 years ago

VS uses msbuild for building and it's works as expected Rider also have errors on build SDK-style projects with net35 targets

alexey-gusarov commented 3 years ago

I've found deferent behaviors:

failed build: image

success build: image

alexey-gusarov commented 3 years ago

I've found workaroud

set properties

    <FrameworkPathOverride Condition="'$(TargetFramework)' == 'net35'">$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client</FrameworkPathOverride>
    <AutomaticallyUseReferenceAssemblyPackages Condition=" '$(TargetFramework)' == 'net35' ">false</AutomaticallyUseReferenceAssemblyPackages>
Forgind commented 3 years ago

It looks like that means $(MSBuildFrameworkToolsRoot) was evaluated to ''. That's normally set in Microsoft.NetFramework.CurrentVersion.props, but that wasn't imported because exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.NETFramework.props\ImportBefore') (C:\Users\jangirg\AppData\Local\Microsoft\MSBuild\Current\Microsoft.NETFramework.props\ImportBefore) evaluated to false. Not sure if that's supposed to exist or if one of those properties is set to the wrong value.

benvillalobos commented 3 years ago

@Forgind Try to get a repro going. See what happens if we target netcoreapp3.1