36
loading...
This website collects cookies to deliver better user experience
Happy holidays! This post is a contribution to C# Advent 2021. Be sure to visit and read all the excellent content focused on C# and the .NET community.
Microsoft.Extensions.Logging
libraryLoggerFactory
to provide the ability for developers to choose their own logging solution. I contacted him as I was getting started to warn him that I was blatantly plagiarizing his work. 😂public static class GpsLocation
{
// This project uses multi-targeting to expose device-specific APIs to .NET Standard.
public static async Task<(double latitude, double longitude)> GetCoordinatesAsync()
{
#if NET461
return CallDotNetFramworkApi();
#elif WINDOWS_UWP
return CallUwpApi();
#else
throw new PlatformNotSupportedException();
#endif
}
// Allows callers to check without having to catch PlatformNotSupportedException
// or replicating the OS check.
public static bool IsSupported
{
get
{
#if NET461 || WINDOWS_UWP
return true;
#else
return false;
#endif
}
}
}
build
and publish
. The build
job creates the NuGet package, while the publish
job handles uploading the generated package to NuGet.org. The publish
job will only run if the build
job completes successfully. You can review the entire CD workflow file here.actions/checkout@v2
to check out the code based on the sha associated with the release.dotnet pack
and passes various parameters to configure the build and packing process to ensure we've got the cleanest output possible.Release
mode rather than Debug
mode.dotnet restore
in the action, there's no need to restore packages from Nuget during the build process. The --no-restore
parameter tells the build process to skip this step to save time../dist
directory.Version
and set it to the value of the get_version
step, which returned our version number based on the GitHub release../dist
directory when the build and packing process completes. We use the actions/upload-artifact@v2
action to save the contents of that directory as an artifact of the action with the name dist. We'll access this artifact in the next step of the process.publish
job will send it to NuGet../dist
directory.dotnet nuget push
to send any .nupkg file in the ./dist
directory to NuGet.org. This requires an access token that NuGet provides. For securities sake, we store that token in the repositories secrets and access it via ${{secrets.NUGET_API_KEY}}
.