1. Origin
In our project, the components to be referenced are stored in the same libs directory. This is true for public components and application modules on the platform.
If an application module, such as Energy Management (EM), must reference the public components provided by the platform, such as the database access (platform. PL), not only must platform. when PL assembly is copied to the libs directory of EM, platform must also be copied. the Assembly referenced by Pl, that is, platform. copy the files in the libs directory of PL to the libs directory of em.
With the increase of application modules on the platform, more and more platform. pl are referenced. How do we assign platform. pl itself and its libs assembly to these application modules? Is manually copied.
So the question is: What should I do if platform. pl is upgraded? The answer is: you can only copy them one by one.
This method is quite old, and it is prone to errors due to manual copying. It is best to place the shared components on the server. When the application module is referenced or upgraded, the shared components will be downloaded or updated on the server. In fact, the industry has been doing this for a long time, that is, using nuget to obtain the assembly. However, these assemblies are generally public, such as nhib.pdf and spring. net. We can use the nuget mechanism and place the shared assembly on the internal server.
Therefore, what we will introduce here is not how to use nuget to manage the Assembly used by a solution, but how to put our self-developed public components on internal servers, download and update other modules.
Let's talk about the development environment, of course. net, and Visual Studio version 2012. The nuget Package Manager is installed by default in this version.
2. Prepare the assembly to be released
After the public components are developed, some preparation work is required to publish them to the nuget server.
0. Download nuget.exe.The address is here. This is a console program and will be run in the command line later. After the download, place it in a proper location and point it to the path. Of course, this file only needs to be downloaded once.
1. Create a configuration file.Open the command line program, enter the folder of the project where the public component is located, and run nuget spec. As shown below:
This will create a file: Platform. pl. nuspec. Open this file and you will see this:
<?xml version="1.0"?><package > <metadata> <id>$id$</id> <version>$version$</version> <title>$title$</title> <authors>$author$</authors> <owners>$author$</owners> <licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl> <projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl> <iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>$description$</description> <releaseNotes>Summary of changes made in this release of the package.</releaseNotes> <copyright>Copyright 2014</copyright> <tags>Tag1 Tag2</tags> </metadata></package>
Some of the content is not required. You can delete it. You can delete all licenseurl, projecturl, and iconurl. It prompts us to delete them. Releasenotes and tags must be modified. Otherwise, a warning will appear in the next step.
For example, I changed this file to the following:
<? XML version = "1.0"?> <Package> <metadata> <ID> $ ID $ </ID> <version> $ version $ </version> <title> $ title $ </title> <authors> $ author $ </authors> <owners> $ author $ </owners> <requirelicenseacceptance> false </requirelicenseacceptance> <description >$ description $ </description> <releasenotes> mes platform database the access component is released to the nuget server for the first time </releasenotes> <copyright> copyright 2014 </Copyright> <tags> mes platform database access </tags> </metadata> </package>
2. Package.On the command line interface above, run the nuget pack, as shown below:
In this way, a file platform. pl. XYZ. nupkg is created. This is the package we will release to the nuget server.
One case is worth mentioning: for some reason, we have to use the spring.net pre-release version (pre-release ). Curious? This is because spring.net uses a dictionary in concurrency, which is not thread-safe and causes problems during runtime. Spring.net solved this problem in the pre-release version 2.0.0-RC1, but there is no stable version yet, so we will use this pre-release version. Nuget has a rule: if an unstable version of the Assembly is used, the published assembly cannot be a stable version. Otherwise, the following error occurs during packaging:
To do this, we need to set the package we want to release to a Beta or pre-release version by manually editing the properties/assemblyinfo. CS file of the project:
The 36 rows are included.
3. Release the assembly to the internal server.
After the previous step, we generated the package to be released: Platform. pl.3.1.0-Alpha. nupkg. This package can be published to the public nuget server for everyone to download. But now we don't want to do this. We just release it to the internal server for internal use only within the project team.
To do this, we must first create a website and use the conventional method to create an IIS website. You can name this website nugetserver.
Next, we need to create a web application. Use vs to create an ASP. NET empty web application. You can name this project nugetserver.
Again, in this application, use nuget to add nuget. server package reference:
After the nuget. server package is referenced, many packages referenced by the nuget. server package are automatically added.
Again, add the newly created platform. pl.3.1.0-Alpha. nupck file to the packages folder of this web project:
Finally, publish the application to the website nugetserver.
After the release is successful, open the website and you will see something like this:
4. Reference assembly
After the Assembly is successfully published on the internal nuget server, it can be referenced in the application module. Before referencing the application module, you also need to make preparations: add the server to the nuget configuration.
In vs 2012, choose menu tool> nuget Package Manager> nuget package for solution management. In the displayed dialog box, click "set" in the lower left corner, the "options" dialog box is displayed. Click the plus sign in the upper right corner to add the "available package source". The address indicated by IE, such as http: // localhost: 8010/nuget, add it. The name can be MES:
So far, we can download our own Assembly from the internal nuget server just like downloading the Assembly from the public nuget server.
5. Others
This post is titled "pre-release version", indicating that this practice has just passed the experiment. If it is used, it should face many unexpected problems. Even so, it is recommended.
It is recommended that our project team:
1. Abandon using libs to manage referenced assembly and switch to nuget to download assembly;
2. Build a unified nuget server on the MES platform;
3. Public components are released to the nuget server in a unified manner, and the version number is set by referring to the semantic version method.
Zookeeper
Use nuget to manage our assembly-prerelease