'Newtonsoft not found by batch file only

My environment is Visual Studio 2019 Community Edition on Windows 10. I have a solution named MyWebApi inside MyWebApi folder which uses Newtonsoft. When I open the solution in Visual Studio and build the solution, it build successfully. Now I am trying to build the solution outside of Visual Studio via a batch file. So I create a batch file with this line:

dotnet build MyWebApi\MyWebApi.sln --configuration Debug

Then open PowerShell and run the batch file. But I get an error message:

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

So on the same computer, Visual Studio can find the 'Newtonsoft' but the batch file cannot? How can I solve this issue?

The batch file only has 1 line:

dotnet build MyWebApi\MyWebApi.sln --configuration Debug

Not sure why someone voted that this question need more clarity? The batch file contains just 1 line and I am running it from PowerShell. I have also tried running it from PowerShell as an Administrator but still the same error message.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source