MapsterMapper / Mapster

A fast, fun and stimulating object to object Mapper
MIT License
4.31k stars 328 forks source link

Cannot find assembly path when building on Linux(Debian) #368

Open JoaoRuani opened 3 years ago

JoaoRuani commented 3 years ago

Hello, I have a asp.net core 5 api using Mapster and Mapster.Tool, that's the csproj where mapster is referenced

Domain.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="FluentValidation.AspNetCore" Version="10.3.0" />
    <PackageReference Include="Mapster" Version="7.2.0" />
  </ItemGroup>

  <ItemGroup>
    <Generated Include="**\*.g.cs" />
  </ItemGroup>

  <Target Name="Mapster" AfterTargets="AfterBuild">
    <Exec WorkingDirectory="$(ProjectDir)" Command="dotnet tool restore" />
    <Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster model -a &quot;$(TargetDir)$(ProjectName).dll&quot;" />
    <Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster extension -a &quot;$(TargetDir)$(ProjectName).dll&quot;" />
    <Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster mapper -a &quot;$(TargetDir)$(ProjectName).dll&quot;" />
  </Target>

  <Target Name="CleanGenerated">
    <Delete Files="@(Generated)" />
  </Target>

</Project>

I'am using Mapster.Tool 8.2.

Inside Domain's project the files are organized like below

Entities Folder:

Build on windows runs as expected and the dtos are generated.

When trying to build on debian the following error occurs at the step dotnet mapster model -a &quot;$(TargetDir)$(ProjectName).dll&quot;":

Microsoft (R) Build Engine version 16.11.0+0538acc04 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  Restored /home/joao/dpOfficer.digital.backend/dpOfficer.Api.BusinessLogic/dpOfficerApi.BusinessLogic.csproj (in 239 ms).
  Restored /home/joao/dpOfficer.digital.backend/dpOfficerApi.Infrastructure/dpOfficerApi.Infrastructure.csproj (in 239 ms).
  Restored /home/joao/dpOfficer.digital.backend/dpOfficerApi.Domain/dpOfficerApi.Domain.csproj (in 239 ms).
  Restored /home/joao/dpOfficer.digital.backend/dpOfficerApi.Api/dpOfficerApi.Api.csproj (in 247 ms).
  dpOfficerApi.Domain -> /home/joao/dpOfficer.digital.backend/dpOfficerApi.Domain/bin/Debug/net5.0/dpOfficerApi.Domain.dll
  Tool 'mapster.tool' (version '8.2.1') was restored. Available commands: dotnet-mapster

  Restore was successful.
  Cannot find assembly path: FluentValidation (type=package, version=10.3.0)
  Cannot find assembly path: FluentValidation (type=package, version=10.3.0)
  Cannot find assembly path: FluentValidation (type=package, version=10.3.0)
  Cannot find assembly path: FluentValidation (type=package, version=10.3.0)
  Unhandled exception. System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.  Could not load file or assembly 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'. The system cannot find the file specified.

  Could not load file or assembly 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'. The system cannot find the file specified.

  Could not load file or assembly 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'. The system cannot find the file specified.

  Could not load file or assembly 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'. The system cannot find the file specified.

     at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
     at System.Reflection.RuntimeModule.GetTypes()
     at System.Reflection.Assembly.GetTypes()
     at Mapster.Tool.Extensions.Scan(CodeGenerationConfig config, Assembly assembly) in D:\git\Mapster\src\Mapster.Tool\Extensions.cs:line 177
     at Mapster.Tool.Program.GenerateModels(ModelOptions opt) in D:\git\Mapster\src\Mapster.Tool\Program.cs:line 146
     at CommandLine.ParserResultExtensions.WithParsed[T](ParserResult`1 result, Action`1 action)
     at Mapster.Tool.Program.Main(String[] args) in D:\git\Mapster\src\Mapster.Tool\Program.cs:line 17
  System.IO.FileNotFoundException: Could not load file or assembly 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'. The system cannot find the file specified.

  File name: 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'
  System.IO.FileNotFoundException: Could not load file or assembly 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'. The system cannot find the file specified.

  File name: 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'
  System.IO.FileNotFoundException: Could not load file or assembly 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'. The system cannot find the file specified.

  File name: 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'
  System.IO.FileNotFoundException: Could not load file or assembly 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'. The system cannot find the file specified.

  File name: 'FluentValidation, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0'
/home/joao/dpOfficer.digital.backend/dpOfficerApi.Domain/dpOfficerApi.Domain.csproj(19,5): error MSB3073: The command "dotnet mapster model -a "/home/joao/dpOfficer.digital.backend/dpOfficerApi.Domain/bin/Debug/net5.0/dpOfficerApi.Domain.dll"" exited with code 134.

Build FAILED.

/home/joao/dpOfficer.digital.backend/dpOfficerApi.Domain/dpOfficerApi.Domain.csproj(19,5): error MSB3073: The command "dotnet mapster model -a "/home/joao/dpOfficer.digital.backend/dpOfficerApi.Domain/bin/Debug/net5.0/dpOfficerApi.Domain.dll"" exited with code 134.
    0 Warning(s)
    1 Error(s)

If i remove all Validators, the project builds fine.

Any Idea of what i might be doing wrong?

Please tell me if more info is needed.

andrerav commented 2 years ago

@JoaoRuani Do you have an update on this issue? Did you figure it out on your end?

Melethainiel commented 2 years ago

@JoaoRuani Any news on this ?

GuimoBear commented 2 years ago

I believe the problem may be in the GetOutput method, in the Program class, in the Mapster.Tool

The character that separates the directory levels is informed directly in the code

        private static string GetOutput(string baseOutput, string? segment, string typeName)
        {
            var fullBasePath = Path.GetFullPath(baseOutput);
            return segment == null 
                ? Path.Combine(fullBasePath, typeName + ".g.cs") 
                : Path.Combine(fullBasePath, segment.Replace('.', '/'), typeName + ".g.cs");
        }

Replacing '/' to Path.DirectorySeparatorChar the problem should be solved and the Mapster.Tool works again for any platform

EniacMlezi commented 1 year ago

I just ran into the same problem. Mapster.Tool on linux is failing.