How to use Github+appveyor+nuget to build your own. NET core Open Source Library

Source: Internet
Author: User
Tags dotnet

The following tutorials are based on a. NET core project that you have hosted on GitHub, and if you don't have one, you can fork it yourself or create your own default project.

We open the project.json file in the project that needs to generate the NuGet package, and the related configuration in NuGet can be configured directly through the packoptions section, such as the following:

1   " Packoptions ": {2     " ICONURL ":" https://avatars0.githubusercontent.com/u/16951448?v=3&s= ",3     " Projecturl ":" Https://github.com/Vip56/Sino.FileManager ",4     "Licenseurl": "Https://github.com/Vip56/Sino.FileManager/blob/master/LICENSE"5   }

The pictures displayed in NuGet ("IconUrl"), the project address (" projecturl" ) and the Copyright information ("Licenseurl"), and of course other configuration sections, are configured. We can find out for ourselves.

The above configuration ensures that we eventually generate the corresponding information in the NuGet package, but Appveyor does not support the. NET core project very well by default, so we need to build the project ourselves with the Powersheel script, and we'll start by creating a new name in the project root directory named build.ps1 The file, and then enter the following in the file:

1 functionensurepsbuildinstalled{2 [Cmdletbinding ()]3     param(4[String]$psbuildInstallUri= ' https://raw.githubusercontent.com/ligershark/psbuild/master/src/Getpsbuild.ps1 '5     )6     Process{7         if(-not(Get-command"Invoke-msbuild"-erroraction silentlycontinue)) {8' Installing Psbuild from [{0}] '- F $psbuildInstallUri| write-Verbose9(New-object net.webclient). Downloadstring ($psbuildInstallUri) |IEXTen         } One         Else{ A' Psbuild already loaded, skipping download ' | write-Verbose -         } -  the         #Make sure it's loaded and throw if not -         if(-not(Get-command"Invoke-msbuild"-erroraction silentlycontinue)) { -             Throw(' Unable to install/load psbuild from [{0}] '- F $psbuildInstallUri) -         } +     } - } +  A functionExec at { - [Cmdletbinding ()] -     param( -[Parameter (Position=0,mandatory=1)] [Scriptblock]$cmd, -[Parameter (Position=1,mandatory=0)] [String]$errorMessage= ($msgs. Error_bad_command- F $cmd) -     ) in&$cmd -     if($lastexitcode -ne0) { to         Throw("Exec:"+$errorMessage) +     } - } the  * if(Test-path. \artifacts) {Remove-item. \artifacts-force-Recurse} $ Panax Notoginseng ensurepsbuildinstalled -  theEXEC {&dotnet Restore} +  Ainvoke-MSBuild the  + $revision= @{$true=$env: Appveyor_build_number;$false= 1}[$env: Appveyor_build_number -ne $NULL]; - $revision= [Convert]::toint32 ($revision, 10) $  $ #EXEC {& dotnet test. \test\sino.wilddogclient.tests-c Release} -  -EXEC {& dotnet pack. \src\sino.wilddogclient-c release-o. \artifacts--version-suffix=$revision}

The final part of the:

# EXEC {& dotnet test. \test\sino.wilddogclient.tests-c Release}  & dotnet Pack. \src\sino.wilddogclient-c release-o. \artifacts--version-suffix=$revision }

The test in the I commented out, if the reader needs to be able to remove the previous #, and then modify the following project name, and the last line is to build the NuGet package of the specified project, here also requires the reader according to their actual situation to modify the path of the project, so that the construction part of the instructions are completed.

Since our CI use is appveyor why do we still need to write this script, so that the automatic construction is not useless, it is not, we just manual the build part of the operation, the rest of the other still need to use CI to complete, so we also need to create a new in the root directory appveyor.yml file so that Appveyor will build the project according to our configuration file, which reads as follows:

1 version: ' {build} '2 Branches:3 Only :4 -Master5 Build_script:6 -PS:. \BUILD.PS17 Test:off8 Artifacts:9 -Path:. \artifacts\**\*.nupkgTen Name:nuget One Deploy: A -Provider:nuget - name:production - Api_key: the secure: "Apikey after Encryption" - skip_symbols:true - On : -Branch:master

Can see this part of the script is very simple, just tell CI, we only build the master branch of the submission and PR, and using the build.ps in the project root as the instructions for the build, and also set the NuGet package output folder Separately, artifacts, finally we configure NuGet to upload the master build build NuGet package to the Nuget.org official library, only here basically enough for most of the use, If you need a more DIY to see the official documents, here is another need to be reminded that secure is our NuGet apikey, this data is confidential content, but as an open source project, it will certainly be exposed, Fortunately, Appveyor provides encryption, allowing us to put the encrypted string into it, so it's much safer.

First we log in to our nuget.org account and find the key as shown in the section:

With this original key, we enter this site: https://ci.appveyor.com/tools/encrypt

Encrypt our key and then place the encrypted string in the " " Apikey"" after encryption. So the Appveyor configuration is over. Finally, we can see a lot of open source projects have a lot of tags, such as whether the current build pass, whether support NuGet installation, and so on, we will beautify our readme.md document. The first is the build state, this opens our Appveyor directly and then finds the following menu to see the corresponding markdown format:

For the following, there is a dedicated website that provides support for various types of SVG:

http://shields.io/

Through this site we can see a variety of, first we find the NuGet form, and then click on the following path:

The following dialog box pops up:

The most important of these is the Link parameter, we need to copy the NuGet address of our library into it, the following will generate the corresponding Markdow format of the string, All we have to do is copy these markdown into the readme.md so that a complete open source project is done.

If you appear nuget cannot upload, the display version number does not meet the requirements, you may need to modify version as follows:

1.0.0-release-* or 1.0.0-beta-*

Do not understand the following several open source projects can be consulted:

Https://github.com/Vip56/Sino.FileManager

Https://github.com/Vip56/Sino.WilddogClient

How to use Github+appveyor+nuget to build your own. NET core Open Source Library

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.