microsoft/node-api-dotnet

Set framework version when using ES / CommonJS module loaders

crhaglun opened this issue · 1 comments

When generating ES or CommonJS module loaders for a C# project, the resulting files import node-api-dotnet without framework qualifier, which means the module loaders will always cause defaultTargetFramework to be loaded.

This works great for a project that targets the default framework (currently .NET 8), or can be loaded by the default framework version.

While perhaps a corner case, I'm working on a service where this breaks down because other code may load net472 in the NodeJS process. This means we can't use the generated module loader, but need to explicitly initialize the C# interop types with import dotnet from 'node-api-dotnet/net472' plus dotnet.require(...) instead of just import { InteropType } from './path/to/assembly'

Should the module loaders take the current target framework into account?
Should we generate multiple module loaders for all supported target frameworks?
Should there be some other way to provide a hint / override for the target framework when using module loaders?

Should the module loaders take the current target framework into account?

Yes, I think that should be the default.

Should there be some other way to provide a hint / override for the target framework when using module loaders?

Yes, another MSBuild property could be used to override the default.