Skip to content

ModelBuilder-generated C# isn't recognized by the compiler #2405

Open

Description

System Information (please complete the following information):

  • Model Builder Version (available in Manage Extensions dialog): 16.14.0.2255902
  • Visual Studio Version: Visual Studio Enterprise 2022 (64-bit), Version 17.4.2

Describe the bug

  • On which step of the process did you run into an issue: After completing Model Builder wizard and C# code is generated.
  • Clear description of the problem: At least in .NET Framework 4.7.2 console apps, with a completed model training process, the generated .cs files aren't recognized by the compiler; thus, the classes (eg, IrisModel, ModelInput, ModelOutput) aren't accessible. The issue seems to be caused by the .csproj's <None/> tags:
<ItemGroup Label="IrisModel">
  <None Include="IrisModel.consumption.cs">
    <DependentUpon>IrisModel.mbconfig</DependentUpon>
  </None>
  <None Include="IrisModel.training.cs">
    <DependentUpon>IrisModel.mbconfig</DependentUpon>
  </None>
  <None Include="IrisModel.zip">
    <DependentUpon>IrisModel.mbconfig</DependentUpon>
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </None>
</ItemGroup>

If these are changed to be <Compile/>, the .cs files are treated as compiled code that is accessible to the rest of the project.

To Reproduce
Steps to reproduce the behavior:

  1. Create new C# console app using the .NET Framework
  2. Create new Model Builder config
  3. Using the Iris dataset such as the one included in the attached file, train a model; in my example, it's created with IrisData.mbconfig.
  4. Try to access IrisData from Main: ModelInput sampleInput = null; will exhibit the lack of recognition of the ModelInput type.

Expected behavior
.cs files should be handled as user-created classes.

Screenshots
Unnecessary, but I can provide them if you'd like.

Additional context
According to @JakeRadMSFT, and from my own test, a .NET 6 project uses 'new-style' .csproj where all .cs files are implicitly included. Thus, this issue shouldn't present in that scenario.

IrisData Framework472.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

Priority:1Work that is critical for the release, but we could probably ship withoutReported by: CustomerStale

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions