Create Custom Nuget Package Via Visual Studio & Publish
1. Creating Your Project
-
Create a class library project
-
Open Visual Studio, Create New Project
-
Select Class Library for .NET
-
Type
c# class library
in search bar -
From dropdown select Class Library (NOT class library for .NET Framework)
-
-
Name the Project & Solution Name (e.g.
Agate.NetCore.RnD.MySql.Core
). See Naming standard [here](Agate Nuget Project Name & Namespaces Standards b569a74e74d445158fdc71c25464e8c9.md) -
Select .NET Version corresponded with your project (ex:
.NET 6.0
) &Create
-
Create Your Logic/classes
-
Configure packages general properties
-
Right click on project > select
Properties
at very bottom -
In Application > General, changes the value of Assembly Name & Default Namespace to your package name
-
Open the
.csproj
file (double click on root project in hierarchy) & you would see this onPropertyGroup
Section<PropertyGroup> <TargetFramework>net6.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <AssemblyName>Agate.Netcore.Mysql.Repository.Core</AssemblyName> <RootNamespace>Agate.Netcore.Mysql.Repository.Core</RootNamespace> </PropertyGroup>
-
Save the file
-
2. Build & Package Project
- Before we build and packing the project, we need to enable auto generate
.nupkg
file on build
-
Right click on project > select
Properties
at very bottom -
In
Package
section > General -
Set
Generate NuGet package on build
checkbox totrue
(checked) -
in
.csproj
file, you should see one property appeared inPropertyGroup
<PropertyGroup> ... <GeneratePackageOnBuild>True</GeneratePackageOnBuild> </PropertyGroup>
-
Back to Properties > Package > General, let give the details of our package
Property Name Example Value | PackageID | Agate.Netcore.Mysql.Repository.Core | | PackageVersion | 1.0.1 | | Authors | Agate Epic Teams or you can give your own name like Bima, Billy | | Company | Agate International | | Description | MySql base repository for .net core 6.0 | | RepositoryURL | https://gategit.agate.id/tech/agate-open-source/backend-template/game-backend-template | | Release Notes | Initial release specifies the changes of this release |
-
in
.csproj
file, new properties appeared in thePropertyGroup
<PropertyGroup> <TargetFramework>net6.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <AssemblyName>Agate.Netcore.MySql.Repository.Core</AssemblyName> <RootNamespace>Agate.Netcore.MySql.Repository.Core</RootNamespace> <GeneratePackageOnBuild>True</GeneratePackageOnBuild> <PackageId>Agate.Netcore.MySql.Repository.Core</PackageId> <Version>1.0.0</Version> <Authors>Agate Team</Authors> <Company>Agate International</Company> <Product>Agate.Netcore.MySql.Repository.Core</Product> <Description>My SQL base repository for .net core 6.0</Description> <RepositoryUrl>https://gategit.agate.id/tech/agate-open-source/backend-template/game-backend-template</RepositoryUrl> </PropertyGroup>
-
Save the
.csproj
file
- Run the pack command
- In
Build
menu > selectPack
- Take a look in
output window
- In
- After it succeed, go to the project folder in explorer > bin > Debug
- You will see
.nupkg
file is created
3. Push To Gitlab
- Create repository on Agate Gitlab
- Set
RepositoryUrl
in csproj file and refer to your url gitlab. - Push on Gitlab
4. Publish into Agate NuGet
-
Open CLI in where the
.nupkg
file is located (project root/bin/debug) -
Run command
dotnet nuget push -s https://nuget-global.agate.id/v3/index.json -k <NUGET-SERVER-KEY> Agate.Netcore.MySql.Repository.Core.1.0.0.nupkg
Notes: Change
into the key on [Agate Internal NuGet Feed](Agate Internal NuGet Feed 2b3ca56457274846aab2b7a0871ae73b.md) . -
Your package is now up in https://nuget-global.agate.id/
Reading References:
Quickstart: Create and publish a NuGet package using Visual Studio (Windows only)
No Comments