SSG Release
Tags: opensource, csharp, release
Published: 2021-11-25 09:07:02

## Introduction
The last piece of puzzle of [Static Site Generator(ssg)](https://github.com/mkim219/kimchi-ssg) development of previous 12 weeks task is releasing application. The most functionalities of SSG has been done successfully. Now it is time to release my application via package manager. 

## NuGet Package Manager
NuGet is a free open source package manager program released by Microsoft as a visual studio development extension. The releasing application is very simple. Generate `.nupkg` file and upload this file on NuGet website! Here is following steps for releasing my application: 

  1. Configure `<propertyGroup>` project file (.csproj)
```
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <RootNamespace>kimchi_ssg</RootNamespace>
    <PackAsTool>true</PackAsTool>
	<PackageId>Kimchi-ssg</PackageId>
	<Version>1.0.1</Version>
        <Authors>Minsu Kim</Authors>
	<IsPackable>true</IsPackable>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <Description>Simple .NET application to generate static HTML file(s) from text and MarkDown</Description>
    <PackageLicenseExpression>MIT</PackageLicenseExpression>
    <PackageProjectUrl>https://github.com/mkim219/kimchi-ssg</PackageProjectUrl>
  </PropertyGroup>
```
If Visual Studio does not generate `.nupkg` file, `<IsPackable>true</IsPackable>` is required to generate `.nupkg` file

2. There is two ways to generate `.nupkg` file
   - `Build > Pack {Your application}` on Visual Studio
   - Enter `dotnet pack {C# project file}` in CLI. More detail please refer this page [https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-pack](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-pack)

3. On the CLI, the successful message indicates the path where the `.nupkg` file is created

4. Go to [Nuget](https://www.nuget.org/) and create account

5. Go to [Nuget Upload](https://www.nuget.org/packages/manage/upload) after login 

6. Upload `.nupkg`!


## GitHub Action
Next step is creating GitHub Action for automating release. First, go to NuGet website for generating API key. Once I have API key, I create secret environment key in `setting > secrets > add new repository secret` that I can use in CI. 

I found very useful publish template for C#. [https://github.com/marketplace/actions/publish-nuget](https://github.com/marketplace/actions/publish-nuget). This template provides a action to build, pack and publish packages automatically when a project version is released. The following code is added on existing `.yml` file

```
    - name: publish on version change
      id: publish_nuget
      uses: rohith/publish-nuget@v2
      with:
        PROJECT_FILE_PATH: ./kimchi-ssg/kimchi-ssg.csproj
        PACKAGE_NAME: Kimchi-ssg
        VERSION_REGEX: '^\s*<Version>(.*)<\/Version>\s*$'
        NUGET_KEY: ${{secrets.KIMCHI_SSG_NUGET_KEY}}
```
When GitHub action detects version updating on C# project file. The NuGet Package version is automatically updated.

## Feedback
After I have released my package via NuGet, I have changed to review with my friend who is working on IT company as developer. I found some error that the path environment is different than Window because he uses Linux. Also, he gave me a advise that my `README.md` is unclear and vague. I have fixed the issue that happen in the Linux environment and `README.md` to make more understandable to reader.

## Release
My first release is [here](https://www.nuget.org/packages/Kimchi-ssg/1.0.3). Go to NuGet Console and enter `dotnet tool install --global Kimchi-ssg --version 1.0.3`.