question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet build for .net 4.7 library fails citing missing references

See original GitHub issue

Steps to reproduce

I have a ASP.Net Core 2 web application with class libraries that target the .net 4.7 framework. Visual Studio compiles fine but dotnet build fails. I’ve tracked the errors down to the class libraries which I’ve switched to use. I’ve followed the workarounds here (https://github.com/dotnet/standard/issues/481) and switched the library to use PackageReferences in the .csproj file and remove the packages.config. After some initial issues VS compiles fine and nuget restore works without issue but dotnet build still fails.

Expected behavior

dotnet build succeeds.

Actual behavior

Multiple errors about missing assemblies (ie Nuget Package references).

ApplicationSupport\EmailConfiguration.cs(4,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?) [C:\Dev\Neptune\Neptune.Common\Neptune.Common.csproj]

Environment data

dotnet --info output:

.NET Command Line Tools (2.1.2)

Product Information: Version: 2.1.2 Commit SHA-1 hash: 5695315371

Runtime Environment: OS Name: Windows OS Version: 10.0.16299 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\2.1.2\

Microsoft .NET Core Shared Framework Host

Version : 2.0.3 Build : a9190d4a75f4a982ae4b4fa8d1a24526566c69df

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
krishnan-unnicommented, Sep 24, 2020

Not sure if anyone is still facing this issue without a solution. After some experiments I found out that the issue is with dotnet cli’s having trouble restoring the nuget packages and referencing them properly for the old style projects. I have 2 solutions for this:

  1. You can convert the old style csproj file to the new SDK style project file and build.
  2. In case you can’t or don’t want to change the csproj file to the new style (due to its complexity of change or other reasons) you can change the nuget settings to use package.config (with project.json file) format instead of PackageReference format and then build. Dotnet cli would build fine.
6reactions
bradleypattoncommented, Dec 14, 2017

My suggestion or hope would be if dotnet could issue warnings rather than fail to build if it encounters framework assemblies (even if there are runtime errors later). The reason this is a big issue is that Visual Studio seems to support mixing full framework and .core packages. But then some functionality in VS breaks because under the covers it is calling dotnet and the cmdline is failing.

I’m in the process of trying to convert all of my code to .net core projects because I just don’t see the mixed code working very well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding .NET Standard libraries to 4.7.1 lib adds loads of ...
The answer I'm creating for my own question is: Does your .NET Framework project use packages.config ? If it does, DO NOT reference...
Read more >
the type is defined in an assembly that is not referenced error
Generally, to fix this error, we just need add the reference DLL that contains the missing type to your project! Some options we...
Read more >
Add references in the Reference Manager - Visual Studio ...
Learn how to use the Reference Manager dialog box to add and manage references to developed components.
Read more >
Troubleshoot .NET Framework targeting errors
This article provides resolutions for MSBuild errors that might occur because of reference issues.
Read more >
Compiler Error CS0246
If you get this error in code that was previously working, first look for missing or unresolved references in Solution Explorer. Do you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found