Skip to content

This package is intended to build Autodesk PackageContent.xml using C# fluent API.

License

Notifications You must be signed in to change notification settings

ricaun-io/Autodesk.PackageBuilder

Repository files navigation

Autodesk.PackageBuilder

This package is intended to build Autodesk PackageContent.xml and RevitAddin.addin using C# fluent API.

Autodesk Revit

Visual Studio 2022 Nuke License MIT Build Release

Examples

Create PackageContents.xml

To get the PackageContents.xml like this:

<?xml version="1.0" encoding="utf-8"?>
<ApplicationPackage SchemaVersion="1.0" ProductType="Application" AutodeskProduct="Revit" Name="RevitAddin" AppVersion="1.0.0">
  <CompanyDetails Name="Company Name" Email="email" Url="url" />
  <Components Description="Revit 2021">
    <RuntimeRequirements OS="Win64" Platform="Revit" SeriesMin="R2021" SeriesMax="R2021" />
    <ComponentEntry AppName="RevitAddin" ModuleName="./Contents/2021/RevitAddin.addin" />
  </Components>
  <Components Description="Revit 2022">
    <RuntimeRequirements OS="Win64" Platform="Revit" SeriesMin="R2022" SeriesMax="R2022" />
    <ComponentEntry AppName="RevitAddin" ModuleName="./Contents/2022/RevitAddin.addin" />
  </Components>
</ApplicationPackage>

Inherit your builder class from PackageContentsBuilder base class.

public class DemoPackageBuilder : PackageContentsBuilder
{
    public DemoPackageBuilder()
    {
        ApplicationPackage
            .Create()
            .ProductType(ProductTypes.Application)
            .AutodeskProduct(AutodeskProducts.Revit)
            .Name("RevitAddin")
            .AppVersion("1.0.0");

        CompanyDetails
            .Create("Company Name")
            .Email("email")
            .Url("url");

        Components
            .CreateEntry("Revit 2021")
            .OS("Win64")
            .Platform("Revit")
            .SeriesMin("R2021")
            .SeriesMax("R2021")
            .AppName("RevitAddin")
            .ModuleName(@"./Contents/2021/RevitAddin.addin");

        Components
            .CreateEntry("Revit 2022")
            .RevitPlatform(2022)
            .AppName("RevitAddin")
            .ModuleName(@"./Contents/2022/RevitAddin.addin");
    }
}

Or use BuilderUtils.Build<PackageContentsBuilder>().

var builder = BuilderUtils.Build<PackageContentsBuilder>(builder =>
{
    builder.ApplicationPackage
        .Create()
        .ProductType(ProductTypes.Application)
        .AutodeskProduct(AutodeskProducts.Revit)
        .Name("RevitAddin")
        .AppVersion("1.0.0");

    builder.CompanyDetails
        .Create("Company Name")
        .Email("email")
        .Url("url");

    builder.Components
        .CreateEntry("Revit 2021")
        .OS("Win64")
        .Platform("Revit")
        .SeriesMin("R2021")
        .SeriesMax("R2021")
        .AppName("RevitAddin")
        .ModuleName(@"./Contents/2021/RevitAddin.addin");

    builder.Components
        .CreateEntry("Revit 2022")
        .RevitPlatform(2022)
        .AppName("RevitAddin")
        .ModuleName(@"./Contents/2022/RevitAddin.addin");
});

Getting results

String result

var builder = new DemoPackageBuilder();
var result = builder.ToString();

.xml file

var builder = new DemoPackageBuilder();
builder.Build("PackageContents.xml");

// or

BuilderUtils.Build<DemoPackageBuilder>("PackageContents.xml");

// or

BuilderUtils.Build<DemoPackageBuilder>("PackageContents.xml", builder => {...});

// or

BuilderUtils.Build<DemoPackageBuilder>(builder => {...}, "PackageContents.xml");

// or

BuilderUtils.Build<DemoPackageBuilder>(builder => {...}).Build("PackageContents.xml");

Create RevitAddin.addin

To get the RevitAddin.addin like this:

<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
  <AddIn Type="Application">
    <Name>RevitAddin</Name>
    <AddInId>11111111-2222-3333-4444-555555555555</AddInId>
    <Assembly>RevitAddin.dll</Assembly>
    <FullClassName>RevitAddin.App</FullClassName>
    <VendorId>RevitAddin</VendorId>
    <VendorDescription>RevitAddin</VendorDescription>
  </AddIn>
</RevitAddIns>

Inherit your builder class from RevitAddInsBuilder base class.

public class DemoAddinBuilder : RevitAddInsBuilder
{
    public DemoAddinBuilder()
    {
        AddIn.CreateEntry("Application")
            .Name("RevitAddin")
            .AddInId("11111111-2222-3333-4444-555555555555")
            .Assembly("RevitAddin.dll")
            .FullClassName("RevitAddin.App")
            .VendorId("RevitAddin")
            .VendorDescription("RevitAddin");
    }
}

Or use BuilderUtils.Build<RevitAddInsBuilder>().

var builder = BuilderUtils.Build<RevitAddInsBuilder>(builder =>
{
    builder.AddIn.CreateEntry("Application")
        .Name("RevitAddin")
        .AddInId("11111111-2222-3333-4444-555555555555")
        .Assembly("RevitAddin.dll")
        .FullClassName("RevitAddin.App")
        .VendorId("RevitAddin")
        .VendorDescription("RevitAddin");
});

Getting results

String result

var builder = new DemoAddinBuilder();
var result = builder.ToString();

.addin file

var builder = new DemoAddinBuilder();
builder.Build("RevitAddin.addin");

// or

BuilderUtils.Build<DemoAddinBuilder>("RevitAddin.addin");

// or

BuilderUtils.Build<DemoAddinBuilder>("RevitAddin.addin", builder => {...});

// or

BuilderUtils.Build<DemoAddinBuilder>(builder => {...}, "RevitAddin.addin");

// or

BuilderUtils.Build<DemoAddinBuilder>(builder => {...}).Build("RevitAddin.addin");

Package Inspiration / Reference

This package was inspared by InnoSetup.ScriptBuilder package.

License

This package is licensed under the MIT Licence.


Do you like this package? Please star this project on GitHub!