Skip to content

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

Open

Description

@aeshirey

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

Activity

  1. zewditu commented on Dec 6, 2022

    @zewditu
    Contributor

    @aeshirey thanks for catching it and pointing to potential causes.

  2. added this to the milestone on Dec 6, 2022
  3. changed the title [-]ModelBuilder using [/-] [+]ModelBuilder-generated C# isn't recognized by the compiler[/+] on Dec 6, 2022
  4. modified the milestones: , January 2023 on Dec 8, 2022
  5. luisquintanilla commented on Jan 9, 2023

    @luisquintanilla
    Contributor

    @zewditu can you please take a look at this one.

  6. beccamc commented on Jan 9, 2023

    @beccamc
    Contributor

    @zewditu If possible, can you add this into the code changes for tomorrow? Its changing the tag to for all the files.

    For example....

    <ItemGroup Label="IrisModel">
      <Compile Include="IrisModel.consumption.cs">
        <DependentUpon>IrisModel.mbconfig</DependentUpon>
      </Compile>
    </ItemGroup>
    

    If you don't have time or it is a complicated change, that is okay! It can ship in February.

  7. zewditu commented on Jan 19, 2023

    @zewditu
    Contributor

    None .NET Framework 4.7.2 projects does not like Compile tag because .net 5 and above projects have default compile and required to set EnableDefaultCompileItems to false which will remove program.cs from the disc.

    the other Tag I tried Item and Link still have the same issue not able to recognize ModelInput in programs .cs in .NET Framework 4.7.2

    Proposed solution:

    The Tag we should use should be dependent on the type of the project, unless otherwise we have a generic tag that could be used for all types of projects.

  8. JakeRadMSFT commented on Jan 19, 2023

    @JakeRadMSFT
    Member

    Sounds good - I support rolling it out to next release and making it framework dependent. Thanks @zewditu!

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

Metadata

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