UHT plugins and nuget packages - Assembly.LoadFrom

Hi!

I have searched a lot about this topic (nuget packages in UHT plugins) but it seems there isn’t really that much information on them. The only information I’ve found is the engine source and a github repo by the-unrealist

I’m working on a dotnet core integration for Unreal, and to generate the glue between c++ and c# I’m working on a UHT plugin to parse metadata for uproperties. I have set up a c# project and it is run properly by the header tool - so far so good!

However, I wanted to use yaml files to configure the behavior of my plugin, so I added the vyaml nuget to my project. I also had to add a reference manually to the .csproj file like so:

<ItemGroup>
     <Reference Include="VYaml">
        <HintPath>$(PkgVYaml)\lib\net6.0\VYaml.dll</HintPath>
     </Reference>
     <Reference Include="VYaml.Annotations">
        <HintPath>$(PkgVYaml_Annotations)\lib\net6.0\VYaml.Annotations.dll</HintPath>
    </Reference>
...

After adding the nuget the build process fails with the following message (I inserted some newlines to make it easier to read):

10>DotnetIntegrationEditor.uhtmanifest(1): Error  : System.IO.FileNotFoundException - Could not load file or assembly 'VYaml.Annotations, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

Total execution time: 4.22 seconds

10>Microsoft.MakeFile.Targets(44,5): Error MSB3073 : The command ""C:\Games\Epic Games\UE_5.3\Engine\Build\BatchFiles\Build.bat" DotnetIntegrationEditor Win64 DebugGame -Project="C:\Projects\Unreal\DotnetIntegration\DotnetIntegration.uproject" -WaitMutex -FromMsBuild" exited with code 6.

I dug into the UBT source code, and eventually found the culprit; in UhtTables.cs there is a function called LoadAssembly which looks like this:

public static Assembly? LoadAssembly(string assemblyFilePath)
{
	Assembly? assembly = FindAssemblyByName(Path.GetFileNameWithoutExtension(assemblyFilePath));
	if (assembly == null)
	{
		assembly = Assembly.LoadFile(assemblyFilePath);
	}
	return assembly;
}

Changing LoadFile to LoadFrom solved my problem it seems - the UHT plugin runs and the nuget seems to be loaded properly.

assembly = Assembly.LoadFrom(assemblyFilePath);

Now my question is, am I doing something wrong? It feels like it should be possible to add a nuget package without editing the source code like this, and from reading (some of) the source it seems like nuget packages are intended to be supported (?).

Is there another way to include nuget packages in UHT plugins that I have sidestepped without knowing? I was thinking about making a PR to the engine repository, but would love to hear someone else’s opinion first in case I missed something :slight_smile: