.NET HELP

tye .NET (How It Works For Developers)

Published August 13, 2024
Share:

In the modern landscape of software development, building and deploying distributed applications can be complex and challenging. Managing multiple services, dependencies, and deployment environments often requires significant effort and coordination. To address these challenges, Microsoft introduced Project Tye, a developer tool designed to simplify the development, testing, and deployment of .NET applications. In this article, we'll delve into the world of Tye, exploring its features, benefits, and practical applications for .NET developers. We will also learn about IronPDF, a PDF generation library from Iron Software, and use Tye and IronPDF in a practical example.

Understanding Project Tye .NET

Tye is an open-source experimental developer tool that streamlines the process of building, testing, and deploying .NET project applications with minimal configuration. Developed by the Microsoft Engineering team, Tye aims to simplify the development workflow by providing a consistent, opinionated approach to managing microservices and their dependencies. At its core, Tye embraces the principles of containerization, orchestration, and developer productivity to enable seamless application development and deployment.

Key Features of Tye .NET

1. Service Discovery and Dependency Management

Tye automatically detects and manages dependencies between services within a .NET application. It leverages project metadata and Docker containers to infer service relationships, making it easier to coordinate communication and orchestration between microservices. This makes developing microservices easier with multiple projects.

2. Integrated Development Experience

Tye integrates seamlessly with Visual Studio and Visual Studio Code, providing a familiar development environment for .NET developers. It offers tools for debugging, logging, and monitoring application components, enabling rapid iteration and troubleshooting during development.

3. Docker Containerization

Tye embraces Docker containers as the unit of deployment for .NET applications. It automatically generates Dockerfiles for each service based on project configurations, facilitating consistent and reproducible container builds across development and production environments, making testing and deploying microservices easy.

4. Local Development Environment

Tye simplifies local development by orchestrating dependencies and services within a single environment. Developers can spin up the entire application stack with a single command, eliminating the need for manual setup and configuration of dependencies.

5. Deployment to Kubernetes

Tye provides built-in support for deploying .NET applications to Kubernetes clusters. It generates Kubernetes manifests and Helm charts based on project specifications, streamlining the deployment process and promoting best practices for container orchestration in cloud-native environments.

6. Monitoring and Observability

Tye integrates with popular observability tools such as Prometheus and Grafana to provide insights into application performance and health. It exposes metrics and logs from application components, enabling developers to monitor resource utilization, identify bottlenecks, and diagnose issues in real-time.

Practical Applications with Tye

Let's explore some practical scenarios where Tye can streamline .NET application development and deployment:

1. Local Development Environment

# Start Tye in local development mode with tye run command
tye run
# Start Tye in local development mode with tye run command
tye run
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

2. Docker Containerization

Build Docker images for Tye services with available solution file
tye build
Build Docker images for Tye services with available solution file
tye build
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

3. Deployment to Kubernetes

Deploy Tye application to Kubernetes cluster 
tye deploy --interactive // deploy microservices and distributed applications
Deploy Tye application to Kubernetes cluster 
tye deploy --interactive // deploy microservices and distributed applications
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

Getting Started with Tye

To get started with Tye:

  1. Install .NET Core 3.1 (not supported for higher version) on your machine.

  2. Install Tye as a global tool using:
dotnet tool install -g Microsoft.Tye --version "0.2.0-alpha.20258.3"
dotnet tool install -g Microsoft.Tye --version "0.2.0-alpha.20258.3"
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#
  1. Create a new folder for your microservices.

  2. Navigate to the folder and create a frontend project (e.g., Razor Pages):
mkdir microservices
cd microservices
dotnet new razor -n frontend  // frontend service or backend service
mkdir microservices
cd microservices
dotnet new razor -n frontend  // frontend service or backend service
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#
  1. Run the frontend project, the tye dashboard:
tye run frontend  // frontend project or backend project
tye run frontend  // frontend project or backend project
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

This will build, run, and monitor the frontend application. You can access the Tye dashboard at http://localhost:8000 to view the state of your services

Tye's Configuration Schema

Tye has an optional configuration file, tye.yaml, that allows for customization of settings. This YAML file includes all of your projects and external dependencies. If you have an existing solution, Tye will automatically populate it with all of your current projects.

To initialize this YAML file, navigate to the microservices directory and run the following command to generate a default tye.yaml file:

tye init
tye init
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

A tye.yaml file is created as shown below

name: myawesomeapplication
services:
- name: backendtest
  project: backend/backend.csproj
  bindings:
  - port: 7000
- name: frontendtest
  project: frontend/frontend.csproj
  replicas: 2
  bindings:
  - port: 8000
- name: workertest
  project: worker/worker.csproj
- name: rabbit
  image: rabbitmq:3-management
  bindings:
    - port: 5672
      protocol: rabbitmq
YAML

