Creating and Publishing NuGet Package for .Net Framework Projects

Mustafa Ozdemir
baakademi
Published in
4 min readSep 7, 2020

--

I will create a Nuget package and publish the Nuget package to the Nuget feed for further usage.I will show how you can implement this in this post. I will keep the post as short and simple as possible. To achieve this only required steps are included.

Let’s fire..

Step 1 : Create a new .Net Framework project. Give a name to the project. My project name is TestProject . Next, create a new class and give a name to it. My class name is TestClass.cs. As displayed in the below diagram, create a cs project and fill it.

Figure 1: Solution Explorer
Figure 2: Class and Its Methods

Step 2: In step two we must modify Assembly Info file. In Solution Explorer, find and click AssemblyInfo.cs under Properties. Now, time for editing the file. We are gonna edit five rows of it. These are; title, description, company, product and copyright. I filled up a sample form for you. Check it out in Figure 3. Fill all essential rows and save it.

Figure 3: Modify just marked rows

Step 3: When you are publishing to NuGet, you want to be in “release” mode. On the toolbar, choose Release from the Solution Configurations list.

Figure 4: Set Release

Step 4: Unload project and set Release;
*In Solution Explorer, right-click the project.
*Select the Unload Project
*
right-click to the unloaded project
*Select Edit Project File
*
Change the build configuration to Release(Figure 6).
*right-click the project and select Reload Project.

Figure 6: Set Release

All that means is when we would like to run the NuGet executable on project, it will pick release instead of debug. You are almost there.

Step 5: Open Folder.
*
In Solution Explorer, right-click the project.
*Select the Open Folder in File Explorer.
*Opened folder is the folder that we would like to push. Leave the folder as it is for now. We will be right back to it.

Step 6: Now, we must download nuget.exe You can download it with the given url. Move the downloaded file into the folder we opened in step 5. For visual reference check Figure 7.

Figure 7: Latest state of cs project

Step 7: So far so good, Time for some console operations. We want to open up the command line. In command line, we are in the same folder as the CS project and “nuget.exe”. So, we can run nuget in console line. Type “nuget spec”. Then you should see something like in figure 8.

Figure 8: TestProject.nuspec has been created.

Step 8: In project folder, we have created a new file called “TestProject.nuspec”. Open up this file with visual code. Check the screenshots. Do your changes according to these screenshots and be ready for the next step.

Figure 9
Figure 10

There are some changes to make on the TestProject.nuspec file. We are going to focus on these changes in coming up steps.

Step 9: In this step, we need to edit some elements of the TestProject.nuspec
These elements are; <authors>, <description>, <projectUrl><releaseNotes>, <tags>. I am going to delete <iconUrl> element because I don’t want to specify any icon for this project. You can check last version of the file in Figure 11.

Figure 11: Updating TestProject.nuspec

Step 10: The project is ready to run nuget pack command in console. run this command in the same folder as cs project. you should see something like figure 12. After running the command, a file called ‘TestProject.1.0.0.nupkg’ has to be created.

Figure 12: Create TestProject.1.0.0.nupkg

We are ready to push our first project to Nuget feed. In this stage, we should create an account on nuget.org. Then, you need to get an API key. After you got the key you can push your project with below console command.


nuget push TestProject.1.0.0.nupkg APIkey -Source https://api.nuget.org/v3/index.json

In this page, I tried to list all required steps to create and publish a Nuget package . Hope, this post gave you an idea about NuGet packaging system.

Thank you.

--

--