The dotnet publish
command publishes application for deployment.
You can publish applications/libraries in a couple of different ways, depending on what your end-goal is. If you want to create a single file executable that you can distribute (or run) directly, you can use something like:
dotnet publish -r win-x64 -c Release --self-contained true -p:PublishSingleFile=true
This publishes an application, targeting Windows on x64 in Release mode as a self-contained single file application.
For more information, see the documentation at https://learn.microsoft.com/en-us/dotnet/core/deploying/ and https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file
.NET 6 (and .NET 5, as well as .NET Core) are all designed to use packages dependencies from nuget.org or other package repositories. All you need to do is add a package dependency to your project file. For example, you want to make use of Newtonsoft.Json
, you add this to your project file:
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
</ItemGroup>
dotnet publish
will automatically include all the dependencies when building your application.
You can specify which package repositories to use through a Nuget.Config
file:
<packageSources>
<add key="CompanyNexus" value="https://nexus.internal.company.com/v3/index.json" />
</packageSources>
nuget.org
is default, but any other package repositories need to be added to this file before dotnet restore
(or dotnet build
or dotnet publish
) can find them.