msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

Cannot find reference assemblies for .NET 3.5 or lower using core msbuild

Open nguerrera opened this issue 10 years ago • 35 comments

dotnet/sdk supports targeting .NET 3.5 just fine if you use desktop msbuild, but it fails to find the reference assemblies using core msbuild. Both desktop and core work fine for NET4.0+.

Steps to reproduce

Create a new project with dotnet new Change the TargetFramework to net35 or lower Add <RuntimeIdentifier>win10-x64</RuntimeIdentifier> to the .csproj dotnet restore dotnet build

I've been seeing this issue since the move to msbuild. Targeting .NET 3.5 and lower works in the Preview 2 release SDK. All the relevant targeting packs are installed.

Expected behavior

A successful build

Actual behavior

Fails with the error: ... error MSB3644: The reference assemblies for framework ".NETFramework,Version=v3.5" 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. ...

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-preview3-004056)

Product Information: Version: 1.0.0-preview3-004056 Commit SHA-1 hash: ccc4968bc3

Runtime Environment: OS Name: Windows OS Version: 10.0.14393 OS Platform: Windows RID: win10-x64

Moved from https://github.com/dotnet/cli/issues/4626 for @Thealexbarney.

Moved from https://github.com/dotnet/sdk/issues/369 for @piotrpMSFT

@rainersigwald

nguerrera avatar Nov 10 '16 19:11 nguerrera

I think the problem is that there aren't any reference assemblies for .NET Framework 3.5. The only thing in my .NETFramework\3.5 reference assemblies folder is Profile\Client. When I target .NET 3.5 from a Class Library, the references are coming from C:\Windows\Microsoft.NET\Framework\v2.0.50727\.

dsplaisted avatar Nov 11 '16 23:11 dsplaisted

This comes down to code in FrameworkLocationHelper.GetPathToDotNetFramework that is disabled on .NET Core: https://github.com/Microsoft/msbuild/blob/63cf735deb821969cb096056c0c429c78cc76fbb/src/Shared/FrameworkLocationHelper.cs#L1308-L1310

There are some (probably avoidable) registry calls there, but the biggest obstacle seems to be that finding the v3.5 (or whatever) runtime depends on locating the current runtime (Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName)) and looking around it to find the desired version of the framework. That won't work on Core where object comes from somewhere else entirely.

There may be another way to locate a framework (looks like HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5 has an InstallPath value that looks promising) but we'd have to figure out the right mechanism (and test the heck out of it).

rainersigwald avatar Nov 16 '16 03:11 rainersigwald

What's the work-around for people who need to build such projects on VS 2017? I just ran into this today, and the only thing I could figure out was to compile on a separate machine with only VS 2015 installed.

halverson-dev avatar Feb 15 '17 05:02 halverson-dev

@KevinH-MS It sounds like you're seeing something different from this issue--as originally reported, projects build fine using MSBuild.exe. Can you describe your problem in more detail?

rainersigwald avatar Feb 15 '17 05:02 rainersigwald

I see. I think that's the answer to my question... 😄

(don't use dotnet build -f net35, use msbuild /p:TargetFramework=net35)

halverson-dev avatar Feb 15 '17 05:02 halverson-dev

Issues a pain when you're trying to generate a multi-target nuget package; prior to the great cheese moving of 2016 I had no issues building a package that targeted 2/3.5/4/4.5/etc Is this likely to be sorted in the next few days when VS17s released? Seems ambitious...

Admittedly I'm presuming this is msbuild related as it came with RC4 / VS2017 changes and the issue in the error being thrown is the same as the op (albeit for every version specified).

<PropertyGroup>
      ...  <TargetFrameworks>net20;net35;net40;net45;net451;net452;net462;netstandard1.3;netstandard1.6;netstandard1.6.1;netcoreapp1.1</TargetFrameworks>
    ...

etc https://github.com/BcryptNet/bcrypt.net/blob/master/src/BCrypt.Net/BCrypt.Net.csproj

Hell, it might be that after all these changes and dotnet versions I need to set fire to my PC and start afresh to get things to build 🔥

ChrisMcKee avatar Mar 01 '17 11:03 ChrisMcKee

Right now the only options I see are:

  1. Stay on the old project.json system. (Can't use VS2017 as an IDE)
  2. Migrate to msbuild and be dependent on the full msbuild. (Can't build with dotnet SDK)
  3. Drop <= net35 support.

I guess legacy support is a lower priority than other things for now.

Ideally (IMO) there would be targeting packs on NuGet for each framework version, making it easier to target .NET Framework from the dotnet SDK.

Thealexbarney avatar Mar 01 '17 19:03 Thealexbarney

Our use case at work: targeting net20 is important for us as we have to make some of our libraries work on old Windows Server 2003 systems. We can't upgrade them right now. And we don't want to install anything (say, newer .NET framework versions) to avoid risks of breaking the systems.

We love dotnet tooling, but while this issue is not fixed, we'll have to stay on the full msbuild for this use case.

ghost avatar Mar 02 '17 16:03 ghost

Any updates on this issue?

schotime avatar Mar 15 '17 22:03 schotime

@schotime I've been using RTW since it came out last week and this seems to be resolved.

ChrisMcKee avatar Mar 15 '17 22:03 ChrisMcKee

@ChrisMcKee In core MSBuild or full MSBuild?

Thealexbarney avatar Mar 15 '17 23:03 Thealexbarney

It works in vs for me, but not calling dotnet build manually.

schotime avatar Mar 15 '17 23:03 schotime

@Thealexbarney Windows, so full. I'm not sure you could target .net 2 on non-win platforms as it would lack the required build targets. 2/3.5/4/4.5/4.6 predating it all. You're back in mono-land there.

ChrisMcKee avatar Mar 15 '17 23:03 ChrisMcKee

Also seeing this. Can build in VS2017, but dotnet build gives:

MSB3644: The reference assemblies for framework ".NETFramework,Version=v3.5" were not found.

drewnoakes avatar Mar 16 '17 09:03 drewnoakes

@drewnoakes use msbuild

ChrisMcKee avatar Mar 16 '17 09:03 ChrisMcKee

I'm getting the error with .NET 2.0. I'm trying to do dotnet pack. Is there a workaround for packaging NuGet packages that will work?

JoshClose avatar Mar 24 '17 15:03 JoshClose

@JoshClose you can directly call

msbuild /t:Pack /p:Configuration=Release

For version suffixes, add /p:VersionSuffix=beta-123 (however, note https://github.com/NuGet/Home/issues/4337)

dasMulli avatar Mar 24 '17 15:03 dasMulli

How can I change the package output location? Sorry, I'm no too familiar with msbuild.

JoshClose avatar Mar 24 '17 15:03 JoshClose

/p:PackageOutputPath=path\to\dir\

dasMulli avatar Mar 24 '17 16:03 dasMulli

I got this working by adding the following to the .csproj file:

<PropertyGroup>
  <FrameworkPathOverride Condition="'$(TargetFramework)' == 'net35'">$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client</FrameworkPathOverride>
</PropertyGroup>

Unfortunately, the "normal" path C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5 doesn't work in this case because it doesn't have a copy of mscorlib.dll.

Update

This can now be addressed using the Microsoft.NETFramework.ReferenceAssemblies NuGet package. Click through to the "Project Website" for documentation.

NightOwl888 avatar Apr 22 '17 04:04 NightOwl888