From 8482973e1631bb7ecba72e3f7cf30850fdfc1dca Mon Sep 17 00:00:00 2001 From: Jason Ginchereau Date: Fri, 25 Oct 2024 09:08:43 -1000 Subject: [PATCH 1/2] Specify target framework in generated assembly loader script --- docs/reference/msbuild-props.md | 1 + .../NodeApi.Generator.targets | 4 +- src/NodeApi.Generator/Program.cs | 24 +-- .../TypeDefinitionsGenerator.cs | 144 ++++++++++-------- src/NodeApi/JSValueScope.cs | 1 - test/JSProjectTests.cs | 3 +- .../projects/js-cjs-dynamic/default.js | 9 -- .../projects/js-cjs-module/default.js | 5 - .../projects/js-cjs-module/net472.js | 5 - .../projects/js-cjs-module/net6.0.js | 5 - .../projects/js-cjs-module/net8.0.js | 5 - .../projects/js-esm-dynamic/default.js | 9 -- .../projects/js-esm-module/default.js | 5 - .../projects/js-esm-module/net472.js | 5 - .../projects/js-esm-module/net6.0.js | 5 - .../projects/js-esm-module/net8.0.js | 5 - .../projects/ts-cjs-dynamic/default.ts | 9 -- .../projects/ts-cjs-module/default.ts | 5 - .../projects/ts-cjs-module/net472.ts | 5 - .../projects/ts-cjs-module/net6.0.ts | 5 - .../projects/ts-cjs-module/net8.0.ts | 5 - .../projects/ts-esm-dynamic/default.ts | 9 -- .../projects/ts-esm-module/default.ts | 5 - .../projects/ts-esm-module/net472.ts | 5 - .../projects/ts-esm-module/net6.0.ts | 5 - .../projects/ts-esm-module/net8.0.ts | 5 - 26 files changed, 100 insertions(+), 193 deletions(-) delete mode 100644 test/TestCases/projects/js-cjs-dynamic/default.js delete mode 100644 test/TestCases/projects/js-cjs-module/default.js delete mode 100644 test/TestCases/projects/js-cjs-module/net472.js delete mode 100644 test/TestCases/projects/js-cjs-module/net6.0.js delete mode 100644 test/TestCases/projects/js-cjs-module/net8.0.js delete mode 100644 test/TestCases/projects/js-esm-dynamic/default.js delete mode 100644 test/TestCases/projects/js-esm-module/default.js delete mode 100644 test/TestCases/projects/js-esm-module/net472.js delete mode 100644 test/TestCases/projects/js-esm-module/net6.0.js delete mode 100644 test/TestCases/projects/js-esm-module/net8.0.js delete mode 100644 test/TestCases/projects/ts-cjs-dynamic/default.ts delete mode 100644 test/TestCases/projects/ts-cjs-module/default.ts delete mode 100644 test/TestCases/projects/ts-cjs-module/net472.ts delete mode 100644 test/TestCases/projects/ts-cjs-module/net6.0.ts delete mode 100644 test/TestCases/projects/ts-cjs-module/net8.0.ts delete mode 100644 test/TestCases/projects/ts-esm-dynamic/default.ts delete mode 100644 test/TestCases/projects/ts-esm-module/default.ts delete mode 100644 test/TestCases/projects/ts-esm-module/net472.ts delete mode 100644 test/TestCases/projects/ts-esm-module/net6.0.ts delete mode 100644 test/TestCases/projects/ts-esm-module/net8.0.ts diff --git a/docs/reference/msbuild-props.md b/docs/reference/msbuild-props.md index 7d737e2b..49a6394a 100644 --- a/docs/reference/msbuild-props.md +++ b/docs/reference/msbuild-props.md @@ -9,6 +9,7 @@ The following properties can be used to customize the build processes for genera | `NodeApiTypeDefinitionsFileName` | Name of the type-definitions file generated for a project. Defaults to `$(TargetName).d.ts`. | | `NodeApiTypeDefinitionsEnableWarnings` | Set to `true` to enable warnings when [generating type definitions](../features/type-definitions). The warnings are suppressed by default because they can be verbose when referencing system or external assemblies. | `NodeApiJSModuleType` | Set to either `commonjs` or `esm` to specify the module system used by the generated type definitions. If unspecified, the module type is detected automatically from `package.json`, which is usually correct. | +| `NodeApiTargetFramework` | Target framework moniker that will be loaded at runtime for the Node API .NET host. Default is the project's `$(TargetFramework)`. | `NodeApiSystemReferenceAssembly` | Item-list of assembly names (not file paths) to be included in typedefs generator. The `System`, `System.Runtime`, and `System.Console` assemblies are included by default. Add system assembly names to the item-list to generate type definitions for them. System assemblies are provided by the installed .NET SDK. | | `PublishNodeModule` | Set to `true` to produce a Native AOT `.node` binary and `.js` module-loader script when building the `Publish` target. The files will be placed in the directory indicated by the `PublishDir` variable. See [Develop a Node.js addon module with .NET Native AOT](../scenarios/js-aot-module). | | `PublishMultiPlatformNodeModule` | If `true`, the published `.node` binary file will be placed in a sub-directory according to the targeted [`RuntimeIdentifier`](https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#runtimeidentifier), for example `win-x64`. Then the publish process may be run spearately for multiple runtime-identifiers, and the module-loader script chooses the approrpriate one at runtime. | diff --git a/src/NodeApi.Generator/NodeApi.Generator.targets b/src/NodeApi.Generator/NodeApi.Generator.targets index f72220c4..c7392514 100644 --- a/src/NodeApi.Generator/NodeApi.Generator.targets +++ b/src/NodeApi.Generator/NodeApi.Generator.targets @@ -20,7 +20,9 @@ "$(NodeApiPackageJson)" commonjs,esm - --module $(NodeApiJSModuleType) --framework $(TargetFramework) $(NodeApiTypedefsGeneratorOptions) + $(TargetFramework) + + --module $(NodeApiJSModuleType) --framework $(NodeApiTargetFramework) $(NodeApiTypedefsGeneratorOptions)