Create MS Project converter for .NET 5.0  in 5 steps
Tags: csharp, netcore, msproject, excel
Published: 2021-04-16 05:24:52

## Writing the Microsoft Project Converter

[Aspose.Tasks](https://products.aspose.com/tasks) is one of the leading C#/Java/C++ on-premises API for Microsoft Project/Primavera project management file processing. And today I want to show how to develop your own .NET MS Project converter (commonly misspelled as "MS Project convertor") in just a few steps.

### Step 1. Creating a new .NET Core Console App
Let's create a new C# project and add Aspose.Tasks for .NET NuGet package:
```
mkdir MSProjectConverter && cd MSProjectConverter
```
```
dotnet new console && dotnet add package Aspose.Tasks
```
### Step 2. Writing a Converter
The next step is to implement the converter class that uses Aspose.Tasks as a converter engine:
``` csharp
namespace MSProjectConverter
{
    using System.IO;

    using Aspose.Tasks;
    using Aspose.Tasks.Saving;

    public class MppToExcelConverter
    {
        public MemoryStream ConvertToXlsx(Project project)
        {
            MemoryStream stream = new MemoryStream();
            project.Save(stream, SaveFileFormat.XLSX);
            return stream;
        }

        public MemoryStream ConvertToSpreadsheet2003(Project project)
        {
            MemoryStream stream = new MemoryStream();
            project.Save(stream, SaveFileFormat.Spreadsheet2003);
            return stream;
        }

        public MemoryStream ConvertToCsv(Project project)
        {
            MemoryStream stream = new MemoryStream();
            project.Save(stream, SaveFileFormat.CSV);
            return stream;
        }
    }
}
```

### Step 3. Using the Converter
Use the converter in user code:
``` csharp
namespace MSProjectConverter
{
  using System;
  using System.IO;

  using Aspose.Tasks;

  public static class Program
  {
    public static void Main(string[] args)
    {
      if (args.Length < 3)
      {
        throw new 
          ArgumentException(
            "At least 3 arguments must be passed.");
      }

      string mppPath = args[0];
      string type = args[1];
      string outPath = args[2];

      Project project = new Project(mppPath);
      MppToExcelConverter converter = new MppToExcelConverter();

      MemoryStream stream = null;
      try
      {
        
        switch (type)
        {
          case "XLSX":
            stream = converter.ConvertToXlsx(project);
            break;
          case "XML":
            stream = converter.ConvertToSpreadsheet2003(project);
            break;
          case "CSV":
            stream = converter.ConvertToCsv(project);
            break;
          default:
            throw new 
             ArgumentException("The conversion type is unknown.");
        }

        File.WriteAllBytes(outPath, stream.ToArray());
      }
      finally
      {
        if (stream != null)
        {
          stream.Dispose();
        }
      }

      Console.WriteLine(
        "The file " + 
        $"{Path.GetFileName(mppPath)} was successfully " + 
        "converted to " + 
        $"{Path.GetFileName(outPath)}.");
    }
  }
}
```
### Step 4. Build the Console App
Let's build the project:
```
dotnet build
```
### Step 5. Using MPP to Excel converter
Try to use the converter app and convert project to Excel, e.g. to CSV format:
```
MSProjectConverter.exe example.mpp CSV example.csv
```

The output is:
```
The file example.mpp was successfully converted to example.csv.
```

Presented below are the input MPP file and the output CSV file:
![ms project convertor](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zxb1qvhv2zs8u0f488w4.png)

![mpp to excel converter](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xu60o7z4eev5u4mo9jgw.png)

The created application can be found [here](https://github.com/alexander-efremov/Aspose.Tasks.Excel.Converter).

If you would like to take more control over MPP to Excel export e.g. apply custom filters for CSV export or customize the exported data fields (columns) for XLSX export then you can refer to our [conversion guide](https://docs.aspose.com/tasks/net/convert-ms-project-to-excel/).

## How to convert MS Project to Excel Online
You can try our free web [conversion apps](https://products.aspose.app/tasks/conversion) to convert MPP to Excel or to 10+ other [file formats](https://docs.aspose.com/tasks/net/supported-file-formats/) - these applications use the up-to-date version [Aspose.Tasks for .NET](https://products.aspose.com/tasks/net) under the hood.