3

I recently upgraded our ASP.NET Core 1.1 application to 2.x. This project (and all other projects in the solution) now target the full 4.6.1 framework (previously targeted the full 4.5.2 framework). Visual Studio Version 15.5.7.

After doing so, all my class library projects in the same solution have a number of broken/yellow references to NETStandard.Library.2.0.2. Strangely, the solution still builds without issue and no pertinent warnings or errors are generated in the build output. All other references are fine including all references in the ASP.NET project (meaning that project does not have this problem).

enter image description here

Does anyone know what might be going on here?

Troubleshooting Steps

  1. Clean Solution/Rebuild
  2. NuGet Restore
  3. Restart Visual Studio
  4. Remove .suo/.vs/project.fragment.lock.json and restart
  5. Suspend/Resume/Turn off R#
  6. Manually remove and rebuild (works but they come back after NuGet restore)
  7. Confirm the files it's looking for are actually available on the path...which they are sans the strange "double backslash" before ref:

enter image description here

Environment Details

  • Visual Studio: 15.5.7
  • Full Framework: 4.6.1
  • dotnet --info:

.NET Command Line Tools (2.1.4)

Product Information: Version: 2.1.4 Commit SHA-1 hash: 5e8add2190

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.4\

Microsoft .NET Core Shared Framework Host

Version : 2.0.5 Build : 17373eb129b3b05aa18ece963f8795d65ef8ea54

Please feel free to let me know what other information may be pertinent.

UPDATE: As Requested CSProj Sample (Some Things Had to be Redacted) https://gist.github.com/mikeomeara1/0edd3b83447473accd3350ffc974c62c

McGuireV10
  • 9,572
  • 5
  • 48
  • 64
mikeo
  • 1,045
  • 13
  • 17

2 Answers2

2

The older .NET Framework project system doesn’t properly support .NET Standard Library 2.x, at least at design time. It requires the new .NET Core SDK project system.

A good migration how-to I’ve recently followed — https://www.natemcmaster.com/blog/2017/03/09/vs2015-to-vs2017-upgrade/.

Matt Brooks
  • 1,584
  • 1
  • 14
  • 27
  • OK that makes sense, this project came from 2015 at got converted to 2017 at some point. I've got an upgrade to current running now, I'll do this now and report back. Thanks so much, I would have never sorted that out on my own. – mikeo Apr 26 '18 at 22:12
  • Forgive me for not fully getting this; When I add a new Class Library Project (.NET Framework) from VS I end up with a .csproj that has what this link says is the old version and it uses the "old" schema. Are you saying that all new VS projects need to be of the ".NET Standard" type? NOT the ".NET Framework" type to avoid what I'm experiencing? – mikeo Apr 27 '18 at 00:48
  • Don’t worry — it can be very confusing and sometimes the tooling doesn’t help very much. What you’ve said is certainly my understanding. You need to endure you're adding a ‘.NET Core class library’ project. Then you can retarget that project, to target full .NET Framework. – Matt Brooks Apr 27 '18 at 06:00
  • @mikeo Every project that uses `` does not need to be .net standard or .net core. You can still use the full dotnet framework with the new format. You only need to set your target framework to `net471` and that will be a .Net 4.7.1 project. – Scott Chamberlain Apr 27 '18 at 13:42
  • Yeah, agreed. New .NET Core SDK based project system does not dictate the target framework. – Matt Brooks Apr 27 '18 at 18:04
  • You got it gents. That was the ticket. Thanks again for your help. I don't think I would have ever worked this out on my own. – mikeo Apr 27 '18 at 19:26
1

@MattBrooks and @ScottChamberlain are correct and this is a Visual Studio csproj issue and following the link @MattBrooks provided is the correct answer to this question (I've marked it as such). However, I also wanted to share my personal experience with this in the hopes it will help others who find this process convoluted and confusing (and it doesn't seem right to plop this into an update to the question). As Matt says, "it can be very confusing and sometimes the tooling doesn’t help very much."

Here is the exact procedure I used to convert my projects over. After trying to manually convert a couple, I gave up and rebuilt them:

  1. Remove Project from Solution
  2. Copy Project Folder to Backup Location
  3. Add New ".NET Standard" Class Library Project with Same Name
  4. Edit new .csproj and Change <TargetFramework> to net461 (or whatever you need. Note this can't be done from the Target Framework UI Dropdown. All you'll see is "Net Standard").
  5. Copy all <package> elements from backup projects packages.json (if you don't have a package.json see the outline from the accepted answer to convert your csproj <References> to <PackageReferences>)
  6. Create <ItemGroup> in new csproj
  7. Paste in <package> elements
  8. Find Replace:
    • <package id= --> <PackageReference Include=
    • targetFramework=".*" --> <blank>
    • version --> Version
  9. Open Backed-Up .csproj and copy all <Reference Include=... That DON'T HAVE Version=4.1.0.0, Culture=neutral, PublicKeyToken=..." e.g. that look like <Reference Include="System.Web" /> and paste into new csproj and save.
  10. At this point, NuGet will restore your packages.
  11. If you (likely) end up with NuGet Dependencies that have Yellow/Warning Triangles:
    • Try to build and see if you get any errors/warnings in the error list. I had some versions that didn't jive between projects. Apparently that's a full stop issue now.
    • I had some Pre-Release NuGet Packages from a Private Feed that I had to re-install manually.
    • If all else fails, remove the reference from csproj and install directly from NuGet
    • If all else all else fails, uninstall and reinstall the package from the VS Package Manager
  12. Copy content files and folders from Backup Project into New Project Folder - VS Will Pick them Up and Auto-Add to Project. I also had to copy node_modules for projects that had NPM packages installed from the backup back into the new project.
  13. Add back any solution project references you may have.
  14. Now, the fun part if you're an idiot like me and had files "excluded from project"....you must hunt those down and remove them.

I would also note that if you (like me) had <Reference> tags to packages in your csproj and a package.json, I found that the package.json was accurate in terms of having the correct versions.

I was not able to convert a single MVC4/WebAPI2 project over because there doesn't seem to be a way in the new project format to tell it "This is a web project, run IIS and debug"...in that all new Core projects expect an static void Main. Probably a different question though.

I was able to get the MVC4/WebAPI2 App Migrated Using the Answer Provided here: https://stackoverflow.com/a/49655107/3892531

Good Luck!

mikeo
  • 1,045
  • 13
  • 17