Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Can't build 4.6.1 project that references netstandard on CI server with VS Build Tools 15.3.1 #458

Closed
daveaglick opened this issue Aug 21, 2017 · 14 comments

Comments

@daveaglick
Copy link

daveaglick commented Aug 21, 2017

I'm having an issue on my in-house Bamboo CI server. I'm attempting to build a .NET Framework 4.6.1 project that uses some netstandard libraries. Everything works fine on my dev system, but on my CI server with build tools I get several errors that look similar to:

error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'

The build server has the latest .NET Core SDK and the latest build tools:

2017-08-21_13h21_07

However, MSBuild can't find netstandard.dll no matter what I try:

  Dependency "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51". (TaskId:309)
      Could not resolve this reference. Could not locate the assembly "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. (TaskId:309)

I did notice this:

(!Exists('..\packages\NETStandard.Library.2.0.0\build\netstandard2.0\NETStandard.Library.targets')) was evaluated as (!Exists('..\packages\NETStandard.Library.2.0.0\build\netstandard2.0\NETStandard.Library.targets')).

And verified the target exists:

2017-08-21_13h24_11

Also worth noting this behavior happens whether I run the build from CI or directly from the command line using MSBuild so it's not directly related to Bamboo. At this point I'm blocked and I've run out of things to try. May attempt to use that prerelease NETStandard.Library.NETFramework package but would like to avoid that if I can since it means someone will have to remember to pull it back out later.

(copied from #454 (comment))

@daveaglick
Copy link
Author

Update: adding the NETStandard.Library.NETFramework package does indeed resolve the issue on the build server. This makes me wonder if the VS Build Tools still don't have the proper tooling?

@daveaglick
Copy link
Author

One more update for anyone who stumbles here with the same problem: I found the issue at dotnet/msbuild#1697 and then went back to check the VS Installer and found the ".NET Core build tools" were not selected:

2017-08-21_16h22_11

After adding that checkbox and removing the NETStandard.Library.NETFramework package my builds still succeed.

I lost almost a whole day to this, which is mostly my fault for not thinking to check the installed build tools components. However, the upgrade experience could have been clearer. When you update from an older version of the VS Build Tools to the newest one, the option to include .NET Core components is deselected by default and you're never presented with a window or dialog indicating that you have to opt-in. If it weren't for the other GH issue I linked, I'm not sure I ever would have checked the VS Installer again. Perhaps .NET Core build tools should be opt-out instead of opt-in, or at least a dialog could be shown letting upgraders know that if they want .NET Core/netstandard support they need to check the box.

@danmoseley
Copy link
Member

@daveaglick are you saying that you did have .NET Core components checked (and installed) but then upgrade unchecked it? That doesn't seem right.
Sorry you wasted so much time.

@daveaglick
Copy link
Author

@danmosemsft Pretty sure it was never checked. IMO the problem is that the upgrade process for VS Build Tools never surfaces it as an option. Unless you know you know beforehand to modify the installation and check the box, you may assume (as I did) that .NET Core support ships by default.

@dasMulli
Copy link

@danmosemsft Is there a plan for making all .net workloads depend on the necessary tooling to support ns2.0? It's probably ok now but if the plan going forward is for package authors to publish ns2.0 nuget packages and the support is missing, that would be unfortunate. ("why do I need to install .NET Core to use a NuGet package in my decade old WinForms application?")

@danmoseley
Copy link
Member

@terrajobst can you speak to the comment above about it not being intuitive when .NET Core workload is needed and missing?

@terrajobst
Copy link
Member

To summarize:

  • You should never use the package NETStandard.Library.Framework as this is deprecated (marked right now)
  • In VS 2017, you need 15.3 or up and the .NET Core SDK workload installed

@scottsauber
Copy link

Installing the .NET Core Build Tools worked for me as well.

I just burned ~4 hours on this trying to build a 4.6.1 project with a .NET Standard 2 library. Built fine locally w/ VS 2017 15.4.1 but died on my on-prem TeamCity server.

I had the dotnet SDK installed and the Web Development Build Tools installed, but I did not have the .NET Core build tools installed. Would've thought the SDK would include everything, including the .NET Core build tools...? We have other apps that are .NET Core + .NET Standard, and having just the SDK installed, because we were using the dotnet cli to restore/build/publish. This was just our first app that combined .NET Framework + .NET Standard.

Came pretty close to just installing full VS until I found this, so thanks for this.

The error I got is below to boost the Google foo of this issue:

C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.Common.targets(73, 5): Project 'C:\pathgoeshere.csproj' targets '.NETStandard,Version=v2.0'. It cannot be referenced by a project that targets '.NETFramework,Version=v4.6.1'.

@talhajunaidd
Copy link

I was facing error CS0012: The type 'ValueType' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' and was solved by installing .Net core build tools

@SushiGuy
Copy link

SushiGuy commented Jan 8, 2018

Fix for us was adding this small reference line above the other references in the csproj file.
<ItemGroup>
<Reference Include="netstandard" />

UselessToucan added a commit to UselessToucan/osu-framework that referenced this issue Jan 18, 2018
@michal-ciechan
Copy link

I fixed this by referencing (as I couldn't upgrade our build server)

Changing my references from lib\netstandard2.0 to lib\portable-net45+win8+wp8+wpa81

<Reference Include="System.Collections.Immutable, Version=1.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  <HintPath>..\packages\System.Collections.Immutable.1.4.0\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
</Reference>

Rather than

<Reference Include="System.Collections.Immutable, Version=1.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  <HintPath>..\packages\System.Collections.Immutable.1.4.0\lib\netstandard2.0\System.Collections.Immutable.dll</HintPath>
</Reference>

@Astor91
Copy link

Astor91 commented Mar 9, 2018

@michal-ciechan that was my issue too! Thanks a lot!

@nehaboora
Copy link

I fixed the problem by modifying my visual studio professional 2017 by checking:

  • Windows 10 SDK (10.0.15063) for desktop, for UWP: C#,VB,JS, for UWP:C++
  • .Net framework 4.6.2 SDK, .Net framework 4.7.1 SDK,
    under individual components using Microsoft Visual Studio installer.

Also, make sure that you have NuGet package manager checked

@bfeinb
Copy link

bfeinb commented Jan 4, 2019

@terrajobst Thanks so much! Your suggestion saved the day for me when trying to build .NET Standard 2.0 projects. I used this chocolatey package to install the .NET Core build tools as part of my CI/CD pipeline: https://chocolatey.org/packages/visualstudio2017-workload-netcorebuildtools.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests