This documentation outlines a step-by-step guide on how to build and start the stevedunn/vogen project. The instructions cover the necessary setup using C#, PowerShell, and Docker.

Prerequisites

  1. Ensure you have .NET SDK installed. Verify the installation using:

    dotnet --version
    
  2. Install Docker if using containerization.

  3. Ensure that PowerShell is available if you are using Windows.

Step 1: Clone the Repository

Clone the stevedunn/vogen repository to your local machine using the following command:

git clone https://github.com/stevedunn/vogen.git
cd vogen

Step 2: Set Execution Policy (Windows only)

If using PowerShell on Windows, you may encounter an execution policy error. To bypass this, execute:

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

This command allows the execution of scripts for the current session, preventing any permanent changes to your system’s execution policy.

Step 3: Restore Dependencies

Within the project directory, restore the necessary dependencies:

dotnet restore

This command downloads and installs the required NuGet packages specified in the project files.

Step 4: Build the Project

Now that dependencies are restored, build the project using:

dotnet build

The build process compiles the code, and any build artifacts are generated in the bin directory of the respective projects.

Step 5: Start the Project

You may start the Vogen project through the following command:

dotnet run --project src/Vogen/Vogen.csproj

This command executes the specified project, starting the application.

Step 6: Docker Setup (Optional)

If you prefer running the project using Docker, ensure you navigate to the Dockerfile directory and build the Docker image:

docker build -t vogen-image .

Once the image is built, you can run it using:

docker run -d --name vogen-container vogen-image

This command starts a new container instance from the previously created Docker image in detached mode.

Step 7: Verify the Operation

After executing the project or the Docker container:

  1. Check console output for logs indicating the application has started successfully.
  2. Access any defined endpoints or test functionalities as needed.

Additional Code Examples

  • Build Configuration from Attributes: The following snippet demonstrates handling attribute data for configuration within the build process.

    if (i == 8)
    {
        _fromPrimitiveCasting = (CastOperator) v;
    }
    
  • Instance Properties Construction: This section showcases how instance properties are constructed from attributes.

    private static InstanceProperties? Build(AttributeData matchingAttribute,
                                              SourceProductionContext context,
                                              INamedTypeSymbol voClass,
                                              INamedTypeSymbol underlyingType)
    {
        // Implementation for constructing properties
    }
    
  • Entity Creation and Saving in EF Core: For those integrating with EF Core, here is a sample of how to add items to the database context.

    static void AddAndSaveItems(int amount)
    {
        using var context = new DbContext();
    
        for (int i = 0; i < amount; i++)
        {
            var entity = new PersonEntity
            {
                Name = Name.From("Fred #" + i),
                Age = Age.From(42 + i)
            };
            
            context.Entities.Add(entity);
        }
    
        context.SaveChanges();
    }
    

By following these steps, you will be able to build and start the stevedunn/vogen project effectively.