NuGet is the package manager for the .NET Framework and .NET (Core).

Packages = reusable DLLs bundled with metadata into .nupkg files.

nuget.org = public package repository.

Packing Assemblies with NuGet

Right Click Project -> Properties -> Package -> "Generate NuGet package on build".

or update the project file:

<PropertyGroup>
                
        <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

dotnet pack -c Release

CarLibrary.1.0.3.nupkg fil will be created (Release or Debug).

Referencing NuGet Packages

The location of NuGet packages is controlled by an XML-Based file named NuGet.Config. On Windows, this file is in the %appdata%\NuGet directory.

Publish Console Applications

Packaging up your app. and its related dependencies is referred to as publishing.

.NET applications can also be published in a similar manner, which is referred to as a framework-dependent deployment. However, .NET apps can also be published as a self-contained app, which doesn't require .NET to be installed at all!

When publishing apps self-contained, you must specify the target runtime identifier (RID) in the project file or through the command-line options. The RID is used to package your app for a specific OS. When a runtime identifier is specified, the publish process defaults to self-contained.

dotnet publish _______

--use-current-runtime : Use current runtime as the target runtime.

-o, --output <DIR> : The output directory to place the published artifacts in.

--self-contained : Publish the .NET Runtime with your app so the runtime doesn't need to be installed on the target machine. The default is true if a runtime identifier is specified.

--no-self-contained : Publish your app as a framework-dependent app without the .NET Runtime. A supported .NET Runtime must be installed to run your app.

-r <RUNTIME_IDENTIFIER>, --runtime <RUNTIME_IDENTIFIER> : The target runtime to publish for. This is used when creating a self-contained deployment. The default is to publish a framework-dependent app.

-c debug | release-configuration debug |release : The configuration to publish for.

-v,, --verbosity <d|detailed|diag|diagnostic|m|minimal|n|normal|q|quiet> : Set the MSBuild verbosity level. Allowed values are q/quiet,m/minimal, n/normal, d/detailed, and diag/diagnostic.

Publishing Framework-Dependent Application

dotnet publish (default debug)
dotnet publish -c Release

Publishing Self-Contained Applications

dotnet publish -r win-x64 -c Release -o selfcontained

or osx-x64 linux-x64

Note: New in .NET 6 the --self-contained true option is no longer necessary. If a runtime identifier is specified, the publish command will use the self-contained process.

Publish Self-Contained Apps as a Single File

dotnet publish -r win-x64 -c release -o singlefile --self-contained true -p:PublishSingle=true -p:DebugType=embedded -p:EnableCompressionInSingleFile=true -p:PublishTrimmed=true -p:PublishReadyToRun=true

Or add these to project file:

<PropertyGroup>
        <PublishSingleFile>true</PublishSingleFile>
        <SelfContained>true</SelfContained>
        <RuntimeIdentifier>win-x64</RuntimeIdentifier>
        <PublishTrimmed>true</PublishTrimmed>
        <DebugType>embedded</DebugType>
        <EnableCompressionInSinglefile>true</EnableCompressionInSinglefile>
        <PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>

dotnet publish -c release -o singlefile