Alex McLean
Alex McLean

Reputation: 2764

MSBuild can't find package for .NET Standard project in solution with other .NET Framework projects

I have a Visual Studio Solution with:

This solution built fine on my local machine running VS Community 2017 15.7.3 This solution also builds fine on my build machine which is using MSBuild from the same VS of the same version.

Problem

The problem occurs when I add a Nuget package (in this case Newtonsoft) to proj A. The solution builds fine on my local machine but doesn't work when using MSBuild. Also, if I load the solution on my build machine using the VS installed there, it builds fine.

The error getting raised is:

error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)

I think I've narrowed down the issue to an issue where .NET Standard & .NET Framework projects don't play well together with Nuget when they're in the same .sln because if I completely remove proj C & proj D the build succeeds on my build machine. I can also confirm that the Newtonsoft package is in my C:/User/.nuget/packages folder, but is not in the ./packages folder of the solution directory (which I'm pretty sure if supposed to happen since it's a .NET Standard project?).

CI .yml File

nuget.exe restore $SOLUTION_FILE
MSBuild.exe '/p:Configuration=release' $SOLUTION_FILE

Notes

I've done a lot of reading trying to find issues similar to this, but the closest I get is issues that look a lot like this one. This issue is similar but is using the .NET Standard project itself as a Nuget package where as I'm trying to get Nuget packages into the .NET Standard project itself. Maybe I need to extract all of my .NET Standard projects into a Nuget package instead of using them in the same solution?

Upvotes: 7

Views: 2672

Answers (1)

Alex McLean
Alex McLean

Reputation: 2764

As Leo Lieu pointed out, using msbuild /t:restore "YourSolutionFile.sln" was the trick, although I had to do it as well as running nuget.exe restore "YourSolutionFile.sln" which I find peculiar...

Upvotes: 3

Related Questions