I tried using the Environment Variable APSNETCORE_ENVIRONMENT in my csproj file as a condition. But it doesn't seem to work.
The code:
<Target Name="NpmInstall" Inputs="$(SpaRoot)/package.json" Outputs="$(SpaRoot)/node_modules/.install-stamp" Condition="$(ASPNETCORE_ENVIRONMENT) != 'Development'">