Nuget: Difference between revisions
Jump to navigation
Jump to search
(9 intermediate revisions by the same user not shown) | |||
Line 43: | Line 43: | ||
public static string Format(DateTime date) => Format(date, DD_MM_YYYY); | public static string Format(DateTime date) => Format(date, DD_MM_YYYY); | ||
public static string Format(DateTime date, string format) => date.ToString( | public static string Format(DateTime date, string format) => date.ToString(format); | ||
public static DateTime Parse(String date) => Parse(date, DD_MM_YYYY); | public static DateTime Parse(String date) => Parse(date, DD_MM_YYYY); | ||
Line 51: | Line 51: | ||
</source> | </source> | ||
==Unit Test== | |||
<source lang="C#"> | <source lang="C#"> | ||
using System; | using System; | ||
Line 75: | Line 76: | ||
dotnet test Chorke.Academia.Core.Utility.Tests | dotnet test Chorke.Academia.Core.Utility.Tests | ||
dotnet publish Chorke.Academia.Core.Utility.Tests | dotnet publish Chorke.Academia.Core.Utility.Tests | ||
</source> | |||
<source lang="bash"> | |||
cd Chorke.Academia.Core.Utility | cd Chorke.Academia.Core.Utility | ||
dotnet pack -c Release /p:PackageVersion=1.0. | dotnet pack -c Release /p:PackageVersion=1.0.0; cd bin/Release/ | ||
dotnet nuget push Chorke.Academia.Core.Utility.1.0. | dotnet nuget push Chorke.Academia.Core.Utility.1.0.0.nupkg -k <nuget api key> -s https://www.nuget.org/ | ||
</source> | |||
==Dependency== | |||
<source lang="bash"> | |||
dotnet new console -n Chorke.Academia.Core.Launch | |||
dotnet add Chorke.Academia.Core.Launch package Chorke.Academia.Core.Utility --version 1.0.2 | |||
</source> | |||
<source lang="C#"> | |||
using System; | |||
using Chorke.Academia.Core.Utility; | |||
namespace Chorke.Academia.Core.Launch | |||
{ | |||
class Program | |||
{ | |||
static void Main(string[] args) | |||
{ | |||
DateTime date = new DateTime(1983, 10, 10); | |||
String birthday = DateUtil.Format(date, DateUtil.DD_MM_YYYY); | |||
Console.WriteLine("Birthday :" + birthday); | |||
} | |||
} | |||
} | |||
</source> | |||
<source lang="bash"> | |||
dotnet publish Chorke.Academia.Core.Launch | |||
dotnet run --project Chorke.Academia.Core.Launch | |||
</source> | </source> | ||
==References== | ==References== | ||
{| | |||
| valign="top" | | |||
* [https://help.github.com/en/articles/configuring-nuget-for-use-with-github-package-registry Configuring NuGet for use with GitHub Package Registry] | * [https://help.github.com/en/articles/configuring-nuget-for-use-with-github-package-registry Configuring NuGet for use with GitHub Package Registry] | ||
* [https://medium.com/@churi.vibhav/creating-and-using-a-local-nuget-package-repository-9f19475d6af8 Creating and using a local NuGet package repository] | * [https://medium.com/@churi.vibhav/creating-and-using-a-local-nuget-package-repository-9f19475d6af8 Creating and using a local NuGet package repository] | ||
Line 92: | Line 126: | ||
* [https://docs.microsoft.com/en-us/nuget/tools/cli-ref-setapikey NuGet CLI setapikey command] | * [https://docs.microsoft.com/en-us/nuget/tools/cli-ref-setapikey NuGet CLI setapikey command] | ||
* [https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package-using-the-dotnet-cli Create and publish a package] | * [https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package-using-the-dotnet-cli Create and publish a package] | ||
| valign="top" | | |||
* [https://help.sonatype.com/repomanager2/.net-package-repositories-with-nuget/nuget-proxy-repositories Nuget Proxy Repositories] | |||
* [https://dotnet.microsoft.com/download/dotnet-core/3.0 Download .NET Core 3.0] | |||
* [https://docs.microsoft.com/en-us/nuget/create-packages/creating-a-package Create NuGet packages] | * [https://docs.microsoft.com/en-us/nuget/create-packages/creating-a-package Create NuGet packages] | ||
* [https://docs.microsoft.com/en-us/nuget/install-nuget-client-tools Install NuGet client tools] | * [https://docs.microsoft.com/en-us/nuget/install-nuget-client-tools Install NuGet client tools] | ||
* [https://github.com/NuGet/NuGet.Server/blob/master/src/NuGet.Server/Web.config Create NuGet Server] | |||
* [https://www.nuget.org/packages/NuGet.Repositories/4.2.0 NuGet Repositories] | * [https://www.nuget.org/packages/NuGet.Repositories/4.2.0 NuGet Repositories] | ||
|} |
Latest revision as of 11:15, 29 April 2020
Mono Nuget
brew install mono
sudo curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
'alias nuget="mono /usr/local/bin/nuget.exe"' >> ~/.bash_profile
brew uninstall mono
sudo rm -rf /usr/local/bin/nuget.exe
# vim ~/.bash_profile and delete 'alias nuget="mono /usr/local/bin/nuget.exe"'
nuget setapikey 4003d786-cc37-4004-bfdf-c4f3e8ef9b3a
nuget setapikey 4003d786-cc37-4004-bfdf-c4f3e8ef9b3a -source https://cdn.chorke.org/feed
Utility Project
mkdir Utility; cd Utility
dotnet new classlib -n Chorke.Academia.Core.Utility
dotnet new xunit -n Chorke.Academia.Core.Utility.Tests
dotnet new sln -n Utility
dotnet sln add Chorke.Academia.Core.Utility/Chorke.Academia.Core.Utility.csproj
cd Chorke.Academia.Core.Utility.Tests/
dotnet add reference ../Chorke.Academia.Core.Utility/Chorke.Academia.Core.Utility.csproj
cd ..; dotnet sln add Chorke.Academia.Core.Utility.Tests/Chorke.Academia.Core.Utility.Tests.csproj
using System;
using System.Globalization;
namespace Chorke.Academia.Core.Utility
{
public class DateUtil
{
public const string DD_MM_YYYY = "dd/MM/yyyy";
public static string Format(DateTime date) => Format(date, DD_MM_YYYY);
public static string Format(DateTime date, string format) => date.ToString(format);
public static DateTime Parse(String date) => Parse(date, DD_MM_YYYY);
public static DateTime Parse(String date, string format) => DateTime.ParseExact(date, format, CultureInfo.InvariantCulture);
}
}
Unit Test
using System;
using Xunit;
using Chorke.Academia.Core.Utility;
namespace Chorke.Academia.Core.Utility.Tests
{
public class DateUtilTest
{
[Fact]
public void FormatTest()
{
DateTime date = new DateTime(1983, 10, 10);
String actual = DateUtil.Format(date, DateUtil.DD_MM_YYYY);
Assert.Equal("10/10/1983", actual);
}
}
}
dotnet publish Chorke.Academia.Core.Utility
dotnet test Chorke.Academia.Core.Utility.Tests
dotnet publish Chorke.Academia.Core.Utility.Tests
cd Chorke.Academia.Core.Utility
dotnet pack -c Release /p:PackageVersion=1.0.0; cd bin/Release/
dotnet nuget push Chorke.Academia.Core.Utility.1.0.0.nupkg -k <nuget api key> -s https://www.nuget.org/
Dependency
dotnet new console -n Chorke.Academia.Core.Launch
dotnet add Chorke.Academia.Core.Launch package Chorke.Academia.Core.Utility --version 1.0.2
using System;
using Chorke.Academia.Core.Utility;
namespace Chorke.Academia.Core.Launch
{
class Program
{
static void Main(string[] args)
{
DateTime date = new DateTime(1983, 10, 10);
String birthday = DateUtil.Format(date, DateUtil.DD_MM_YYYY);
Console.WriteLine("Birthday :" + birthday);
}
}
}
dotnet publish Chorke.Academia.Core.Launch
dotnet run --project Chorke.Academia.Core.Launch