🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Codegen Issues .net standard
This page was created by Hans.karlsen on 2020-11-18. Last edited by Wikiadmin on 2026-07-29.

You can make MDriven code generation work reliably in SDK-style .NET projects by configuring how the project includes generated .cs and .eco.cs files.

Why this happens

SDK-style .NET projects automatically include source files in the project directory as compile items. Older project formats listed each source file explicitly in the project file.

MDriven code generation needs the generated implementation file to be associated with its class file in Visual Studio. For example, Class3.eco.cs must be a dependent file of Class3.cs. If the project relies on automatic file inclusion without the required dependency metadata, Codegen can fail or leave generated files with an incorrect Visual Studio structure.

Configure explicit compile items

Use explicit compile items when Codegen cannot correctly find or associate generated files in an SDK-style project.

  1. Open the project file (.csproj) for editing.
  2. In a PropertyGroup, disable the SDK's automatic compile-item inclusion:
<PropertyGroup>
  <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
  1. Add explicit Compile entries for both the class file and its generated file. Set DependentUpon on the generated .eco.cs file:
<ItemGroup>
  <Compile Include="EcoProject1\Class3.cs" />
  <Compile Include="EcoProject1\Class3.eco.cs">
    <DependentUpon>Class3.cs</DependentUpon>
  </Compile>
</ItemGroup>
  1. Repeat these entries for every generated class pair that the project must compile.
  2. Save the project file, reload the project if Visual Studio requests it, and run Codegen again.
  3. Build the solution to verify that both files compile.

In this example, EcoProject1 is the folder containing the generated class files. Replace it with the actual relative folder in your project.

If the project uses default compile items

If you keep automatic compile-item inclusion enabled, do not add a second Compile Include entry for a file that the SDK already includes. Add the dependency metadata with Update instead:

<ItemGroup>
  <Compile Update="EcoProject1\Class3.eco.cs">
    <DependentUpon>Class3.cs</DependentUpon>
  </Compile>
</ItemGroup>

Use one approach consistently:

Project-file approach Compile-item setting File entries
Explicit compile items EnableDefaultCompileItems is false Add Compile Include for both Class3.cs and Class3.eco.cs; place DependentUpon on the .eco.cs entry.
Default SDK compile items Default inclusion remains enabled Use Compile Update on Class3.eco.cs to add DependentUpon metadata.

Repair an incorrect generated-file structure

A source-control merge can leave generated files with missing or incorrect project-file entries. To recreate the expected structure:

  1. In Visual Studio, exclude — do not delete — the generated class files, including both .cs and .eco.cs files.
  2. Open the MDriven model and generate all class code with Ctrl + the C# button.
  3. Check that each generated .eco.cs file is associated with its corresponding .cs file.
  4. Build the solution.

Code generation does not overwrite the excluded files during this recovery step; it regenerates the expected Visual Studio project structure. For the complete recovery procedure, see HowTos:Fix Code Generation Issues.

Related .NET project guidance

For the supported process for creating a .NET Core MDriven project, including saving the model as .ecomdl, placing related files in the project, and generating C# code, see HowTos:How To Create a .NET Core MDriven Project. For background on the SDK-style project format and current .NET direction, see Documentation:Dotnet core.

See also