How to Use MyGet to Manage and Distribute Packages

MyGet is a universal package manager that allows you to create custom package feeds for Python, Maven, NuGet, npm, Bower, PHP, Vsix, and Ruby Gems.  For me, the most significant advantage of using MyGet is I can overwrite the package with the same version number comparing to other package repositories like PyPi and npmjs. This article shares how to upload Dynamsoft Barcode Reader packages to MyGet and how to install the packages for relevant projects.

myget package manager

Uploading Packages to MyGet

Create a MyGet account.

Sign in to MyGet and create a feed.

myget custom feed

I created a feed for Dynamsoft packages.

The next step is to click ADD PACKAGE to upload relevant packages. I will upload packages for Maven, Python, NuGet, and NPM.

myget package upload

Maven

Upload the pom.xml and .jar files.

maven package

Python

Upload the .whl file.

python package

NuGet

Upload the *.nupkg file.

nuget package

NPM

I failed to upload a zip package when using NPM. Using command-line tool seems more convenient.

Click FEED DETAILS to get your npm feed URL.

npm package

Run the adduser command via command-line tool:

npm adduser --registry=https://www.myget.org/F/dynamsoft/npm/

Publish the package with the new registry:

npm publish  --registry=https://www.myget.org/F/dynamsoft/npm/

Installing Dynamsoft Barcode Reader Packages from MyGet

Get the free trial license.

Maven

Create a Maven project and add the configuration to pom.xml:

<repositories>
    <repository>
      <id>dbr</id>
      <url>https://www.myget.org/F/dynamsoft/maven/</url>
    </repository>
  </repositories>
<dependencies>
    <dependency>
      <groupId>com.dynamsoft</groupId>
      <artifactId>dbr</artifactId>
      <version>7.2.2</version>
    </dependency>
  </dependencies>

Set the license:

BarcodeReader br = new BarcodeReader("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==");         

Sample code:

package com.dynamsoft.demo;

import com.dynamsoft.barcode.*;

public class App {

    public static void main(String[] args) throws Exception {
        System.out.println("Working Directory = " + System.getProperty("user.dir"));
        
        try {
            BarcodeReader br = new BarcodeReader("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==");          

            TextResult[] results = br.decodeFile("../test.jpg", "");
            if (results == null || results.length == 0) {
                System.out.println("No barcode found");
            } 
            else {
                String pszTemp = String.format("Total barcode(s) found: %d.", results.length);
                System.out.println(pszTemp);
                int iIndex = 0;
                for (TextResult result : results) {
                    iIndex++;
                    pszTemp = String.format("  Barcode %d:", iIndex);
                    System.out.println(pszTemp);
                    pszTemp = String.format("    Page: %d", result.localizationResult.pageNumber + 1);
                    System.out.println(pszTemp);
                    pszTemp = "    Type: " + result.barcodeFormatString;
                    System.out.println(pszTemp);
                    pszTemp = "    Value: " + result.barcodeText;
                    System.out.println(pszTemp);

                    pszTemp = String.format("    Region points: {(%d,%d),(%d,%d),(%d,%d),(%d,%d)}",
                            result.localizationResult.resultPoints[0].x, result.localizationResult.resultPoints[0].y,
                            result.localizationResult.resultPoints[1].x,result.localizationResult.resultPoints[1].y,
                            result.localizationResult.resultPoints[2].x,result.localizationResult.resultPoints[2].y,
                            result.localizationResult.resultPoints[3].x,result.localizationResult.resultPoints[3].y);

                    System.out.println(pszTemp);
                    System.out.println();
                }
            }
        } catch (BarcodeReaderException e) {
            e.printStackTrace();
        }
    }
}

Python

Install dbr:

pip install –index-url https://www.myget.org/F/dynamsoft/python/ dbr

Set the license:

dbr.InitLicense(license)

Sample code:

from dbr import DynamsoftBarcodeReader
dbr = DynamsoftBarcodeReader()

def InitLicense(license):
    dbr.InitLicense(license)

def DecodeFile(fileName):
    try:
        results = dbr.DecodeFile(fileName)
        textResults = results["TextResults"]
        resultsLength = len(textResults)
        print("count: " + str(resultsLength))
        if resultsLength != 0:
            for textResult in textResults:
                print(textResult["BarcodeFormatString"])
                print(textResult["BarcodeText"])
                localizationResult = textResult["LocalizationResult"]
                x1 = localizationResult["X1"]
                y1 = localizationResult["Y1"]
                x2 = localizationResult["X2"]
                y2 = localizationResult["Y2"]
                x3 = localizationResult["X3"]
                y3 = localizationResult["Y3"]
                x4 = localizationResult["X4"]
                y4 = localizationResult["Y4"]
                localizationPoints = [(x1,y1),(x2,y2),(x3,y3),(x4,y4)]
                print(localizationPoints)
        else :
            print("No barcode detected")
    except Exception as err:
        print(err)

if __name__ == "__main__":

#you can change the following three variables' value to your own value.
    licenseKey = "Input your own license"
    fileName = r"../test.jpg"
    InitLicense(licenseKey)
    DecodeFile(fileName)

NuGet

In Visual Studio 2017, add the package source https://www.myget.org/F/dynamsoft/api/v3/index.json.

nuget feed

Install the package to your .NET project.

nuget install

Set the license:

mBarcodeReader = new BarcodeReader("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==");

Sample code:

                    pictureBox1.Image = bitmap;
                    textBox1.Clear();

                    this.Invoke((MethodInvoker)delegate
                    {
                        string[] results = mBarcodeReaderManager.ReadBarcode(bitmap);
                        if (results != null)
                        {
                            foreach (string result in results)
                            {
                                textBox1.AppendText(result);
                                textBox1.AppendText(Environment.NewLine);
                            }
                        }
                        else
                        {
                            textBox1.AppendText("No barcode detected!");
                        }
                        
                    });

NPM

Install dynamsoft-javascript-barcode via the custom registry:

npm set registry https://www.myget.org/F/dynamsoft/npm/
npm install dynamsoft-javascript-barcode

Set the license:

Dynamsoft.DBR.BarcodeReader.license = "DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==";

Sample code:

<!DOCTYPE html>
<html>

<body>
    <script src="https://code.jquery.com/jquery-3.4.1.js"></script>
    <script src="node_modules/dynamsoft-javascript-barcode/dist/dbr.js"></script>
    <input id="uploadImage" type="file" accept="image/bmp,image/jpeg,image/png,image/gif">
    <p id="results"></p>

    <script>
        Dynamsoft.DBR.BarcodeReader.license = "DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==";
        document.getElementById('uploadImage').addEventListener('change', async function () {
            $("#results").empty();
            var files = this.files;
            let reader = await Dynamsoft.DBR.BarcodeReader.createInstance();
            let results = await reader.decode(files[0]);
            if (results.length == 0) {
                $("#results").append('No barcode detected!');
                return;
            }
            for (let result of results) {
                console.log(result.barcodeText);
                $("#results").append(result.barcodeText);
            }
        });
    </script>

</body>

</html>

Source Code

https://github.com/yushulx/myget-barcode-sample