Showing posts with label 開發流程. Show all posts
Showing posts with label 開發流程. Show all posts

Wednesday, June 13, 2018

[ProGet] Setup NPM registry and publish package


  ProGet    NPM Package  





▌Introduction


We are going to create a NPM registry by ProGet and learn how to publish and install packages from it.



▌Environment


▋ProGet 5.0.11
▋Windows Server 2008 R2
▋NPM 6.1.0



▌Setup PorGet’s NPM registry


▋Create new feed

Go to Feeds and click 【Create New Feed】, then create one Feed for NPM.






After the Feed is created, take a look at it and copy the API endpoint URL:


In this example, it is “http/myserver/npm/mynpm/”, which is also the URL of our NPM registry.





▋Set scoped registry for npm

Register a scoped registry like this to .npmrc

$ npm config set @myscope:registry http://myserver/npm/feedName/

Scope name can be your unique name or organization name.
I will register a registry which has a scope named “JB”.

Open .npmrc by

$ npm config edit


You will see the scoped registry is appended to the file.





▋Set ProGet’s login user for the registry

Now close the .npmrc. We will add the permission for it with ProGet’s default user: “Admin”.

$ npm adduser --registry=http://myserver/npm/feedName/ --scope=@myscope


Don’t miss the last slash “/” in the URL of registry!
I encountered the following problem just because of it, and was stuck for 2 hours. lol


npm add user, will fail with error:
npm ERR! 404 Registry returned 404 for PUT on http://myserver/npm/-/user/org.couchdb.user:admin



If everything is cool, you will get the following logined message.



Now open .npmrc again to check the updated information for your registry.




▌Upload or Publish NPM package


▋Prepare your awesome package

Since we use a scoped registry, it’s recommend to name you package with the mapping scope.
You can name the package with a scope name by

$ npm init --scope=@myscope

Which will make the package’s name in package.json looked like this,

{
  "name": "@myscope/awesome-pkg",
}




▋Upload thru ProGet

We can zip the package and upload it through PorGet’s website.
Notice that the supported file must be zipped as tar.gz.


▋Zip your awesome package

I use 7.zip for example. First zip the folder as .tar




Then zip the .tar as .tar.gz




▋Upload

Go to ProGet’s Feed page, and click on 【Add Package】



Choose 【Upload npm Package】






If you get the below error message, check the zipped format.




▋Publish thru npm

A better way is using npm cli.

▋Update package.json

Add the following publish config to package.json, in order to force publishing to our private registry. (See reference)

"publishConfig":{"registry":"http://myserver/npm/feedName/"}


▋Add .npmignore (Optional)

If you wanna to skip some folders or files while publishing the package.
Add the .npmignore in root path to ignore them. (See reference)


▋Publish

$ npm publish




▌Install NPM package


Congrates! We finally successfully upload our own awesome package.
Now it’s easy to install it thru npm.



Enjoy it!


▌Reference






Thursday, April 12, 2018

[ProGet] Installation tips and Setup (NuGet)


  ProGet    Nuget Package  




▌Introduction


We will learn some tips for installing and setting ProGet and upload first nuget package to it.



▌Environment


▋ProGet 5.0.11
▋Windows Server 2008 R2



▌Installation


▋Download



▋Install

Before you start the installation, create a new database in SQL Server.
Run the .exe and follow the official installation guide.




▋Trouble shooting

When installing ProGet, I encountered the following error.

The database could not be exclusively locked to perform the operation.
ALTER DATABASE failed. Cannot set database XXX’s default collation as SQL_Latin1_General_CP1_CI_AS

System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   於 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   於 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   於 System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
   於 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   於 System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   於 Inedo.ProGet.Setup.InstallProGetTask.CheckCreateDB()
   於 Inedo.ProGet.Setup.InstallProGetTask.Install()
   於 Inedo.Installer.InstallationTask`1.Inedo.Installer.IInstallationTask.RunInternal()
ClientConnectionId:59abd9f0-3013-4b14-be74-1f8e3344e424
Error Number:5030,State:2,Class:16






One of the solution is to set the database to single user manually.

ALTER DATABASE [Your_DbName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE


PS. Don’t forget to set it back as MULTI_USER after installation.

ALTER DATABASE [Your_DbName] SET MULTI_USER WITH ROLLBACK IMMEDIATE



However, it didn’t work for me.
I finally solved this issue by manually executing the ALTER DATABASE sql like this,

ALTER DATABASE [DbName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE

ALTER DATABASE [DbName]
COLLATE SQL_Latin1_General_CP1_CI_AS ;
GO

ALTER DATABASE [DbName] SET MULTI_USER WITH ROLLBACK IMMEDIATE


Done!




▌Setup and upload a NuGet package



▋Setup

Now open http://server-name:8624 and login as Admin. (Default ID/PWD: Admin/Admin)


Then create a new Feed



Select NuGet as following.



For more information about setting the Feed, see document.


Since we have a Feed, create an api key for it.







▋Upload a nupkg package

Use either of the following ways to upload a NuGet package.

2.      NuGet CLI

▋NuGet Package Explorer

【FILE】→【Publish】

Publish Url: http://server-name/nuget/Feed-name/
Publish key: The API key




▋NuGet CLI

$ nuget push MyPackage.nupkg -ApiKey XXXXXXXXX -source http://server-name/nuget/Feed-name/



Now you can add the NuGet package Feed (http://server-name/nuget/Feed-name/)
into Visual Studio: Package Sources.


Enjoy it!



▌Reference