I have a Visual Studio Solution with:
.csproj
)
proj A
(class library): proj refs -> proj B
, no Nuget packagesproj B
(class library): no proj refs, no Nuget packages.csproj
)
proj C
(class library): proj refs -> proj B
, several Nuget packagesproj D
(test project): proj refs -> proj C
, proj B
& proj A
, several Nuget packagesThis 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?
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With