Benefits of Using Tye

  1. Simplified Development Workflow: Tye simplifies the development workflow by providing a unified tool set for building, testing, and debugging .NET applications locally.
  2. Accelerated Time-to-Market: By automating common tasks such as service discovery, dependency management, and containerization, Tye reduces the time and effort required to deploy applications to production environments.
  3. Improved Collaboration: Tye promotes collaboration between development, operations, and DevOps teams by providing a common platform for managing application dependencies and deployment configurations.
  4. Cloud-Native Readiness: Tye equips .NET applications with the necessary tools and practices for running in cloud-native environments, such as Kubernetes, enabling organizations to embrace modern infrastructure paradigms with confidence.
  5. Community Support and Contribution: As an open-source project backed by Microsoft, Tye benefits from a vibrant community of contributors and users who actively contribute to its development, documentation, and ecosystem.

Project Tye License

Project Tye comes with MIT License which is free for use for development and commercial purposes.

Introducing IronPDF

tye .NET (How It Works For Developers): Figure 1 - IronPDF for .NET: The C# PDF Library

IronPDF is a powerful C# library designed for creating, editing, and signing PDFs from HTML, CSS, images, and JavaScript. It offers commercial-grade performance with a low memory footprint.

Key Features of IronPDF

1. HTML to PDF Conversion

Convert HTML files, HTML strings, and URLs to PDFs. For example, render a webpage as a PDF using the Chrome PDF renderer.

2. Cross-Platform Support

Compatible with various .NET platforms, including .NET Core, .NET Standard, and .NET Framework. It supports Windows, Linux, and macOS.

3. Editing and Signing

Set properties, add security with passwords and permissions, and apply digital signatures to your PDFs.

4. Page Templates and Settings

Customize PDFs with headers, footers, page numbers, and adjustable margins. Supports responsive layouts and custom paper sizes.

5. Standards Compliance

Adheres to PDF standards such as PDF/A and PDF/UA. Supports UTF-8 character encoding and handles assets like images, CSS, and fonts.

Now let us see a practice example with these two libraries.

Generate PDF Document Using IronPDF And Tye to Run

First, let's create a Visual Studio Razor application. Open Visual Studio and create a new project and select the razor app as shown below.

tye .NET (How It Works For Developers): Figure 2 - Open Visual Studio and create a new ASP.NET Core Web App (Razor Pages).

Provide the project name and location.

tye .NET (How It Works For Developers): Figure 3 - Configure the project by specifying Project name and Location. Then click on Next.

In the next step, select the .NET Framework version and click on Create. Since Tye works only on .NET 3.1, we will select the same.

tye .NET (How It Works For Developers): Figure 4 - Select the .NET Core 3.1 framework, then click on Create.

Install IronPDF from NuGet Package from Visual Studio Package Manager.

tye .NET (How It Works For Developers): Figure 5 - Install IronPDF using the Manage NuGet Package for Solution by searching IronPDF in the search bar of NuGet Package Manager, then select the project and click on the Install button.

Next, open the File Browser and navigate to the solution folder. Then open the CMD prompt.

Install Tye using the following command:

dotnet tool install -g Microsoft.Tye --version "0.11.0-alpha.22111.1"
dotnet tool install -g Microsoft.Tye --version "0.11.0-alpha.22111.1"
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

OR if you already have Tye installed and want to update it use the below command:

dotnet tool update -g Microsoft.Tye --version "0.11.0-alpha.22111.1"
dotnet tool update -g Microsoft.Tye --version "0.11.0-alpha.22111.1"
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

Initialize Tye using the following command:

tye init
tye init
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

This will create a template YAML file as below:

# tye application configuration file
# read all about it at https://github.com/dotnet/tye
#
# when you've given us a try, we'd love to know what you think:
#    https://aka.ms/AA7q20u
#
# define global settings here
# name: exampleapp # application name
# registry: exampleuser # dockerhub username or container registry hostname
# define multiple services here
services:
- name: frontend
  project: Frontend\Frontend.csproj # msbuild project path (relative to this file)
  # executable: app.exe # path to an executable (relative to this file)
    args: -f=netcoreapp3.1 # arguments to pass to the process
  # replicas: 5 # number of times to launch the application
  # env: # array of environment variables
  #  - name: key
  #    value: value
  # bindings: # optional array of bindings (ports, connection strings)
    # - port: 8080 # number port of the binding
YAML

Run Tye with the following command:

tye run frontend
tye run frontend
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

This will open the Tye dashboard at URL: http://127.0.0.1:8000/ to see the app running.

Tye Dashboard

tye .NET (How It Works For Developers): Figure 6 - Razor application running using Tye on localhost

Next, add the below code to the project to generate a PDF document from any website URL with a click of a button.

Add the below code to the Index.cshtml file:

@page
@model IndexModel
@{
    ViewData["Title"] = "Generate PDF";
}
<form method="post"  class="text-center flex-row">
    <h1 class="display-4">Welcome To Url To PDF Generator </h1>
    <p>Enter Website Url:
    <button type="submit">Generate PDF</button>
    @if (Model.Message != null)
    {
        <p>@Model.Message</p>
    }
</form>
@page
@model IndexModel
@{
    ViewData["Title"] = "Generate PDF";
}
<form method="post"  class="text-center flex-row">
    <h1 class="display-4">Welcome To Url To PDF Generator </h1>
    <p>Enter Website Url:
    <button type="submit">Generate PDF</button>
    @if (Model.Message != null)
    {
        <p>@Model.Message</p>
    }
</form>
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

Then add the below code to Index.cshtml.cs:

using IronPdf;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
namespace Frontend.Pages
{
    public class IndexModel : PageModel
    {
        public string Message { get; set; }
        [BindProperty]
        public string UrlInput { get; set; }
        private readonly ILogger<IndexModel> _logger;
        public IndexModel(ILogger<IndexModel> logger)
        {
            _logger = logger;
        }
        public void OnGet()
        {
        }
        public IActionResult OnPost()
        {
            if (string.IsNullOrEmpty(UrlInput))
            {
                ModelState.AddModelError("UrlInput", "Please enter some text.");
                return Page();
            }
            // Create PDF from ChromePdfRenderer
            var renderer = new ChromePdfRenderer();
            var pdf = renderer.RenderUrlAsPdf(UrlInput);
            // Return the PDF as a file result
            var pdfBytes = pdf.BinaryData;
            return File(pdfBytes, "application/pdf", "GeneratedDocument.pdf");
        }
    }
}
using IronPdf;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
namespace Frontend.Pages
{
    public class IndexModel : PageModel
    {
        public string Message { get; set; }
        [BindProperty]
        public string UrlInput { get; set; }
        private readonly ILogger<IndexModel> _logger;
        public IndexModel(ILogger<IndexModel> logger)
        {
            _logger = logger;
        }
        public void OnGet()
        {
        }
        public IActionResult OnPost()
        {
            if (string.IsNullOrEmpty(UrlInput))
            {
                ModelState.AddModelError("UrlInput", "Please enter some text.");
                return Page();
            }
            // Create PDF from ChromePdfRenderer
            var renderer = new ChromePdfRenderer();
            var pdf = renderer.RenderUrlAsPdf(UrlInput);
            // Return the PDF as a file result
            var pdfBytes = pdf.BinaryData;
            return File(pdfBytes, "application/pdf", "GeneratedDocument.pdf");
        }
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

Now run Tye as below:

tye .NET (How It Works For Developers): Figure 7 - Run type using the command: tye run frontend

This will launch the Tye dashboard.

tye .NET (How It Works For Developers): Figure 8 - Tye Dashboard

Now click on any of the links in the bindings section to open the PDF generator app and enter a sample URL for PDF generation.

tye .NET (How It Works For Developers): Figure 9 - URL to PDF Generator using IronPDF

Click the generate button to get the following PDF as output:

tye .NET (How It Works For Developers): Figure 10 - HTML URL to PDF conversion using IronPDF

Code Explanation

  1. Index.cshtml contains the button and input to take Website URL and Trigger the PDF generation.
  2. Index.cshtml.cs contains the code behind to generate the PDF document using IronPDF.
  3. We use the ChromePdfRenderer class and RenderUrlAsPdf() method to generate the PDF from the URL.
  4. This generated URL is returned as a response to the Post method.
  5. Tye Run command will launch the Tye dashboard where you can see all the running services.
  6. Click on the Frontend service and open the app to generate the PDF documents.

IronPDF License

Visit IronPDF Licensing page.

Place the License Key in the appSettings.json file as shown below:

{
  "IronPdf.License.LicenseKey" : "The Key Here"
}

Conclusion

In conclusion, Tye represents a significant advancement in the .NET ecosystem, offering a streamlined approach to building, testing, and deploying distributed applications. Whether you're a seasoned .NET developer or new to containerization and microservices, Tye provides a user-friendly platform for embracing modern development practices and accelerating your journey toward cloud-native architecture.

IronPDF is a .NET library that allows developers to create, manipulate, and render PDF documents from HTML content easily. It supports converting HTML to PDF, merging and splitting PDFs, and adding headers, footers, and watermarks. IronPDF is known for its ease of use, high-quality rendering, and compatibility with .NET Core and .NET Framework applications. Knowing both the IronPDF library and the Tye build tool, developers can gain advanced skills to develop modern applications with PDF generation capabilities.

< PREVIOUS
C# Nito.Asyncex (How It Works For Developers)
NEXT >
Quartz .NET (How It Works For Developers)

Ready to get started? Version: 2024.12 just released

Free NuGet Download Total downloads: 11,622,374 View Licenses >