How to use baget to build nuget private server

How to use baget to build nuget private server? Almost all languages now provide package management tools, such as JavaScript’s npm, Java’s Maven, and Dart’s pub. The .Net program is of course NuGet. NuGet has been around for many years, and the strange thing is that there are still many people who don’t know.

Now that the software structure is becoming more and more complex, it is often necessary to share some libraries, components, etc. in multiple projects. NuGet provides us with convenient package management functions.

However, NuGet provides services exposed on the external network by default. If we want to manage some libraries within the company or in our own home, we need to build NuGet private servers ourselves.

Use baget to build nuget private server

Nuget Private Server has several tools to build official Nuget.Server, ProGet, BaGet, etc. The tool BaGet is recommended here. It is cross-platform and very lightweight, easy to deploy, and can be run with a single line of docker command.

Surprisingly, Nuget.Server, as a tool officially provided by NuGet, still relies on the Framework.

There are many ways to deploy BaGet. For example, you can pull the released release file from Github and run it manually with dotnet, or you can directly use docker containerized deployment. Now is the age of containerization, so of course docker deployment first.

# The following config is the API Key used to publish packages.
# You should change this to a secret value to secure your server.
ApiKey=NUGET-SERVER-API-KEY

Storage__Type=FileSystem
Storage__Path=/var/baget/packages
Database__Type=Sqlite
Database__ConnectionString=Data Source=/var/baget/baget.db
Search__Type=Database

First create a baget.env environment variable configuration file.

docker run --rm --name nuget-server -p 5555:80 --env-file baget.env -v "$(pwd)/baget-data:/var/baget" loicsharma/baget:latest

Use the docker run command to run

How to use baget to build nuget private server
How to use baget to build nuget private server

Visit this service, you can see that the service is running successfully. But now there is no package, so nothing here…

Build NuGet package

To push the NeGet package, first we need to package our library into a NuGet package.

How to use baget to build nuget private server
How to use baget to build nuget private server

Packing can use nuget’s cli to pack. In fact, the easiest way is to right-click on the properties of our project and check the “Generate NuGet package during build” on the packaging tab page, so that every time we generate the project, the corresponding nuget package will be generated in the bin directory. .

Push NuGet package

After the Nuget package is packaged, you can push your own package to this service.

 dotnet nuget push -s https://znlive.com/v3/index.json .\AgileConfig.Client.1.1.8.11.nupkg

Use dotnet nuget push command to push

How to use baget to build nuget private server
How to use baget to build nuget private server

If the push is successful, it will display “Package Pushed”, during which there is a warning because we have not set apikey, this is ignored.

How to use baget to build nuget private server
How to use baget to build nuget private server

Refresh the BaGet page again, and you can see the package we just pushed up.

Use BaGet source

In order for our VisualStudio to be able to retrieve the BaGet service, we need to perform a simple configuration.

How to use baget to build nuget private server
How to use baget to build nuget private server

Open VS> Tools> Options> NuGet Package Manager> Package Source, click the green plus sign, configure the source name baget, address: https://znlive.com/v3/index.json and click OK.

How to use baget to build nuget private server
How to use baget to build nuget private server

Just open a project solution, select the package source to “baget” on the NuGet package retrieval page, and the browse page will list the packages currently owned by this source. In this way, management and installation can be carried out normally.

Conclusion

Through the above, we simply demonstrated how to run a BaGet service through the docker command. BaGet is cross-platform, lightweight, and easy to deploy. The experience is very good. You can try it.

https://github.com/loic-sharma/BaGet

Leave a Comment