curiosity-ai / h5

🚀 The next generation C# to JavaScript compiler
https://github.com/curiosity-ai/h5
Apache License 2.0
211 stars 30 forks source link

Referencing netstandard2.0 library projects. #29

Open IceReaper opened 3 years ago

IceReaper commented 3 years ago

I am working on an opengl/webgl based ui rendering library. The project is setup as follows:

Using Bridge.net it was possible to reference one of the implementation projects, and compile the whole application into either an desktop or webgl powered application. Using H5 however, compiling the Html5 projects results in:

         [info] [10:36:24]  

              __ _  _  _  _ 
             |_ |_)|_)/ \|_)
             |__| \| \\_/| \

         [fail] [10:36:24]  
     1>H5 : error H5003: Could not find file '/home/andre/RiderProjects/Tetys/csharp/Tetys.Libs.UniGui.Core/bin/Debug/netstandard2.0/netstandard.dll'.
         [fail] [10:36:24]  
         Stack Trace:    at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter)
            at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
            at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
            at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
            at Mono.Cecil.ModuleDefinition.GetFileStream(String fileName, FileMode mode, FileAccess access, FileShare share)
            at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters)
            at H5.Translator.Translator.AddNestedReferences(List`1 referencesPathes, String refPath)
            at H5.Translator.Translator.AddNestedReferences(List`1 referencesPathes, String refPath)
            at H5.Translator.Translator.BuildAssembly(CancellationToken cancellationToken)
            at H5.Translator.Translator.Translate(CancellationToken cancellationToken)
            at H5.Translator.TranslatorProcessor.Process()
            at H5.Compiler.CompilationProcessor.Compile(CompilationRequest compilationRequest, UID128 compilationUID, CancellationToken cancellationToken)
     1>/home/andre/.nuget/packages/h5.target/0.0.11500/Sdk/Sdk.targets(462,9): error MSB3073: The command "h5 --project "/home/andre/RiderProjects/Tetys/csharp/Tetys.Libs.UniGui.Html5/Tetys.Libs.UniGui.Html5.csproj" --configuration "Debug" --assembly-version "1.0.0.0"" exited with code 1.
     1>Done Building Project "/home/andre/RiderProjects/Tetys/csharp/Tetys.Libs.UniGui.Html5/Tetys.Libs.UniGui.Html5.csproj" (build target(s)) -- FAILED.

Build FAILED.

       "/home/andre/RiderProjects/Tetys/csharp/Tetys.Libs.UniGui.Html5/Tetys.Libs.UniGui.Html5.csproj" (build target) (1) ->
       (_H5Build target) -> 
         H5 : error H5003: Could not find file '/home/andre/RiderProjects/Tetys/csharp/Tetys.Libs.UniGui.Core/bin/Debug/netstandard2.0/netstandard.dll'.
         /home/andre/.nuget/packages/h5.target/0.0.11500/Sdk/Sdk.targets(462,9): error MSB3073: The command "h5 --project "/home/andre/RiderProjects/Tetys/csharp/Tetys.Libs.UniGui.Html5/Tetys.Libs.UniGui.Html5.csproj" --configuration "Debug" --assembly-version "1.0.0.0"" exited with code 1.

    0 Warning(s)
    2 Error(s)
theolivenbaum commented 3 years ago

Hi @IceReaper - do you think you can share with me the code so I can debug locally?

IceReaper commented 3 years ago

Got any contact information for me, to provide you a code share?

theolivenbaum commented 3 years ago

you can reach me at rafael (at) curiosity . ai

On Mon, Oct 26, 2020, 2:54 PM Andre Mohren notifications@github.com wrote:

Got any contact information for me, to provide you a code share?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/theolivenbaum/h5/issues/29#issuecomment-716561144, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACDCOA6UCB5VKKAHU5I23K3SMV5QNANCNFSM4SZPJXQA .

IceReaper commented 3 years ago

I managed to reproduce it on a small scale test project: H5Test.zip

Both Windows 10 and Ubuntu 20.10 produce the same error.

theolivenbaum commented 3 years ago

Thanks! I'm going to be off next week but will take a look as soon as I'm back!

IceReaper commented 3 years ago

Ongoing from #25: Above error is gone, but now the following error occurs:

H5 : error H5003: Invalid static method invocation syntax: "[MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)', 2)". Method '[MSBuild]::GetTargetFrameworkVersion' not found. Static method invocation should be of the form: $([FullTypeName]::Method()), e.g. $([System.IO.Path]::Combine(`a`, `b`)). Check that all parameters are defined, are of the correct type, and are specified in the right order.  C:\Program Files\dotnet\sdk\5.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets
theolivenbaum commented 3 years ago

Strange - this last error was supposed to be gone with the update to the h5 SDK target that you've already applied.

By the way, I didn't know referencing libraries that are compiled against the normal C# SDK was supported by Bridge before - I'll take a look on the zip file you shared here

theolivenbaum commented 3 years ago

So tested here, the issue seems to be referencing a standard csproj:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>
</Project>

If you change the Library.csproj to be a h5 project:

<Project Sdk="h5.Target/0.0.13615">
    <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="h5" Version="0.0.13619" />
    </ItemGroup>
</Project>

Then it compiles fine. Is this possible on your case? If this is code that is shared on your code-base outside of h5, I would recommend having 2 csproj files, one using the standard SDK and one with the h5 SDK.

IceReaper commented 3 years ago

What i have written against bridge originally is the following setup:

If i change the Ui.Core project to use the h5 target, i cant build it with Ui.Desktop anymore. Using bridge this setup worked perfectly.

Ill test the 2 csproj files approach for now, if that works out i can go with that solution for now. But on the long term i would love to see the feature back (as this will cause a mess if we add more and more libraries) :)

EDIT: The additional csproj approach works as a workaround for now.