vipwan / Biwen.AutoClassGen

Source Gen Roslyn
MIT License
12 stars 0 forks source link

Does not generate files -please help #3

Closed ignatandrei closed 10 months ago

ignatandrei commented 10 months ago

I am trying to do an example at https://github.com/ignatandrei/RSCG_Examples/tree/143-biwenautoclassgen

You can find the sources at v2\rscg_examples\Biwen.AutoClassGen\src\FromInterface.sln

It cannot compile because it will not find [AutoGen("Person", "FromInterface")]

( The purpose of the example is to add to my list of RSCG , https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG )

vipwan commented 10 months ago

Yes, in order to use this library you also need to add a nuget reference

dotnet add package Biwen.AutoClassGen.Attributes
ignatandrei commented 10 months ago

I have added . Still not generate files into obj\GX folder

 <ItemGroup>
   <PackageReference Include="Biwen.AutoClassGen" Version="1.0.0.6" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
   <PackageReference Include="Biwen.AutoClassGen.Attributes" Version="1.0.0" />

 </ItemGroup>

<PropertyGroup>
    <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
    <CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
vipwan commented 10 months ago

Take a look at the test case scenarios I provided,

    public interface IPager
    {
        [DefaultValue(0), Description("页码,从0开始")]
        [Range(0, int.MaxValue)]
        int? CurrentPage { get; set; }

        [DefaultValue(10), Description("每页项数,10-30之间")]
        [Range(10, 30)]
        int? PageLen { get; set; }
    }

    public interface IQuery
    {
        [StringLength(100), Description("查询关键字")]
        string? KeyWord { get; set; }
    }

    [AutoGen("QueryRequest", "Biwen.AutoClassGen.Models")]
    [AutoGen("Query2Request", "Biwen.AutoClassGen.Models")]
    public interface IQueryRequest : IPager, IQuery
    {
    }

GEN001: The interface marked [AutoGen] should be inherent one or more interface

ignatandrei commented 10 months ago

I have modified

public interface IPerson
{

    [StringLength(100), Description("person first name")]
    string FirstName { get; set; }
   // string LastName { get; set; }

    //public string FullName();

}

and

using Biwen.AutoClassGen.Attributes;

namespace FromInterface;

[AutoGen("Person", "FromInterface")]
public interface IPerson2: IPerson
{

}

And still no file generated

vipwan commented 10 months ago

pls download my demo code, which can be compiled, your repository is too big for me to download https://github.com/vipwan/Biwen.AutoClassGen/tree/master/Biwen.AutoClassGen.TestConsole

ignatandrei commented 10 months ago

I have done this to test with Nuget in your project

  1. Cloned your project
  2. replace in Biwen.AutoClassGen.TestConsole.csproj

    <ItemGroup>
    <ProjectReference Include="..\Biwen.AutoClassGen.Attributes\Biwen.AutoClassGen.Attributes.csproj" />
    </ItemGroup>
    <ItemGroup>
        <ProjectReference Include="..\Biwen.AutoClassGen.Gen\Biwen.AutoClassGen.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />

    with their nuget definitions

    
    <ItemGroup>
        <PackageReference Include="Biwen.AutoClassGen" Version="1.0.0.6" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
        <PackageReference Include="Biwen.AutoClassGen.Attributes" Version="1.0.0" />
    
    </ItemGroup>

4. Delete the bin and obj folders from Biwen.AutoClassGen.TestConsole
5. Rebuild Biwen.AutoClassGen.TestConsole 

Biwen.AutoClassGen\Biwen.AutoClassGen.TestConsole\Program.cs(7,27,7,39): error CS0234: The type or namespace name 'QueryRequest' does not exist in the namespace 'Biwen.AutoClassGen.Models' (are you missing an assembly reference?)

7. Nothing in obj\GX 

Could you reproduce ?
vipwan commented 10 months ago
global using Biwen.AutoClassGen.Attributes;
global using Biwen.AutoClassGen.Models;
ignatandrei commented 10 months ago

Yes, there are in file _GloableUsings

The problem is that Roslyn is not generating files in obj/GX ( QueryRequest is fully generated by your code )

Please replace in Biwen.AutoClassGen.TestConsole.csproj the reference to the projects with their NuGet counterparts.

vipwan commented 10 months ago

I have done this to test with Nuget in your project

  1. Cloned your project
  2. replace in Biwen.AutoClassGen.TestConsole.csproj
<ItemGroup>
    <ProjectReference Include="..\Biwen.AutoClassGen.Attributes\Biwen.AutoClassGen.Attributes.csproj" />
  </ItemGroup>
  <ItemGroup>
      <ProjectReference Include="..\Biwen.AutoClassGen.Gen\Biwen.AutoClassGen.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />

with their nuget definitions

  <ItemGroup>
      <PackageReference Include="Biwen.AutoClassGen" Version="1.0.0.6" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
      <PackageReference Include="Biwen.AutoClassGen.Attributes" Version="1.0.0" />

  </ItemGroup>
  1. Delete the bin and obj folders from Biwen.AutoClassGen.TestConsole
  2. Rebuild Biwen.AutoClassGen.TestConsole

Biwen.AutoClassGen\Biwen.AutoClassGen.TestConsole\Program.cs(7,27,7,39): error CS0234: The type or namespace name 'QueryRequest' does not exist in the namespace 'Biwen.AutoClassGen.Models' (are you missing an assembly reference?)

  1. Nothing in obj\GX

Could you reproduce ?

I've used it in my project and it works great

https://github.com/vipwan/Biwen.QuickApi/blob/master/Biwen.QuickApi.DemoWeb/Apis/AutoClassGenApi.cs

ignatandrei commented 10 months ago

Oh, your API is .NET 8. I have .NET 7 ;-) . Maybe .... this is the difference

vipwan commented 10 months ago

Oh, your API is .NET 8. I have .NET 7 ;-) . Maybe .... this is the difference

I'm not sure about this, it may have something to do with the environment of the IDE , I'm using VS2022 Preview

ignatandrei commented 10 months ago

This could be also a difference( I am using VS2022 Version 17.7.6 ). Let's wait for .NET 8 and latest VS2022 and I will be back with news...

ignatandrei commented 10 months ago

Works with .NET 8 https://ignatandrei.github.io/RSCG_Examples/v2/docs/Biwen.AutoClassGen

Thanks!