[Xamarin.android] release of NuGet Suite preface
In Xamarin, you can package your own project as a NuGet suite and publish it to NuGet Server for other developers to use. This article describes how to encapsulate and publish a NuGet suite so that developers can build their own NuGet suite in NuGet server, leaving a record for themselves and hoping to help developers in need.
Packaging
-
The program code that will be encapsulated into the NuGet suite is first created as a class Library (Android) type project. The DLL file that gets output after the project is compiled, which is the shared component that is to be encapsulated into the NuGet suite for use by other developers. In this case, you need to put the DLL file in a package folder for backup.
-
Then go to the NuGet website to download the NuGet.exe to encapsulate the NuGet suite, which will also put NuGet.exe in the package folder.
- Http://docs.nuget.org/docs/start-here/installing-nuget
-
In the package folder where DLL files and NuGet.exe are stored, use the Notepad application to add a text file with the extension nuspec, and add the following XML format data to the content.
<?xml version="1.0"?><package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"> <metadata> <id>CustomControlSample</id> <version>1.0.0</version> <title>CustomControlSample</title> <authors>Clark</authors> <owners>Clark</owners> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>CustomControlSample</description> <copyright>Copyright © 2014</copyright> <dependencies> </dependencies> </metadata> <files> <file src="CustomControlSample.dll" target="lib\MonoAndroid" /> </files></package>
The Nuspec file with the extension NUSPEC is an XML-formatted text file that describes the NuGet suite information. Some of the more important information is labeled as follows:
- ID: number.
- Version: Versions.
- Title: Name.
- Authors: Author
- Owners: Owned by
- Description: Description
- Copyrights: Copyright Announcement
- Files: Shared Components collection
- File: Shared Components
One of the more important things to note here is the file tag. The SRC parameter contents of the file volume label, which defines the file name and file path of the shared component. The target parameter content of the other file tag is the platform that defines the shared component. (target platform is xamarin.android content is lib\monoandroid, target platform is xamarin.ios content is Lib\monotouch)
<files> <file src="CustomControlSample.dll" target="lib\MonoAndroid" /></files>
-
Then open the command prompt character, according to the following execution parameters, to perform the previously obtained standby NuGet.exe. With this execution parameter setting, the NuGet.exe will establish a NuGet wrapper file with the extension nupkg according to the package information described in the Nuspec file. A nupkg file with the extension nupkg was built, and the entire NuGet suite package was completed.
NuGet.exe pack CustomControlSample.nuspec
Release
After creating the Nupkg file through NuGet.exe, the packaged NuGet package is then published to the NuGet Server. There are many ways to publish a suite to NuGet server, and NuGet server can be divided into NuGet official servers, private enterprise Servers ... Wait a minute. The example in this article shows you how to publish a NuGet suite to the NuGet official server through the features of the NuGet official website.
-
Open the NuGet website and enter the upload package feature page after login.
- Https://www.nuget.org/packages/upload
-
Click the "Select Profile" button on the page, and select the Nupkg file that you previously established through NuGet.exe, then click the "upload" button to upload the file.
-
After uploading the nupkg file, the page displays the contents of the NuGet suite information that is currently uploaded. If you find that the information is incorrect, you can edit it directly on this page. Once you have confirmed the content of the message, you can click the "submit" button at the bottom of the page to publish the NuGet suite.
-
The process of releasing a NuGet suite is a bit longer, and it takes a bit of patience to see the release of the NuGet Suite home page.
Use
After releasing the NuGet suite to the NuGet official server, other developers can download and use the NuGet suite through the NuGet Suite management tool in the Xamarin.android project.
-
In the Xamarin.android project, right-click the project and select "Manage NuGet Suite ..." To open the NuGet Suite management tool.
-
In the NuGet Suite management tool, enter the name of the previously released NuGet suite, which you can find in the administrative tools.
-
Then click on the "Install" button on the kit to download the NuGet kit and install it to Xamarin. Android Project.
-
Later in the Xamarin.android project, you can use the categories provided by the NuGet suite directly.
Sample Download
Sample program code: Click here to download
[Xamarin.android] Release NuGet Suite