Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net Core - Building to release does not copy NUGET dependencies

I have a console .net core app.
It references a few nuget packages.
Now that it's ready to deploy, when i'm building to release, the nuget references are not coming along so i'm getting a bunch of file not found...

how can i fix this?

like image 816
Leonardo Avatar asked Feb 20 '18 15:02

Leonardo


People also ask

Does dotnet build do a restore?

You don't have to run dotnet restore because it's run implicitly by all commands that require a restore to occur, such as dotnet new , dotnet build , dotnet run , dotnet test , dotnet publish , and dotnet pack . To disable implicit restore, use the --no-restore option.

Does dotnet restore NuGet packages?

NET Core 2.0 and later dotnet build and dotnet run commands restore packages automatically. As of NuGet 4.0, dotnet restore runs the same code as nuget restore . To restore a package with dotnet restore : Open a command line and switch to the directory that contains your project file.

Does dotnet Publish do a build?

The dotnet publish command accepts MSBuild options, such as -p for setting properties and -l to define a logger. For example, you can set an MSBuild property by using the format: -p:<NAME>=<VALUE> .

What is DEPS JSON file?

deps. json will mean the host will blindly enumerate all . dll files in the application directory and use those as the "entire app". This typically means: Portable apps may not work (building with no RID specified will produce a portable app)


1 Answers

It's the difference between building (for testing) and publishing (for deployment to production). dotnet build will build your application for local testing and usage. It will assume that nuget dependencies are present on the machine. If you want to build for deployment, use dotnet publish instead:

dotnet publish -c Release

Then look into the ./bin/Release/netcoreapp2.0/publish directory. It should contain all your dependencies too.

See https://docs.microsoft.com/en-us/dotnet/core/deploying/deploy-with-cli for more details.

like image 175
omajid Avatar answered Sep 30 '22 09:09

omajid