{"componentChunkName":"component---src-pages-markdown-remark-fields-slug-js","path":"/engineering/using-nuget-to-publish-net-packages/","result":{"data":{"markdownRemark":{"id":"8a93da19-d5e6-5946-8796-674fa1afde91","excerpt":"NuGet is a free and open-source package manager for the .NET ecosystem. We can create and install packages using NuGet client tools. All of the .NET packages…","html":"<p>NuGet is a free and open-source package manager for the .NET ecosystem. We can create and install packages using NuGet client tools. All of the .NET packages are hosted for publishing and consumption on a central package repository known as NuGet Gallery.</p>\n<p>Prerequisites</p>\n<ul>\n<li>Visual Studio 2017 (with .NET-related workload)</li>\n<li>nuget.exe (add it’s location to PATH environment variable)</li>\n<li>Valid account on nuget.org</li>\n</ul>\n<p><strong>Create a class library project</strong></p>\n<p>For a .NET package to be published in the NuGet Gallery, it should be a valid class library project. The following instructions can be used to create a simple class library project:</p>\n<ul>\n<li>Open Visual Studio, go to File > New > Project, expand the Visual C# > .NET Standard node. Select the \"Class Library (.NET Standard)\" template and provide a valid name.</li>\n<li>To build the project, right-click on the project file and select Build. A DLL file will be generated in the Debug folder or Release folder (if you build the configuration)</li>\n</ul>\n<p>For a real useful NuGet package, you should write necessary code which can be used by others to develop applications. However, a class library from the template is sufficient to create a package.</p>\n<p><strong>Configure Package Properties</strong></p>\n<ol>\n<li>Go to Project > Properties, select Package tab.</li>\n<li>Provide a unique identifier for your package and fill out other required properties. For a description of various properties, please visit <a href=\"https://docs.microsoft.com/en-us/nuget/reference/nuspec\">here</a>. The properties provided at this stage will be defined in .nuspec manifest that is created by Visual Studio for the project.</li>\n<li>To view the properties directly in the project file, right-click the project in Solution Explorer and select Edit AppLogger.csproj.</li>\n</ol>\n<p><strong>Run the pack command</strong></p>\n<ol>\n<li>Set the configuration to Release.</li>\n<li>Right click the project in Solution Explorer and select the Pack command.</li>\n<li>Visual Studio builds the project and creates the .nupkg file. Please note that the built package is in bin\\Release\\netstandard2.0 as befits the .NET Standard 2.0 target.</li>\n</ol>\n<p><strong>Acquire API Key</strong></p>\n<ol>\n<li><a href=\"https://www.nuget.org/users/account/LogOn?returnUrl=%2F\">Sign in to your nuget.org account</a> or create an account if it doesn’t already exist.</li>\n<li>Select your user name on the top right, then select API Keys.</li>\n<li>Select Create, provide a name for your key, select Select Scopes > Push.</li>\n<li>Under API Key, enter * for Glob pattern, then select Create.</li>\n<li>After the key is created, select Copy to retrieve the access key needed for publishing the package.</li>\n</ol>\n<p><strong>Important:</strong> Save your key in a secure location because you cannot copy the key again later on. If you return to the API key page, you need to regenerate the key to copy it.</p>\n<p><strong>Publish with nuget push</strong></p>\n<ol>\n<li>Open Command Prompt.</li>\n<li>Change to the folder containing the .nupkg file.</li>\n<li>\n<p>Run the following command, specifying your package name and replacing the key value with your API key:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"powershell\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">nuget push &amp;lt;PACKAGE-NAME&amp;gt;.nupkg &amp;lt;API-KEY&amp;gt; -Source https://api.nuget.org/v3/index.json</span></span></code></pre>\n</li>\n<li>nuget.exe displays the results of the publishing process.</li>\n</ol>\n<p><strong>Manage the published package</strong></p>\n<p>You can view your published package in your profile on nuget.org. Select Manage Packages to see the one that was just published. It might take a while for your package to be visible in search results.</p>\n<p>If you want to unlist the package and hide it from search results, follow the steps listed below:</p>\n<ol>\n<li>On nuget.org, select your user name on top right, then select Manage Packages.</li>\n<li>Find the package to be unlisted under Published and select the trash can icon on the right.</li>\n<li>On the next page, clear the box labeled List (package-name) in search results and select Save.</li>\n</ol>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n  .dark-default-dark .mtk1 { color: #D4D4D4; }\n</style>","headings":[],"fields":{"slug":"/engineering/using-nuget-to-publish-net-packages/"},"frontmatter":{"metatitle":null,"metadescription":null,"description":null,"title":"Using NuGet to publish .NET packages","canonical":null,"date":"June 28, 2018","updated_date":null,"tags":["NuGet",".NET"],"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1,"src":"/static/61bc9402fec623803bf04d21e948e84a/c2ae5/desdev.png","srcSet":"/static/61bc9402fec623803bf04d21e948e84a/f5f11/desdev.png 200w,\n/static/61bc9402fec623803bf04d21e948e84a/6d133/desdev.png 400w,\n/static/61bc9402fec623803bf04d21e948e84a/c2ae5/desdev.png 600w","sizes":"(max-width: 600px) 100vw, 600px"}}},"author":{"id":"Hitesh Pamnani","github":null,"bio":"An enthusiastic developer with hands-on-experience in various tech platforms. Settled as an Android developer from past 4 years, worked on some interesting stuff and looking forward to more. Loves gadgets, soothing music and spending time with family.","avatar":null}}}},"pageContext":{"id":"8a93da19-d5e6-5946-8796-674fa1afde91","fields__slug":"/engineering/using-nuget-to-publish-net-packages/","__params":{"fields__slug":"engineering"}}},"staticQueryHashes":["1171199041","1384082988","1711371485","1753898100","2100481360","229320306","23180105","528864852"]}