Table of Contents

Project Structure

This article describes how to work with projects and setting up a workflow for publishing changes

When creating a project structure, it's worth considering whether the project is going to have custom code, or whether customizations are exclusive to the Files folder, i.e., templates and item types.

The basics of the project structure is simple:

  1. Have a solution with a host application
  2. Add projects for the various features that you need

So, if you don't need any custom code -- like notification subscribers or screen injectors -- you can disregard those projects.

This is an illustration of the project structure of a project containing customizations for both Files and custom code.

- MyCustomerProject
  - MyCustomerProject.CustomCode
  - MyCustomerProject.Files
  - MyCustomerProject.Host

Take note of the Host project. This one is a little special as it's necessary only to run the solution locally. If the solution is hosted in DynamicWeb Cloud, this project is never deployed. If the solution is used in a CI/CD setup, you may need to create a clean host as well. This is discussed more in the article about Working with CI/CD.

Creating the solution file

There are a couple of ways to create the solution file. You can either use an IDE, e.g., Visual Studio, VS Code or Rider, or you can use the dotnet cli. In this example, we'll use the dotnet cli to create all our projects and create the relevant references. In the following examples, it's assumed that the solution we're creating is called MyCustomerProject.

dotnet new solution -o MyCustomerProject

From here on, it's assumed that the working directory is the solution folder we just created, MyCustomerProject.

Creating the Host

Once the solution is created, we need to add the Host application so we can run DynamicWeb locally, then we add it to the solution file. We're going to install the DynamicWeb 10 Suite package, so it's assumed the project templates are installed. If you don't want or need the Suite, you can choose any of the other DynamicWeb 10 packages available. The rest of the example is unaffected by this choice.

dotnet new dw10-suite -o MyCustomerProject.Host
dotnet sln MyCustomerProject add MyCustomerProject.Host

Using the project templates will ensure that relevant package dependencies to run DynamicWeb are added to the project. This will not be the case for the following projects.

Creating the Files project

Even if you're using Swift, we recommend that you create a project for your Files folder. That way all your changes, even the ones made to item types and repository definitions, are tracked together. Especially if you're using a git repository.

Because the Files project mainly deals with template files, we're creating it as a web project:

dotnet new web -o MyCustomerProject.Files
dotnet sln MyCustomerProject add MyCustomerProject.Files
dotnet add MyCustomerProject.Files package Dynamicweb.Rendering.Providers.NetCore -v 10.*

The last command installs the Rendering package into the Files project. This pulls in some types that are necessary to enable IntelliSense in templates. If you don't want or need IntelliSense in your templates, you can leave it out, but it's recommended to add it.

Creating the CustomCode project

This project may or may not be necessary, but this is how to add it if you do need it. In this example, custom code goes into a class library, so we'll create one of those and add it to our solution.

dotnet new classlib -o MyCustomerProject.CustomCode
dotnet sln MyCustomerProject add MyCustomerProject.CustomCode

At this point a decision needs to be made about workflow: How do you want to test custom code locally? There are three ways to approach publishing add-ins to your local solution.

  • Copying add-ins into /bin (see below)
  • Using the DynamicWeb CLI to publish assemblies to a running solution
  • Using post build scripts to copy the assembly to the correct folder in /Files

While the easiest way to get assemblies loaded locally is by copying them to the /bin folder, this scenario is not a supported for solutions hosted in DynamicWeb Cloud as you do not have access to the /bin folder for the solution. If you want a local environment that as closely as possible resembles the production environment, do not choose this option.

To closely resemble production environments, use the DynamicWeb CLI or copy assemblies to /Files, either manually or with post build scripts. As an added bonus, add-ins installed using the CLI will also show up in the App store as installed code.

If you do want to load custom assemblies from the /bin folder, despite our recommendations, use this command to add the custom code project as a dependency to the host project:

dotnet add MyCustomerProject.Host reference MyCustomerProject.CustomCode

Scripting the process

Here are the scripts that create the project structure as described above. Pick the one that fits your development environment. You can change the projectName variable to change the name of the project, e.g., this could be the name of the customer for whom this project is created.

# This script creates a DynamicWeb 10 solution with projects for files and custom code.

$projectName = "MyCustomerProject"

Write-Host "Creating solution"
dotnet new solution -o $projectName

Write-Host "Creating host project"
dotnet new dw10-suite -o "${projectName}\${projectName}.Host"
dotnet sln $projectName add "${projectName}\${projectName}.Host"

Write-Host "Creating Files project"
dotnet new web -o "${projectName}\${projectName}.Files"
dotnet sln $projectName add "${projectName}\${projectName}.Files"
dotnet add "${projectName}\${projectName}.Files" package Dynamicweb.Rendering.Providers.NetCore -v 10.*

Write-Host "Creating CustomCode project"
dotnet new classlib -o "${projectName}\${projectName}.CustomCode"
dotnet sln $projectName add "${projectName}\${projectName}.CustomCode"

Write-Host "To run the project, type 'dotnet run --project ${projectName}\${projectName}.Host'"

Next steps

Your DynamicWeb 10 project is now setup and you can start development. Before starting the solution for the first time, it's worth considering the next steps.

Follow this guide if you want to install Swift in the project. Otherwise, you can start the solution up and follow the installation guide, making sure to select the option to use an existing Files path. It's recommended that you create a new folder in the Files project to keep the files organized. MyCustomerProject.Files/Files would be a suitable option.

To top