-1

We are using dotnet publish command to perform the building the project as well as publishing the binaries. The following command is used for that?

dotnet publish <PROJECT>|<SOLUTION>]--force -o <OUTPUT_DIRECTORY>]

We also want to use the some dependent binaries from a package that is pushed to Nexus during our build process. What is the best way to Specify the dependencies during the dotnet publish command and use that dependency to build the project

mystack
  • 4,910
  • 10
  • 44
  • 75
  • Package repo like Nuget? – Hamlet Hakobyan Nov 29 '21 at 17:47
  • Do we have any solution if we use Nuget ?Could consider Azure DevOps artifact repo. it is similar to Nuget,rt? – mystack Nov 29 '21 at 17:55
  • Yes, you can. Publish all your dependencies as nuget packages and publish them to the feed. Then you can add dependencies as nuget packages to the project from that feed. During to build you should restore dependencies as a build step. – Hamlet Hakobyan Nov 29 '21 at 19:21
  • But , how I could use these dependencies with dotnet publish. Could you provide me series of commands or any link that I should follow – mystack Nov 29 '21 at 20:22
  • Beside `dotnet publish` command there is a [dotnet restore](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-restore) – Hamlet Hakobyan Nov 29 '21 at 22:47

2 Answers2

0

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.

omajid
  • 14,165
  • 4
  • 47
  • 64
0

If your dotnet project is dependent with other project.

Example: A project is dependent on Project B but B project repository is different

Than

use bellow command to resolve the dependency from your A project.

dotnet add path/of/project/A.csproj reference path/of/dependent/project/B.csproj

Now finally you can use

dotnet build

or

dotnet publish

It will resolve your issue, Cheers...!!!

Deepak Sharma
  • 331
  • 3
  • 11