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.
- Open the project file (
.csproj) for editing. - In a
PropertyGroup, disable the SDK's automatic compile-item inclusion:
<PropertyGroup>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
- Add explicit
Compileentries for both the class file and its generated file. SetDependentUponon the generated.eco.csfile:
<ItemGroup>
<Compile Include="EcoProject1\Class3.cs" />
<Compile Include="EcoProject1\Class3.eco.cs">
<DependentUpon>Class3.cs</DependentUpon>
</Compile>
</ItemGroup>
- Repeat these entries for every generated class pair that the project must compile.
- Save the project file, reload the project if Visual Studio requests it, and run Codegen again.
- 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:
- In Visual Studio, exclude — do not delete — the generated class files, including both
.csand.eco.csfiles. - Open the MDriven model and generate all class code with
Ctrl+ the C# button. - Check that each generated
.eco.csfile is associated with its corresponding.csfile. - 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.
