Coder Social home page Coder Social logo

phil-harmoniq / netpkg-tool Goto Github PK

View Code? Open in Web Editor NEW
14.0 2.0 3.0 3.8 MB

Bundle .NET Core applications into convenient Linux binaries.

License: MIT License

Shell 18.50% C# 81.50%
linux appimage csharp dotnet dotnet-core dotnet-standard dotnet-cli appdir fdd scd

netpkg-tool's Introduction

netpkg-tool Build Status License

Download

Released Binary

Pre-packaged versions of netpkg-tool are available from the releases tab:

# Github releases are tagged with their version (ex: 0.3.10)
wget https://github.com/phil-harmoniq/netpkg-tool/releases/download/0.3.10/netpkg-tool
chmod a+x ./netpkg-tool

# Place netpkg-tool somewhere on your $PATH (Optional)
mv ./netpkg-tool ~/.local/bin

Docker Image

netpkg-tool is also available as a Docker image if you don't want to install any dependencies:

# Pull the latest netpkg-tool Docker image
docker pull philharmoniq/netpkg-tool

For more information, see the Docker README.

Build From Source

To build netpkg-tool from source, run build.sh and specify a destination folder:

git clone https://github.com/phil-harmoniq/netpkg-tool
./netpkg-tool/build.sh ~/Desktop

Examples

Packaging a simple "Hello World" app:

git clone https://github.com/phil-harmoniq/Hello
netpkg-tool Hello ~/Desktop
~/Desktop/Hello one two three

Packaging a default ASP.NET Core MVC template:

dotnet new mvc -n aspnet-src
netpkg-tool aspnet-src . -n aspnet-pkg
./aspnet-pkg

Optional Flags

ASP.NET

ASP.NET is picky about where its content root directory is located. By default, it searches for wwwroot in Directory.GetCurrentDirectory(). Using netpkg-tool on an unmodified ASP.NET project will result in your web app being unable to locate any of its assets. A simple workaround would be to check for the existence of an environment variable set by netpkg-tool, like $NET_PKG, and setting the content directory to the Assembly location if it exists. This will allow the project's content to be found regardless of whether it's packaged up or being run with dotnet run. Example:

public class Program
{
    public static void Main(string[] args)
    {
        var assembly = Assembly.GetExecutingAssembly().Location;
        var pkgEnv = Environment.GetEnvironmentVariable("NET_PKG");

        if (string.IsNullOrEmpty(pkgEnv))
            BuildWebHost(args, Directory.GetCurrentDirectory()).Run();
        else
            BuildWebHost(args, Path.GetDirectoryName(assembly)).Run();
    }

    public static IWebHost BuildWebHost(string[] args, string root) =>
        WebHost.CreateDefaultBuilder(args)
            .UseContentRoot(root)
            .UseStartup<Startup>()
            .Build();
}

Details

Using netpkg-tool will restore and compile your project based on settings in your *.csproj file. By default, netpkg-tool will use Framework Dependent Deployment to compile your project. To use Self-Contained Deployment, use the --scd flag. The full process for netpkg-tool:

  1. Restore project dependencies
  2. Compile .NET Core app
  3. Create AppDir and transfer files
  4. Run appimagetool on created AppDir
  5. Delete temporary files

Dependencies

  • .NET Core 2.0 SDK: Per-distro RID tags were replaced with the universal linux-x64 RID, simplifying the Linux build process. Earlier versions should work with netpkg-tool but only using Framework Dependent Deployment.
  • appimagetool: (Included) Bundles Linux applications into AppImages, currently utilizes version 9 of appimagetool.
  • Shell.NET: (Included) .NET Standard library for interacting with Bash.

Contributing

If you have a feature request or issue, feel free to submit an issue. A pull request would be even better! Pull requests should target the develop branch.

Mono

While this project is mainly aimed at Microsoft's new .NET Core ecosystem, it should be possible to eventually make this tool work with Mono. Mono support is planned but no exact ETA can be given until the core utility is in a more stable state.

Disclaimer

The netpkg-tool project is still in alpha development. Names, commands, and features are subject to change. Please keep this in mind when using this utility.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.