I was working on the Habitat based implementation where we have requirment to develop the components based on the Helix guideline. I have created multiples of components which were grouped based on the Module(Feature, Foundation, Project).
Now I wanted to share these components with different team where they can reuse them based on their requirement. I decided to create the nuget package and deploy those package in a common Artifactory.
There are several way to create the nuget packages but below are the simple steps which I have used for my Sitecore components:
Create Nuget Package:
- Open command prompt in Admin mode
- Navigate to the folder where Project(.csproj) file is available
- Execute the Below command to Create Nuget Specification
nuget spec
It will create a .nuspec file with same name as project file
Ex:
MySitecoreLibrary.Foundation.MyComponent.nuspec
4. Open .nuspec in any text editor and update the Metadata and files details
Example:-
<?xml version="1.0" encoding="utf-8"?> <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"> <metadata> <id>MySitecoreLibrary.Foundation.MyComponent</id> <version>1.0.0</version> <title>MySitecoreLibrary.Foundation.MyComponent</title> <authors>Ravindra Giri</authors> <owners>Ravindra Giri</owners> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>My foundation component </description> <copyright>Copyright © 2017</copyright> <dependencies> <dependency id="MySitecoreLibrary.Foundation.SitecoreExtensions" version="1.0.0" /> <dependency id="Microsoft.AspNet.Mvc" version="5.2.3" /> </dependencies> </metadata> <files> <file src="appx.json" target="docs\" /> <file src="images\**\*.*" target="docs\images\" /> <file src="readme.md" target="docs\" /> <file src="bin\MySitecoreLibrary.Foundation.MyComponent.dll" target="lib\net46\" /> <file src="App_config\**\*.*" target="content\App_config\"/> </files> </package>
5. Execute below command to create Nuget Package
nuget pack MySitecoreLibrary.Foundation.MyComponent.nuspec
It will create a MySitecoreLibrary.Foundation.MyComponent.1.0.0.nupkg package file at the same location where .nuspec file is available.
Deployment of Nuget Package to Artifactory :
- Open command prompt in Admin mode
- Navigate to the folder where Nuget package is available
- Execute the Below command
nuget push [package name] -Source [artifactory Path URL] Example:- nuget push MySitecoreLibrary.Foundation.MyComponent.1.0.0.nupkg -Source https://xyz.com/artifactory/api/nuget/nuget-release/MySitecore/MyComponent/
Note:
- You should have the write access to the Artifactory
- Make sure the appx.json encoding is set to UTF-8 if not then convert it to UTF-8 using notepad++


